Java Code Examples for io.netty.buffer.ByteBuf.readUnsignedInt()

The following are Jave code examples for showing how to use readUnsignedInt() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: minebox   File: OperationParameters.java   Source Code and License Vote up 5 votes
private OperationParameters(ByteBuf message) {
    cmdFlags = message.readShort();
    cmdType = message.readShort();
    cmdHandle = message.readLong();
    cmdOffset = message.readLong();
    cmdLength = message.readUnsignedInt();
    state = State.TM_RECEIVE_CMD_DATA;
}
 
Example 2
Project: minebox   File: HandshakePhase.java   Source Code and License Vote up 5 votes
private void receiveHandshakeOption(ChannelHandlerContext ctx, ByteBuf message) throws IOException {

        final long ihaveopt = message.readLong();
        if (ihaveopt != Protocol.IHAVEOPT)
            throw new IllegalArgumentException("Invalid negotiation magic != 'IHAVEOPT'");

        int option = message.readInt();
        long optionLen = message.readUnsignedInt();

        currentOption = option;
        currentOptionLen = optionLen;
        LOGGER.debug("currentOption {} currentOptionLen {}", currentOption, currentOptionLen);
        state = State.HS_OPTION_DATA;
    }
 
Example 3
Project: message-broker   File: LongString.java   Source Code and License Vote up 5 votes
public static LongString parse(ByteBuf buf) throws Exception {
    int size = (int) buf.readUnsignedInt();

    if (size < 0) {
        throw new Exception("Invalid string length");
    }

    byte[] data = new byte[size];
    buf.readBytes(data);

    return new LongString(size, data);
}
 
Example 4
Project: message-broker   File: FieldTable.java   Source Code and License Vote up 5 votes
public static FieldTable parse(ByteBuf buf) throws Exception {
    long size = buf.readUnsignedInt();
    long readBytes = 0L;
    Map<ShortString, FieldValue> properties = new HashMap<>();

    while (readBytes < size) {
        ShortString key = ShortString.parse(buf);
        FieldValue value = FieldValue.parse(buf);
        properties.put(key, value);

        readBytes = readBytes + key.getSize() + value.getSize();
    }

    return new FieldTable(properties);
}
 
Example 5
Project: nearenough   File: RtMessage.java   Source Code and License Vote up 5 votes
private Map<RtTag, byte[]> extractSingleMapping(ByteBuf msg) {
  long uintTag = msg.readUnsignedInt();
  RtTag tag = RtTag.fromUnsignedInt((int) uintTag);

  byte[] value = new byte[msg.readableBytes()];
  msg.readBytes(value);

  return Collections.singletonMap(tag, value);
}
 
Example 6
Project: nearenough   File: RtMessage.java   Source Code and License Vote up 5 votes
private Map<RtTag, byte[]> extractMultiMapping(ByteBuf msg) {
  // extractOffsets will leave the reader index positioned at the first tag
  int[] offsets = extractOffsets(msg);

  int startOfValues = msg.readerIndex() + (4 * numTags);
  Map<RtTag, byte[]> mapping = new LinkedHashMap<>(numTags);
  RtTag prevTag = null;

  for (int i = 0; i < offsets.length; i++) {
    long uintCurrTag = msg.readUnsignedInt();
    RtTag currTag = RtTag.fromUnsignedInt((int) uintCurrTag);

    if ((prevTag != null) && currTag.isLessThan(prevTag)) {
      String exMsg = String.format(
          "tags not strictly increasing: current '%s' (0x%08x), previous '%s' (0x%08x)",
          currTag, currTag.valueLE(), prevTag, prevTag.valueLE()
      );
      throw new TagsNotIncreasingException(exMsg);
    }

    int valueIdx = startOfValues + offsets[i];
    int valueLen = ((i + 1) == offsets.length) ? msg.readableBytes() - offsets[i]
                                               : offsets[i + 1] - offsets[i];
    byte[] valueBytes = new byte[valueLen];
    msg.getBytes(valueIdx, valueBytes);

    mapping.put(currTag, valueBytes);
    prevTag = currTag;
  }

  return mapping;
}
 
Example 7
Project: tools   File: OperationParameters.java   Source Code and License Vote up 5 votes
private OperationParameters(ByteBuf message) {
    cmdFlags = message.readShort();
    cmdType = message.readShort();
    cmdHandle = message.readLong();
    cmdOffset = message.readLong();
    cmdLength = message.readUnsignedInt();
    state = State.TM_RECEIVE_CMD_DATA;
}
 
Example 8
Project: tools   File: HandshakePhase.java   Source Code and License Vote up 5 votes
private void receiveHandshakeOption(ChannelHandlerContext ctx, ByteBuf message) throws IOException {

        final long ihaveopt = message.readLong();
        if (ihaveopt != Protocol.IHAVEOPT)
            throw new IllegalArgumentException("Invalid negotiation magic != 'IHAVEOPT'");

        int option = message.readInt();
        long optionLen = message.readUnsignedInt();

        currentOption = option;
        currentOptionLen = optionLen;
        LOGGER.debug("currentOption {} currentOptionLen {}", currentOption, currentOptionLen);
        state = State.HS_OPTION_DATA;
    }