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:io.atomix.catalyst.transport.NettyConnection.java

License:Apache License

/**
 * Handles response./*from   www .  j  av  a  2  s. c  om*/
 */
void handleResponse(ByteBuf response) {
    long requestId = response.readLong();
    byte status = response.readByte();
    switch (status) {
    case SUCCESS:
        handleResponseSuccess(requestId, readResponse(response));
        break;
    case FAILURE:
        handleResponseFailure(requestId, readError(response));
        break;
    }
    response.release();
}

From source file:io.atomix.cluster.messaging.impl.MessageDecoder.java

License:Apache License

@Override
@SuppressWarnings("squid:S128") // suppress switch fall through warning
protected void decode(ChannelHandlerContext context, ByteBuf buffer, List<Object> out) throws Exception {

    switch (currentState) {
    case READ_SENDER_VERSION:
        if (buffer.readableBytes() < SHORT_SIZE) {
            return;
        }/*from   w w  w .  jav a  2 s  .  co m*/
        version = buffer.readShort();
        currentState = DecoderState.READ_SENDER_IP;
    case READ_SENDER_IP:
        if (buffer.readableBytes() < BYTE_SIZE) {
            return;
        }
        buffer.markReaderIndex();
        int octetsLength = buffer.readByte();
        if (buffer.readableBytes() < octetsLength) {
            buffer.resetReaderIndex();
            return;
        }

        byte[] octets = new byte[octetsLength];
        buffer.readBytes(octets);
        senderIp = InetAddress.getByAddress(octets);
        currentState = DecoderState.READ_SENDER_PORT;
    case READ_SENDER_PORT:
        if (buffer.readableBytes() < INT_SIZE) {
            return;
        }
        senderPort = buffer.readInt();
        address = new Address(senderIp.getHostName(), senderPort, senderIp);
        currentState = DecoderState.READ_TYPE;
    case READ_TYPE:
        if (buffer.readableBytes() < BYTE_SIZE) {
            return;
        }
        type = InternalMessage.Type.forId(buffer.readByte());
        currentState = DecoderState.READ_PREAMBLE;
    case READ_PREAMBLE:
        if (buffer.readableBytes() < INT_SIZE) {
            return;
        }
        preamble = buffer.readInt();
        currentState = DecoderState.READ_MESSAGE_ID;
    case READ_MESSAGE_ID:
        if (buffer.readableBytes() < LONG_SIZE) {
            return;
        }
        messageId = buffer.readLong();
        currentState = DecoderState.READ_CONTENT_LENGTH;
    case READ_CONTENT_LENGTH:
        if (buffer.readableBytes() < INT_SIZE) {
            return;
        }
        contentLength = buffer.readInt();
        currentState = DecoderState.READ_CONTENT;
    case READ_CONTENT:
        if (buffer.readableBytes() < contentLength) {
            return;
        }
        if (contentLength > 0) {
            // TODO: Perform a sanity check on the size before allocating
            content = new byte[contentLength];
            buffer.readBytes(content);
        } else {
            content = EMPTY_PAYLOAD;
        }

        switch (type) {
        case REQUEST:
            currentState = DecoderState.READ_SUBJECT_LENGTH;
            break;
        case REPLY:
            currentState = DecoderState.READ_STATUS;
            break;
        default:
            checkState(false, "Must not be here");
        }
        break;
    default:
        break;
    }

    switch (type) {
    case REQUEST:
        switch (currentState) {
        case READ_SUBJECT_LENGTH:
            if (buffer.readableBytes() < SHORT_SIZE) {
                return;
            }
            subjectLength = buffer.readShort();
            currentState = DecoderState.READ_SUBJECT;
        case READ_SUBJECT:
            if (buffer.readableBytes() < subjectLength) {
                return;
            }
            final String subject = readString(buffer, subjectLength, UTF_8);
            InternalRequest message = new InternalRequest(preamble, messageId, address, subject, content);
            out.add(message);
            currentState = DecoderState.READ_TYPE;
            break;
        default:
            break;
        }
        break;
    case REPLY:
        switch (currentState) {
        case READ_STATUS:
            if (buffer.readableBytes() < BYTE_SIZE) {
                return;
            }
            InternalReply.Status status = InternalReply.Status.forId(buffer.readByte());
            InternalReply message = new InternalReply(preamble, messageId, content, status);
            out.add(message);
            currentState = DecoderState.READ_TYPE;
            break;
        default:
            break;
        }
        break;
    default:
        checkState(false, "Must not be here");
    }
}

From source file:io.crate.protocols.postgres.types.BigIntType.java

License:Apache License

@Override
public Object readBinaryValue(ByteBuf buffer, int valueLength) {
    assert valueLength == TYPE_LEN : "length should be " + TYPE_LEN + " because long is int64. Actual length: "
            + valueLength;//from w w w  .  j ava 2  s .c  om
    return buffer.readLong();
}

From source file:io.datty.msgpack.core.AbstractMessageReader.java

License:Apache License

public long readLong(ByteBuf buffer) {
    return buffer.readLong();
}

From source file:io.datty.msgpack.core.AbstractMessageReader.java

License:Apache License

public long readUnsignedLong(ByteBuf buffer) {
    long u64 = buffer.readLong();
    if (u64 < 0) {
        throw new MessageNumberOverflowException(u64);
    }//  ww  w . j a  va 2s.c  o m
    return u64;
}

From source file:io.datty.msgpack.core.AbstractMessageReader.java

License:Apache License

public double readDouble(ByteBuf buffer) {
    return Double.longBitsToDouble(buffer.readLong());
}

From source file:io.github.vastframework.codecs.primitives.DecodingPrimitiveSupport.java

License:Apache License

default long decodeLong(ByteBuf buffer) {
    return buffer.readLong();
}

From source file:io.hydramq.core.type.converters.CursorInfoConverter.java

License:Open Source License

@Override
public CursorInfo read(ConversionContext context, ByteBuf buffer) {
    return new CursorInfo(buffer.readLong(), buffer.readLong(), buffer.readLong());
}

From source file:io.hydramq.core.type.converters.MessagePropertiesConverter.java

License:Open Source License

@Override
public MessageProperties read(final ConversionContext context, final ByteBuf buffer) {
    MessageProperties properties = new MessageProperties();
    int flags = buffer.readInt();
    if ((flags & HAS_STRING_PROPERTIES) == HAS_STRING_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setString(context.read(String.class, buffer), context.read(String.class, buffer));
        }/*w  ww .j av  a 2s .c  o m*/
    }
    if ((flags & HAS_BOOLEAN_PROPERTIES) == HAS_BOOLEAN_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setBoolean(context.read(String.class, buffer), buffer.readBoolean());
        }
    }
    if ((flags & HAS_INTEGER_PROPERTIES) == HAS_INTEGER_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setInteger(context.read(String.class, buffer), buffer.readInt());
        }
    }
    if ((flags & HAS_LONG_PROPERTIES) == HAS_LONG_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setLong(context.read(String.class, buffer), buffer.readLong());
        }
    }
    if ((flags & HAS_FLOAT_PROPERTIES) == HAS_FLOAT_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setFloat(context.read(String.class, buffer), buffer.readFloat());
        }
    }
    if ((flags & HAS_DOUBLE_PROPERTIES) == HAS_DOUBLE_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setDouble(context.read(String.class, buffer), buffer.readDouble());
        }
    }
    if ((flags & HAS_BYTES_PROPERTIES) == HAS_BYTES_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setBytes(context.read(String.class, buffer), context.read(byte[].class, buffer));
        }
    }
    if ((flags & HAS_SHORT_PROPERTIES) == HAS_SHORT_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setShort(context.read(String.class, buffer), buffer.readShort());
        }
    }
    if ((flags & HAS_BYTE_PROPERTIES) == HAS_BYTE_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setByte(context.read(String.class, buffer), buffer.readByte());
        }
    }

    return properties;
}

From source file:io.hydramq.core.type.converters.MessageSetConverter.java

License:Open Source License

@Override
public MessageSet read(ConversionContext context, ByteBuf buffer) {
    MessageSet messageSet = new MessageSet(buffer.readLong());
    int messageCount = buffer.readInt();
    for (int i = 0; i < messageCount; i++) {
        messageSet.add(context.read(Message.class, buffer));
    }/* w w  w. j  a v  a 2  s . c  om*/
    return messageSet;
}