Java Code Examples for io.netty.buffer.ByteBuf#readIntLE()

The following examples show how to use io.netty.buffer.ByteBuf#readIntLE() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: r2dbc-mysql   File: PreparedOkMessage.java    License: Apache License 2.0 6 votes vote down vote up
static PreparedOkMessage decode(ByteBuf buf) {
    buf.skipBytes(1); // constant 0x00
    int statementId = buf.readIntLE();
    int totalColumns = buf.readUnsignedShortLE();
    int totalParameters = buf.readUnsignedShortLE();
    buf.skipBytes(1); // constant filler, 0x00
    int warnings;

    if (buf.isReadable(2)) {
        warnings = buf.readUnsignedShortLE();
    } else {
        warnings = 0;
    }

    return new PreparedOkMessage(statementId, totalColumns, totalParameters, warnings);
}
 
Example 2
@Override
public DefaultSPHead headFromByteBuf(ByteBuf buf) throws BadSchemaException {
    DefaultSPHead head = new DefaultSPHead();
    if (buf.readableBytes() < SPHEAD_LENGTH) {
        throw new IllegalArgumentException("not enough bytes to read");
    }
    head.id = buf.readShortLE();
    head.version = buf.readShortLE();
    head.logId = buf.readLongLE();
    head.correlationId = buf.readLongLE();
    byte[] bytes = new byte[PROVIDER_LENGTH];
    buf.readBytes(bytes);
    int n = 0;
    while (n < bytes.length && bytes[n] != 0) {
        n++;
    }
    head.provider = new String(bytes, 0, n);
    head.magicNumber = buf.readIntLE();
    if (head.magicNumber != SPHEAD_MAGIC_NUM) {
        throw new BadSchemaException("nshead magic number does not match");
    }
    head.type = buf.readIntLE();
    head.bodyLength = buf.readIntLE();
    return head;
}
 
Example 3
/**
 * Gets a 32-bit integer at the current {@code readerIndex}
 * in the Little Endian Byte Order and increases the {@code readerIndex}
 * by {@code 4} in this buffer.
 *
 * @throws IndexOutOfBoundsException
 *         if {@code this.readableBytes} is less than {@code 4}
 */
public int readIntLE() {
    checkReadableBytes0(4);
    ByteBuf first = buffers.peek();
    int firstLen = first.readableBytes();
    if (firstLen >= 4) {
        int res = first.readIntLE();
        readableBytes -= 4;
        if (firstLen == 4) {
            buffers.removeFirst().release();
        }
        return res;
    } else if (order() == ByteOrder.BIG_ENDIAN) {
        return readShortLE() & 0xffff | (readShortLE() & 0xffff) << 16;
    } else {
        return (readShortLE() & 0xffff) << 16 | readShortLE() & 0xffff;
    }
}
 
Example 4
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AsciiString readLEAsciiString(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int length = buffer.readIntLE();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes);
    return new AsciiString(bytes);
}
 
Example 5
private static GeometryCollection decodeGeometryCollection(ByteBuf buffer, long srid) {
  long numWkbGeometries = buffer.readUnsignedIntLE();
  List<Geometry> wkbGeometries = new ArrayList<>();
  for (long i = 0; i < numWkbGeometries; i++) {
    buffer.skipBytes(1);
    int type = buffer.readIntLE();
    Geometry geometry = (Geometry) decodeWkbFormatGeometry(buffer, srid, type);
    wkbGeometries.add(geometry);
  }
  return new GeometryCollection(srid, wkbGeometries);
}
 
Example 6
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AsciiString readLEAsciiString(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int length = buffer.readIntLE();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes);
    return new AsciiString(bytes);
}
 
Example 7
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AsciiString readLEAsciiString(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int length = buffer.readIntLE();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes);
    return new AsciiString(bytes);
}
 
Example 8
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    ByteBuf data = msg.content();
    if (data.readableBytes() > 6 && data.readIntLE() == -1) {
        byte[] raw = new byte[data.readableBytes() - 2];
        data.readBytes(raw);
        data.skipBytes(2);
        //Pass to the callback
        if (logEventCallback != null)
            logEventCallback.accept(new SourceLogEntry(new String(raw, Charsets.UTF_8), msg.sender()));
    }
}
 
Example 9
Source Project: riiablo   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  if (in.readableBytes() < 4) return;
  in.markReaderIndex();
  final int length = in.readIntLE();
  if (in.readableBytes() < length) {
    in.resetReaderIndex();
    return;
  }
  out.add(in.readRetainedSlice(length));
}
 
Example 10
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AsciiString readLEAsciiString(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int length = buffer.readIntLE();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes);
    return new AsciiString(bytes);
}
 
Example 11
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ImageData readImageData(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int width = buffer.readIntLE();
    int height = buffer.readIntLE();
    byte[] image = BedrockUtils.readByteArray(buffer);
    return ImageData.of(width, height, image);
}
 
Example 12
Source Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AsciiString readLEAsciiString(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    int length = buffer.readIntLE();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes);
    return new AsciiString(bytes);
}
 
Example 13
Source Project: r2dbc-mysql   File: HandshakeHeader.java    License: Apache License 2.0 4 votes vote down vote up
static HandshakeHeader decode(ByteBuf buf) {
    short protocolVersion = buf.readUnsignedByte();
    ServerVersion serverVersion = ServerVersion.parse(readCStringAscii(buf));
    return new HandshakeHeader(protocolVersion, serverVersion, buf.readIntLE());
}
 
Example 14
Source Project: azure-cosmosdb-java   File: RntbdTokenType.java    License: MIT License 4 votes vote down vote up
@Override
public final Object read(final ByteBuf in) {
    return in.readIntLE();
}
 
Example 15
private static int decodeInt(ByteBuf in) {
  return in.readIntLE();
}
 
Example 16
Source Project: vertx-sql-client   File: DataTypeCodec.java    License: Apache License 2.0 4 votes vote down vote up
private static Integer binaryDecodeInt3(ByteBuf buffer) {
  return buffer.readIntLE();
}
 
Example 17
Source Project: brpc-java   File: HuluRpcProtocol.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public HuluRpcDecodePacket decode(ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest)
        throws BadSchemaException, TooBigDataException, NotEnoughDataException {
    if (in.readableBytes() < FIXED_LEN) {
        throw notEnoughDataException;
    }
    ByteBuf fixHeaderBuf = in.retainedSlice(FIXED_LEN);

    try {
        byte[] magic = new byte[4];
        fixHeaderBuf.readBytes(magic);
        if (!Arrays.equals(magic, MAGIC_HEAD)) {
            throw new BadSchemaException("not valid magic head for hulu");
        }
        int bodySize = fixHeaderBuf.readIntLE();
        int metaSize = fixHeaderBuf.readIntLE();
        // 512M
        if (bodySize > 512 * 1024 * 1024) {
            throw new TooBigDataException("to big body size:" + bodySize);
        }
        if (in.readableBytes() < FIXED_LEN + bodySize) {
            throw notEnoughDataException;
        }

        in.skipBytes(FIXED_LEN);
        HuluRpcDecodePacket packet = new HuluRpcDecodePacket();
        try {
            // meta
            ByteBuf metaBuf = in.readRetainedSlice(metaSize);
            packet.setMetaBuf(metaBuf);

            // body
            ByteBuf protoAndAttachmentBuf = in.readRetainedSlice(bodySize - metaSize);
            packet.setProtoAndAttachmentBuf(protoAndAttachmentBuf);

            return packet;
        } catch (Exception ex) {
            LOG.warn("decode failed, ex={}", ex.getMessage());
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, ex);
        }
    } finally {
        fixHeaderBuf.release();
    }
}
 
Example 18
Source Project: r2dbc-mysql   File: HandshakeHeader.java    License: Apache License 2.0 4 votes vote down vote up
static HandshakeHeader decode(ByteBuf buf) {
    short protocolVersion = buf.readUnsignedByte();
    ServerVersion serverVersion = ServerVersion.parse(readCStringAscii(buf));
    return new HandshakeHeader(protocolVersion, serverVersion, buf.readIntLE());
}
 
Example 19
Source Project: vertx-sql-client   File: DataTypeCodec.java    License: Apache License 2.0 4 votes vote down vote up
private static Integer binaryDecodeUnsignedInt3(ByteBuf buffer) {
  return buffer.readIntLE() & 0xFFFFFF;
}
 
Example 20
public static Object decodeMySQLGeometry(ByteBuf buffer) {
  long srid = buffer.readUnsignedIntLE();
  buffer.readByte(); // byteOrder, always Little-endian for MySQL
  int type = buffer.readIntLE();
  return decodeWkbFormatGeometry(buffer, srid, type);
}