Java Code Examples for io.netty.buffer.ByteBuf#readLongLE()
The following examples show how to use
io.netty.buffer.ByteBuf#readLongLE() .
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: BedrockUtils.java From Protocol with Apache License 2.0 | 6 votes |
public static List<ResourcePacksInfoPacket.Entry> readPacksInfoEntries(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); List<ResourcePacksInfoPacket.Entry> entries = new ObjectArrayList<>(); int length = buffer.readUnsignedShortLE(); for (int i = 0; i < length; i++) { String packId = readString(buffer); String packVersion = readString(buffer); long packSize = buffer.readLongLE(); String encryptionKey = readString(buffer); String subpackName = readString(buffer); String contentId = readString(buffer); entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, false)); } return entries; }
Example 2
Source File: VarIntUtils.java From r2dbc-mysql with Apache License 2.0 | 6 votes |
/** * Note: it will change {@code buf} readerIndex. * * @param buf a readable buffer include a var integer. * @return A var integer read from buffer. */ public static long readVarInt(ByteBuf buf) { requireNonNull(buf, "buf must not be null"); short firstByte = buf.readUnsignedByte(); if (firstByte < VAR_INT_2_BYTE_CODE) { return firstByte; } else if (firstByte == VAR_INT_2_BYTE_CODE) { return buf.readUnsignedShortLE(); } else if (firstByte == VAR_INT_3_BYTE_CODE) { return buf.readUnsignedMediumLE(); } else { return buf.readLongLE(); } }
Example 3
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 6 votes |
public static List<ResourcePacksInfoPacket.Entry> readPacksInfoEntries(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); List<ResourcePacksInfoPacket.Entry> entries = new ObjectArrayList<>(); int length = buffer.readUnsignedShortLE(); for (int i = 0; i < length; i++) { String packId = readString(buffer); String packVersion = readString(buffer); long packSize = buffer.readLongLE(); String encryptionKey = readString(buffer); String subpackName = readString(buffer); String contentId = readString(buffer); boolean scripting = buffer.readBoolean(); entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, scripting)); } return entries; }
Example 4
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 6 votes |
public static List<ResourcePacksInfoPacket.Entry> readPacksInfoEntries(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); List<ResourcePacksInfoPacket.Entry> entries = new ObjectArrayList<>(); int length = buffer.readUnsignedShortLE(); for (int i = 0; i < length; i++) { String packId = readString(buffer); String packVersion = readString(buffer); long packSize = buffer.readLongLE(); String encryptionKey = readString(buffer); String subpackName = readString(buffer); String contentId = readString(buffer); entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, false)); } return entries; }
Example 5
Source File: MSSQLDataTypeCodec.java From vertx-sql-client with Apache License 2.0 | 6 votes |
private static Object decodeIntN(ByteBuf buffer) { int intNDataTypeLength = buffer.readByte(); switch (intNDataTypeLength) { case 0: // this means we read a NULL value(nullable data type). return null; case 1: return buffer.readUnsignedByte(); case 2: return buffer.readShortLE(); case 4: return buffer.readIntLE(); case 8: return buffer.readLongLE(); default: throw new UnsupportedOperationException(String.format("SEVERE: Unsupported length=[%d] for decoding IntNDataType row value.", intNDataTypeLength)); } }
Example 6
Source File: MSSQLDataTypeCodec.java From vertx-sql-client with Apache License 2.0 | 6 votes |
private static Numeric decodeNumeric(NumericDataType dataType, ByteBuf in) { int scale = dataType.scale(); short length = in.readUnsignedByte(); if (length == 0) { return null; } else { int sign = in.readByte(); Number value; switch (length - 1) { case 4: value = in.readIntLE(); break; case 8: value = in.readLongLE(); break; case 12: return Numeric.create(new BigDecimal(readUnsignedInt96LE(in), scale)); case 16: return Numeric.create(new BigDecimal(readUnsignedInt128LE(in), scale)); default: throw new IllegalStateException("Unexpected numeric length of [" + length + "]"); } return Numeric.create(value.longValue() / Math.pow(10, scale) * sign); } }
Example 7
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 6 votes |
public static List<ResourcePacksInfoPacket.Entry> readPacksInfoEntries(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); List<ResourcePacksInfoPacket.Entry> entries = new ObjectArrayList<>(); int length = buffer.readUnsignedShortLE(); for (int i = 0; i < length; i++) { String packId = readString(buffer); String packVersion = readString(buffer); long packSize = buffer.readLongLE(); String encryptionKey = readString(buffer); String subpackName = readString(buffer); String contentId = readString(buffer); boolean unknownBool = buffer.readBoolean(); entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, unknownBool)); } return entries; }
Example 8
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 6 votes |
public static List<ResourcePacksInfoPacket.Entry> readPacksInfoEntries(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); List<ResourcePacksInfoPacket.Entry> entries = new ObjectArrayList<>(); int length = buffer.readUnsignedShortLE(); for (int i = 0; i < length; i++) { String packId = readString(buffer); String packVersion = readString(buffer); long packSize = buffer.readLongLE(); String encryptionKey = readString(buffer); String subpackName = readString(buffer); String contentId = readString(buffer); boolean unknownBool = buffer.readBoolean(); entries.add(new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, encryptionKey, subpackName, contentId, unknownBool)); } return entries; }
Example 9
Source File: CodecUtils.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
public static long readLengthEncodedInteger(ByteBuf buf, int firstByte) { firstByte = firstByte & 0xff; if (firstByte < NULL_VALUE) { return firstByte; } if (firstByte == NULL_VALUE) { return -1; } if (firstByte == SHORT_VALUE) { return buf.readUnsignedShortLE(); } if (firstByte == MEDIUM_VALUE) { return buf.readUnsignedMediumLE(); } if (firstByte == LONG_VALUE) { long length = buf.readLongLE(); if (length < 0) { throw new CodecException("Received a length value too large to handle: " + Long.toHexString(length)); } return length; } throw new CodecException("Received an invalid length value " + firstByte); }
Example 10
Source File: LongCodec.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
private static long decodeBinary(ByteBuf buf, short type, boolean isUnsigned) { switch (type) { case DataTypes.BIGINT: // Note: no check overflow for BIGINT UNSIGNED return buf.readLongLE(); case DataTypes.INT: if (isUnsigned) { return buf.readUnsignedIntLE(); } else { return buf.readIntLE(); } case DataTypes.MEDIUMINT: // Note: MySQL return 32-bits two's complement for 24-bits integer return buf.readIntLE(); case DataTypes.SMALLINT: if (isUnsigned) { return buf.readUnsignedShortLE(); } else { return buf.readShortLE(); } case DataTypes.YEAR: return buf.readShortLE(); default: // TINYINT if (isUnsigned) { return buf.readUnsignedByte(); } else { return buf.readByte(); } } }
Example 11
Source File: ClientCacheMissResponseSerializer_v388.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { Long2ObjectMap<byte[]> blobs = packet.getBlobs(); int length = VarInts.readUnsignedInt(buffer); for (int i = 0; i < length; i++) { long id = buffer.readLongLE(); byte[] blob = BedrockUtils.readByteArray(buffer); blobs.put(id, blob); } }
Example 12
Source File: BufferUtils.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public static long readLengthEncodedInteger(ByteBuf buffer) { short firstByte = buffer.readUnsignedByte(); switch (firstByte) { case 0xFB: return -1; case 0xFC: return buffer.readUnsignedShortLE(); case 0xFD: return buffer.readUnsignedMediumLE(); case 0xFE: return buffer.readLongLE(); default: return firstByte; } }
Example 13
Source File: ClientCacheMissResponseSerializer_v361.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) { Long2ObjectMap<byte[]> blobs = packet.getBlobs(); int length = VarInts.readUnsignedInt(buffer); for (int i = 0; i < length; i++) { long id = buffer.readLongLE(); byte[] blob = BedrockUtils.readByteArray(buffer); blobs.put(id, blob); } }
Example 14
Source File: BigIntegerCodec.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
private static BigInteger decodeBinary(ByteBuf value, FieldInformation info) { boolean isUnsigned = (info.getDefinitions() & ColumnDefinitions.UNSIGNED) != 0; switch (info.getType()) { case DataTypes.BIGINT: long v = value.readLongLE(); if (isUnsigned && v < 0) { return unsignedBigInteger(v); } return BigInteger.valueOf(v); case DataTypes.INT: if (isUnsigned) { return BigInteger.valueOf(value.readUnsignedIntLE()); } else { return BigInteger.valueOf(value.readIntLE()); } case DataTypes.MEDIUMINT: // Note: MySQL return 32-bits two's complement for 24-bits integer return BigInteger.valueOf(value.readIntLE()); case DataTypes.SMALLINT: if (isUnsigned) { return BigInteger.valueOf(value.readUnsignedShortLE()); } else { return BigInteger.valueOf(value.readShortLE()); } case DataTypes.YEAR: return BigInteger.valueOf(value.readShortLE()); default: // TINYINT if (isUnsigned) { return BigInteger.valueOf(value.readUnsignedByte()); } else { return BigInteger.valueOf(value.readByte()); } } }
Example 15
Source File: VarIntUtils.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
private static long crossReadLong0(ByteBuf firstPart, ByteBuf secondPart) { int readable = firstPart.readableBytes(); if (readable == 0) { return secondPart.readLongLE(); } long low, middle, high; switch (readable) { case 1: low = firstPart.readUnsignedByte(); middle = (secondPart.readUnsignedIntLE() << Byte.SIZE); high = ((long) secondPart.readUnsignedMediumLE()) << (Byte.SIZE + Integer.SIZE); return high | middle | low; case 2: low = firstPart.readUnsignedShortLE(); middle = secondPart.readUnsignedIntLE() << Short.SIZE; high = ((long) secondPart.readUnsignedShortLE()) << (Short.SIZE + Integer.SIZE); return high | middle | low; case 3: low = firstPart.readUnsignedMediumLE(); middle = secondPart.readUnsignedIntLE() << MEDIUM_SIZE; high = ((long) secondPart.readUnsignedByte()) << (MEDIUM_SIZE + Integer.SIZE); return high | middle | low; case 4: low = firstPart.readUnsignedIntLE(); high = secondPart.readUnsignedIntLE() << Integer.SIZE; return high | low; case 5: low = firstPart.readUnsignedIntLE(); middle = ((long) firstPart.readUnsignedByte()) << Integer.SIZE; high = ((long) secondPart.readUnsignedMediumLE()) << (Integer.SIZE + Byte.SIZE); return high | middle | low; case 6: low = firstPart.readUnsignedIntLE(); middle = ((long) firstPart.readUnsignedShortLE()) << Integer.SIZE; high = ((long) secondPart.readUnsignedShortLE()) << (Integer.SIZE + Short.SIZE); return high | middle | low; case 7: low = firstPart.readUnsignedIntLE(); middle = ((long) firstPart.readUnsignedMediumLE()) << Integer.SIZE; high = ((long) secondPart.readUnsignedByte()) << (Integer.SIZE + MEDIUM_SIZE); return high | middle | low; default: return firstPart.readLongLE(); } }
Example 16
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static UUID readUuid(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); return new UUID(buffer.readLongLE(), buffer.readLongLE()); }
Example 17
Source File: MySQLJsonValueDecoder.java From shardingsphere with Apache License 2.0 | 4 votes |
private static BigInteger readUnsignedLongLE(final ByteBuf byteBuf) { long value = byteBuf.readLongLE(); return 0 <= value ? BigInteger.valueOf(value) : MAX_BIG_INTEGER_VALUE.add(BigInteger.valueOf(1 + value)); }
Example 18
Source File: RntbdTokenType.java From azure-cosmosdb-java with MIT License | 4 votes |
@Override public final Object read(final ByteBuf in) { return in.readLongLE(); }
Example 19
Source File: ExtendedQueryCommandCodec.java From vertx-sql-client with Apache License 2.0 | 4 votes |
@Override void decodeMessage(TdsMessage message, TdsMessageEncoder encoder) { ByteBuf messageBody = message.content(); while (messageBody.isReadable()) { int tokenByte = messageBody.readUnsignedByte(); switch (tokenByte) { case DataPacketStreamTokenType.COLMETADATA_TOKEN: MSSQLRowDesc rowDesc = decodeColmetadataToken(messageBody); rowResultDecoder = new RowResultDecoder<>(cmd.collector(), rowDesc); break; case DataPacketStreamTokenType.ROW_TOKEN: handleRow(messageBody); break; case DataPacketStreamTokenType.NBCROW_TOKEN: handleNbcRow(messageBody); break; case DataPacketStreamTokenType.DONE_TOKEN: messageBody.skipBytes(12); // this should only be after ERROR_TOKEN? handleDoneToken(); break; case DataPacketStreamTokenType.INFO_TOKEN: int infoTokenLength = messageBody.readUnsignedShortLE(); //TODO not used for now messageBody.skipBytes(infoTokenLength); break; case DataPacketStreamTokenType.ERROR_TOKEN: handleErrorToken(messageBody); break; case DataPacketStreamTokenType.DONEINPROC_TOKEN: short status = messageBody.readShortLE(); short curCmd = messageBody.readShortLE(); long doneRowCount = messageBody.readLongLE(); handleResultSetDone((int) doneRowCount); handleDoneToken(); break; case DataPacketStreamTokenType.RETURNSTATUS_TOKEN: messageBody.skipBytes(4); break; case DataPacketStreamTokenType.RETURNVALUE_TOKEN: messageBody.skipBytes(messageBody.readableBytes()); // FIXME break; default: throw new UnsupportedOperationException("Unsupported token: " + tokenByte); } } }
Example 20
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static UUID readUuid(ByteBuf buffer) { Preconditions.checkNotNull(buffer, "buffer"); return new UUID(buffer.readLongLE(), buffer.readLongLE()); }