Search in sources :

Example 1 with UnsafeBuffer

use of com.hazelcast.client.impl.protocol.util.UnsafeBuffer in project hazelcast by hazelcast.

the class ClientMessage method readFrom.

public boolean readFrom(ByteBuffer src) {
    int frameLength = 0;
    if (this.buffer == null) {
        // init internal buffer
        final int remaining = src.remaining();
        if (remaining < Bits.INT_SIZE_IN_BYTES) {
            // we don't have even the frame length ready
            return false;
        }
        frameLength = Bits.readIntL(src.array(), src.position());
        if (frameLength < HEADER_SIZE) {
            throw new IllegalArgumentException("Client message frame length cannot be smaller than header size.");
        }
        if (USE_UNSAFE) {
            wrap(new UnsafeBuffer(new byte[frameLength]), 0);
        } else {
            wrap(new SafeBuffer(new byte[frameLength]), 0);
        }
    }
    frameLength = frameLength > 0 ? frameLength : getFrameLength();
    accumulate(src, frameLength - index());
    return isComplete();
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) UnsafeBuffer(com.hazelcast.client.impl.protocol.util.UnsafeBuffer)

Example 2 with UnsafeBuffer

use of com.hazelcast.client.impl.protocol.util.UnsafeBuffer in project hazelcast by hazelcast.

the class FuzzyClientProtocolBufferTest method init.

@BeforeClass
public static void init() {
    capacity = random.nextInt(1000) + 1000;
    safeBuffer = new SafeBuffer(new byte[capacity]);
    unsafeBuffer = new UnsafeBuffer(new byte[capacity]);
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) UnsafeBuffer(com.hazelcast.client.impl.protocol.util.UnsafeBuffer) BeforeClass(org.junit.BeforeClass)

Aggregations

SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)2 UnsafeBuffer (com.hazelcast.client.impl.protocol.util.UnsafeBuffer)2 BeforeClass (org.junit.BeforeClass)1