Java Code Examples for org.apache.cassandra.utils.ByteBufferUtil#readBytesWithShortLength()

The following examples show how to use org.apache.cassandra.utils.ByteBufferUtil#readBytesWithShortLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCompositeType.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public List<CompositeComponent> deconstruct( ByteBuffer bytes )
{
    List<CompositeComponent> list = new ArrayList<CompositeComponent>();

    ByteBuffer bb = bytes.duplicate();
    readIsStatic(bb);
    int i = 0;

    while (bb.remaining() > 0)
    {
        AbstractType comparator = getComparator(i, bb);
        ByteBuffer value = ByteBufferUtil.readBytesWithShortLength(bb);

        list.add( new CompositeComponent(comparator,value) );

        byte b = bb.get(); // Ignore; not relevant here
        ++i;
    }
    return list;
}
 
Example 2
Source File: CompositeType.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static ByteBuffer extractComponent(ByteBuffer bb, int idx)
{
    bb = bb.duplicate();
    readStatic(bb);
    int i = 0;
    while (bb.remaining() > 0)
    {
        ByteBuffer c = ByteBufferUtil.readBytesWithShortLength(bb);
        if (i == idx)
            return c;

        bb.get(); // skip end-of-component
        ++i;
    }
    return null;
}
 
Example 3
Source File: AbstractCompositeType.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public String getString(ByteBuffer bytes)
{
    StringBuilder sb = new StringBuilder();
    ByteBuffer bb = bytes.duplicate();
    readIsStatic(bb);

    int i = 0;
    while (bb.remaining() > 0)
    {
        if (bb.remaining() != bytes.remaining())
            sb.append(":");

        AbstractType<?> comparator = getAndAppendComparator(i, bb, sb);
        ByteBuffer value = ByteBufferUtil.readBytesWithShortLength(bb);

        sb.append(escape(comparator.getString(value)));

        byte b = bb.get();
        if (b != 0)
        {
            sb.append(b < 0 ? ":_" : ":!");
            break;
        }
        ++i;
    }
    return sb.toString();
}
 
Example 4
Source File: CompositeType.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuffer[] split(ByteBuffer name)
{
    // Assume all components, we'll trunk the array afterwards if need be, but
    // most names will be complete.
    ByteBuffer[] l = new ByteBuffer[types.size()];
    ByteBuffer bb = name.duplicate();
    int i = 0;
    while (bb.remaining() > 0)
    {
        l[i++] = ByteBufferUtil.readBytesWithShortLength(bb);
        bb.get(); // skip end-of-component
    }
    return i == l.length ? l : Arrays.copyOfRange(l, 0, i);
}
 
Example 5
Source File: CollectionSerializer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static ByteBuffer readValue(ByteBuffer input, int version)
{
    if (version >= Server.VERSION_3)
    {
        int size = input.getInt();
        if (size < 0)
            return null;

        return ByteBufferUtil.readBytes(input, size);
    }
    else
    {
        return ByteBufferUtil.readBytesWithShortLength(input);
    }
}
 
Example 6
Source File: AbstractCompositeType.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public int compare(ByteBuffer o1, ByteBuffer o2)
{
    if (!o1.hasRemaining() || !o2.hasRemaining())
        return o1.hasRemaining() ? 1 : o2.hasRemaining() ? -1 : 0;

    ByteBuffer bb1 = o1.duplicate();
    ByteBuffer bb2 = o2.duplicate();

    boolean isStatic1 = readIsStatic(bb1);
    boolean isStatic2 = readIsStatic(bb2);
    if (isStatic1 != isStatic2)
        return isStatic1 ? -1 : 1;

    int i = 0;

    ByteBuffer previous = null;

    while (bb1.remaining() > 0 && bb2.remaining() > 0)
    {
        AbstractType<?> comparator = getComparator(i, bb1, bb2);

        ByteBuffer value1 = ByteBufferUtil.readBytesWithShortLength(bb1);
        ByteBuffer value2 = ByteBufferUtil.readBytesWithShortLength(bb2);

        int cmp = comparator.compareCollectionMembers(value1, value2, previous);
        if (cmp != 0)
            return cmp;

        previous = value1;

        byte b1 = bb1.get();
        byte b2 = bb2.get();
        if (b1 != b2)
            return b1 - b2;

        ++i;
    }

    if (bb1.remaining() == 0)
        return bb2.remaining() == 0 ? 0 : -1;

    // bb1.remaining() > 0 && bb2.remaining() == 0
    return 1;
}