Class ReadableByteBuf
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReadableByteBuf(byte[] buf) Packet buffer constructor, limit being the buffer lengthReadableByteBuf(byte[] buf, int limit) Packet buffer constructor -
Method Summary
Modifier and TypeMethodDescriptionlongatoll(int length) longatoull(int length) byte[]buf()voidbuf(byte[] buf, int limit, int pos) voidcheckLength(int length) Ensure a server-declared length fits in the bytes remaining in this buffer.bytegetByte()bytegetByte(int index) shortintpos()voidpos(int pos) intreadAscii(int length) readBlob(int length) bytereadByte()voidreadBytes(byte[] dst) byte[]readBytes(int length) Readlengthbytes into a new array.byte[]doubledoublefloatintreadInt()intintRead a length-encoded integer as an int.Read a nullable length-encoded integer as an Integer.longreadLong()longlongintshortreadString(int length) shortlongintintvoidskip()voidskip(int length) intIdentifier can have a max length of 256 (alias) So no need to check whole length encoding.void
-
Field Details
-
buf
public byte[] bufbuffer -
pos
public int poscurrent position reading buffer -
limit
private int limitrow data limit
-
-
Constructor Details
-
ReadableByteBuf
public ReadableByteBuf(byte[] buf, int limit) Packet buffer constructor- Parameters:
buf- bufferlimit- buffer limit
-
ReadableByteBuf
public ReadableByteBuf(byte[] buf) Packet buffer constructor, limit being the buffer length- Parameters:
buf- buffer
-
-
Method Details
-
readableBytes
public int readableBytes() -
pos
public int pos() -
buf
public byte[] buf() -
buf
public void buf(byte[] buf, int limit, int pos) -
pos
public void pos(int pos) -
skip
public void skip() -
skip
public void skip(int length) -
skipLengthEncoded
public void skipLengthEncoded() -
readBlob
-
atoll
public long atoll(int length) -
atoull
public long atoull(int length) -
getByte
public byte getByte() -
getByte
public byte getByte(int index) -
getUnsignedByte
public short getUnsignedByte() -
readLongLengthEncodedNotNull
public long readLongLengthEncodedNotNull() -
readIntLengthEncodedNotNull
public int readIntLengthEncodedNotNull()Read a length-encoded integer as an int.Length-encoded integers are unsigned on the wire, so a value that does not fit a non-negative int is malformed. Every caller uses the result as a length or a count, so returning it verbatim would let a server drive negative array sizes (
NegativeArraySizeException) or silently truncate to an unrelated value. The range is validated here rather than at each call site.- Returns:
- decoded value, always in range [0,
Integer.MAX_VALUE] - Throws:
IllegalArgumentException- if the encoded value does not fit a non-negative int
-
skipIdentifier
public int skipIdentifier()Identifier can have a max length of 256 (alias) So no need to check whole length encoding.- Returns:
- current pos
-
readLength
Read a nullable length-encoded integer as an Integer.Same range validation as
readIntLengthEncodedNotNull(): the 8-byte form is rejected when it does not fit a non-negative int instead of being silently narrowed.- Returns:
- decoded value in range [0,
Integer.MAX_VALUE], or null for the NULL marker - Throws:
IllegalArgumentException- if the encoded value does not fit a non-negative int
-
checkLength
public void checkLength(int length) Ensure a server-declared length fits in the bytes remaining in this buffer.Declared lengths come from the server. Allocating or copying before checking them against the packet would let a rogue server drive a multi-gigabyte allocation or an out-of-bounds read from a packet of a few bytes, so every read that consumes a declared length goes through this check first.
- Parameters:
length- server-declared length- Throws:
IllegalArgumentException- if the length is negative or exceeds the readable bytes
-
readByte
public byte readByte() -
readUnsignedByte
public short readUnsignedByte() -
readShort
public short readShort() -
readUnsignedShort
public int readUnsignedShort() -
readMedium
public int readMedium() -
readUnsignedMedium
public int readUnsignedMedium() -
readInt
public int readInt() -
readIntBE
public int readIntBE() -
readUnsignedInt
public long readUnsignedInt() -
readLong
public long readLong() -
readLongBE
public long readLongBE() -
readBytes
public void readBytes(byte[] dst) -
readBytes
public byte[] readBytes(int length) Readlengthbytes into a new array. The length is not checked here: a caller passing a server-declared length must first check it againstreadableBytes(), as the column metadata and OK packet parsers do, so that no allocation is sized from an unchecked value.- Parameters:
length- number of bytes to read- Returns:
- the bytes read
-
readBytesNullEnd
public byte[] readBytesNullEnd() -
readLengthBuffer
-
readString
-
readAscii
-
readStringNullEnd
-
readStringEof
-
readFloat
public float readFloat() -
readDouble
public double readDouble() -
readDoubleBE
public double readDoubleBE()
-