Example usage for io.netty.buffer ByteBuf readLong

List of usage examples for io.netty.buffer ByteBuf readLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readLong.

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:com.github.sparkfy.network.protocol.RpcFailure.java

License:Apache License

public static RpcFailure decode(ByteBuf buf) {
    long requestId = buf.readLong();
    String errorString = Encoders.Strings.decode(buf);
    return new RpcFailure(requestId, errorString);
}

From source file:com.github.sparkfy.network.protocol.RpcRequest.java

License:Apache License

public static RpcRequest decode(ByteBuf buf) {
    long requestId = buf.readLong();
    // See comment in encodedLength().
    buf.readInt();/*from  w w w  .  j  a v a2 s.  c om*/
    return new RpcRequest(requestId, new NettyManagedBuffer(buf.retain()));
}

From source file:com.github.sparkfy.network.protocol.RpcResponse.java

License:Apache License

public static RpcResponse decode(ByteBuf buf) {
    long requestId = buf.readLong();
    // See comment in encodedLength().
    buf.readInt();/*from w w w .j  a va  2  s.c  o  m*/
    return new RpcResponse(requestId, new NettyManagedBuffer(buf.retain()));
}

From source file:com.github.sparkfy.network.protocol.StreamChunkId.java

License:Apache License

public static StreamChunkId decode(ByteBuf buffer) {
    assert buffer.readableBytes() >= 8 + 4;
    long streamId = buffer.readLong();
    int chunkIndex = buffer.readInt();
    return new StreamChunkId(streamId, chunkIndex);
}

From source file:com.github.sparkfy.network.protocol.StreamResponse.java

License:Apache License

public static StreamResponse decode(ByteBuf buf) {
    String streamId = Encoders.Strings.decode(buf);
    long byteCount = buf.readLong();
    return new StreamResponse(streamId, byteCount, null);
}

From source file:com.github.sparkfy.network.util.TransportFrameDecoder.java

License:Apache License

private long decodeFrameSize() {
    if (nextFrameSize != UNKNOWN_FRAME_SIZE || totalSize < LENGTH_SIZE) {
        return nextFrameSize;
    }//w ww .j  av  a  2s.c om

    // We know there's enough data. If the first buffer contains all the data, great. Otherwise,
    // hold the bytes for the frame length in a composite buffer until we have enough data to read
    // the frame size. Normally, it should be rare to need more than one buffer to read the frame
    // size.
    ByteBuf first = buffers.getFirst();
    if (first.readableBytes() >= LENGTH_SIZE) {
        nextFrameSize = first.readLong() - LENGTH_SIZE;
        totalSize -= LENGTH_SIZE;
        if (!first.isReadable()) {
            buffers.removeFirst().release();
        }
        return nextFrameSize;
    }

    while (frameLenBuf.readableBytes() < LENGTH_SIZE) {
        ByteBuf next = buffers.getFirst();
        int toRead = Math.min(next.readableBytes(), LENGTH_SIZE - frameLenBuf.readableBytes());
        frameLenBuf.writeBytes(next, toRead);
        if (!next.isReadable()) {
            buffers.removeFirst().release();
        }
    }

    nextFrameSize = frameLenBuf.readLong() - LENGTH_SIZE;
    totalSize -= LENGTH_SIZE;
    frameLenBuf.clear();
    return nextFrameSize;
}

From source file:com.gmail.socraticphoenix.forge.randore.packet.RandoresPacket.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.setSeed(buf.readLong());
}

From source file:com.gmail.socraticphoenix.forge.randore.packet.RandoresSeedPacket.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.setSeed(buf.readLong()).setOreCount(buf.readInt());
}

From source file:com.hazelcast.simulator.protocol.core.ResponseCodec.java

License:Open Source License

public static Response decodeResponse(ByteBuf buffer) {
    int frameLength = buffer.readInt();
    int dataLength = (frameLength - HEADER_SIZE) / DATA_ENTRY_SIZE;

    if (buffer.readInt() != MAGIC_BYTES) {
        throw new IllegalArgumentException("Invalid magic bytes for Response");
    }/*from   w  ww.  ja va 2s .  c om*/

    long messageId = buffer.readLong();
    SimulatorAddress destination = decodeSimulatorAddress(buffer);
    Response response = new Response(messageId, destination);

    for (int i = 0; i < dataLength; i++) {
        SimulatorAddress source = decodeSimulatorAddress(buffer);
        ResponseType responseType = ResponseType.fromInt(buffer.readInt());
        response.addResponse(source, responseType);
    }

    return response;
}

From source file:com.hazelcast.simulator.protocol.core.SimulatorMessageCodec.java

License:Open Source License

public static SimulatorMessage decodeSimulatorMessage(ByteBuf buffer) {
    int frameLength = buffer.readInt();
    int dataLength = frameLength - HEADER_SIZE;

    if (buffer.readInt() != MAGIC_BYTES) {
        throw new IllegalArgumentException("Invalid magic bytes for SimulatorMessage");
    }/*from   ww w. ja  v a  2 s  . c o m*/

    SimulatorAddress destination = decodeSimulatorAddress(buffer);
    SimulatorAddress source = decodeSimulatorAddress(buffer);

    long messageId = buffer.readLong();
    OperationType operationType = OperationType.fromInt(buffer.readInt());

    String operationData = buffer.readSlice(dataLength).toString(UTF_8);

    return new SimulatorMessage(destination, source, messageId, operationType, operationData);
}