Java Code Examples for io.netty.buffer.ByteBuf#readIntLE()
The following examples show how to use
io.netty.buffer.ByteBuf#readIntLE() .
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 check out the related API usage on the sidebar.
Example 1
Source File: PreparedOkMessage.java From r2dbc-mysql with Apache License 2.0 | 6 votes |
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
Source File: DynamicCompositeByteBuf.java From brpc-java with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: DefaultServerPushProtocol.java From brpc-java with Apache License 2.0 | 6 votes |
@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 4
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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 6
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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 File: Main.java From riiablo with Apache License 2.0 | 5 votes |
@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 8
Source File: SourceLogListenHandler.java From async-gamequery-lib with MIT License | 5 votes |
@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 File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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 10
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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 File: GeometryWkbFormatCodec.java From vertx-sql-client with Apache License 2.0 | 5 votes |
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 12
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 5 votes |
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 File: DataTypeCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private static Integer binaryDecodeInt3(ByteBuf buffer) { return buffer.readIntLE(); }
Example 14
Source File: HuluRpcProtocol.java From brpc-java with Apache License 2.0 | 4 votes |
@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 15
Source File: HandshakeHeader.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
static HandshakeHeader decode(ByteBuf buf) { short protocolVersion = buf.readUnsignedByte(); ServerVersion serverVersion = ServerVersion.parse(readCStringAscii(buf)); return new HandshakeHeader(protocolVersion, serverVersion, buf.readIntLE()); }
Example 16
Source File: MSSQLDataTypeCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private static int decodeInt(ByteBuf in) { return in.readIntLE(); }
Example 17
Source File: DataTypeCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private static Integer binaryDecodeUnsignedInt3(ByteBuf buffer) { return buffer.readIntLE() & 0xFFFFFF; }
Example 18
Source File: GeometryWkbFormatCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
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); }
Example 19
Source File: RntbdTokenType.java From azure-cosmosdb-java with MIT License | 4 votes |
@Override public final Object read(final ByteBuf in) { return in.readIntLE(); }
Example 20
Source File: HandshakeHeader.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
static HandshakeHeader decode(ByteBuf buf) { short protocolVersion = buf.readUnsignedByte(); ServerVersion serverVersion = ServerVersion.parse(readCStringAscii(buf)); return new HandshakeHeader(protocolVersion, serverVersion, buf.readIntLE()); }