Class ReadableByteBuf
- java.lang.Object
-
- org.mariadb.jdbc.client.ReadableByteBuf
-
public final class ReadableByteBuf extends java.lang.ObjectPacket buffer
-
-
Constructor Summary
Constructors Constructor Description ReadableByteBuf(byte[] buf)Packet buffer constructor, limit being the buffer lengthReadableByteBuf(byte[] buf, int limit)Packet buffer constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longatoll(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)shortgetUnsignedByte()intpos()voidpos(int pos)intreadableBytes()java.lang.StringreadAscii(int length)MariaDbBlobreadBlob(int length)bytereadByte()voidreadBytes(byte[] dst)byte[]readBytes(int length)Readlengthbytes into a new array.byte[]readBytesNullEnd()doublereadDouble()doublereadDoubleBE()floatreadFloat()intreadInt()intreadIntBE()intreadIntLengthEncodedNotNull()Read a length-encoded integer as an int.java.lang.IntegerreadLength()Read a nullable length-encoded integer as an Integer.ReadableByteBufreadLengthBuffer()longreadLong()longreadLongBE()longreadLongLengthEncodedNotNull()intreadMedium()shortreadShort()java.lang.StringreadString(int length)java.lang.StringreadStringEof()java.lang.StringreadStringNullEnd()shortreadUnsignedByte()longreadUnsignedInt()intreadUnsignedMedium()intreadUnsignedShort()voidskip()voidskip(int length)intskipIdentifier()Identifier can have a max length of 256 (alias) So no need to check whole length encoding.voidskipLengthEncoded()
-
-
-
Method Detail
-
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
public MariaDbBlob readBlob(int length)
-
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:
java.lang.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
public java.lang.Integer 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:
java.lang.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:
java.lang.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
public ReadableByteBuf readLengthBuffer()
-
readString
public java.lang.String readString(int length)
-
readAscii
public java.lang.String readAscii(int length)
-
readStringNullEnd
public java.lang.String readStringNullEnd()
-
readStringEof
public java.lang.String readStringEof()
-
readFloat
public float readFloat()
-
readDouble
public double readDouble()
-
readDoubleBE
public double readDoubleBE()
-
-