Package org.mariadb.jdbc.client.impl
Class StandardReadableByteBuf
- java.lang.Object
-
- org.mariadb.jdbc.client.impl.StandardReadableByteBuf
-
- All Implemented Interfaces:
org.mariadb.jdbc.client.ReadableByteBuf
public final class StandardReadableByteBuf extends Object implements org.mariadb.jdbc.client.ReadableByteBuf
Packet buffer
-
-
Field Summary
Fields Modifier and Type Field Description byte[]
buf
-
Constructor Summary
Constructors Constructor Description StandardReadableByteBuf(byte[] buf, int limit)
Packet buffer constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
atoi(int length)
Fast long from text parsingbyte[]
buf()
buffervoid
buf(byte[] buf, int limit, int pos)
Reset bufferbyte
getByte()
Read byte from buffer at current position, without changing positionbyte
getByte(int index)
Read byte from buffer at indicated index, without changing positionshort
getUnsignedByte()
Read unsigned byte value at current position, without changing positionint
pos()
Current buffer positionvoid
pos(int pos)
Set positionint
readableBytes()
buffer number of unread bytesString
readAscii(int length)
Read ascii encoded string from length bytesMariaDbBlob
readBlob(int length)
Read Blob at current positionbyte
readByte()
Read byte at current position, incrementing positionvoid
readBytes(byte[] dst)
Read as many bytes to fill destination arraybyte[]
readBytesNullEnd()
Read null-ended encoded bytes.double
readDouble()
Read double encoded on 8 bytes value at current positiondouble
readDoubleBE()
Read double encoded on 8 bytes (big endian) value at current positionfloat
readFloat()
Read float encoded on 4 bytes value at current positionint
readInt()
Read signed 4 bytes value (little endian) at current positionint
readIntBE()
Read signed 4 bytes value (big endian) at current positionint
readIntLengthEncodedNotNull()
Read encoded length value that cannot be null see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integersInteger
readLength()
Read encoded length value see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integersStandardReadableByteBuf
readLengthBuffer()
Return a length encoded bufferlong
readLong()
Read signed 8 bytes value (little endian) at current positionlong
readLongBE()
Read unsigned 4 bytes value (big endian) at current positionlong
readLongLengthEncodedNotNull()
Read encoded length value that cannot be null see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integersint
readMedium()
Read signed 3 bytes value (little endian) at current positionshort
readShort()
Read signed 2 bytes value (little endian) at current positionString
readString(int length)
Read utf-8 encoded string from length bytesString
readStringEof()
Return the utf-8 string represented by current position to the limit of bufferString
readStringNullEnd()
Read null-ended utf-8 encoded string.short
readUnsignedByte()
Read unsigned byte value at current positionlong
readUnsignedInt()
Read unsigned 4 bytes value (little endian) at current positionint
readUnsignedMedium()
Read unsigned 3 bytes value (little endian) at current positionint
readUnsignedShort()
Read unsigned 2 bytes value (little endian) at current positionvoid
skip()
Skip one bytevoid
skip(int length)
Skip length value of bytesint
skipIdentifier()
Identifier can have a max length of 256 (alias) So no need to check whole length encoding.void
skipLengthEncoded()
Skip length encoded value
-
-
-
Method Detail
-
readableBytes
public int readableBytes()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
buffer number of unread bytes- Specified by:
readableBytes
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- remaining bytes number
-
pos
public int pos()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Current buffer position- Specified by:
pos
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- position
-
buf
public byte[] buf()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
buffer- Specified by:
buf
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- buffer
-
buf
public void buf(byte[] buf, int limit, int pos)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Reset buffer- Specified by:
buf
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
buf
- new bufferlimit
- buffer limitpos
- initial position
-
pos
public void pos(int pos)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Set position- Specified by:
pos
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
pos
- new position
-
skip
public void skip()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Skip one byte- Specified by:
skip
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
-
skip
public void skip(int length)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Skip length value of bytes- Specified by:
skip
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
length
- number of position to skip
-
skipLengthEncoded
public void skipLengthEncoded()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Skip length encoded value- Specified by:
skipLengthEncoded
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
-
readBlob
public MariaDbBlob readBlob(int length)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read Blob at current position- Specified by:
readBlob
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
length
- blob length- Returns:
- Blob
-
atoi
public long atoi(int length)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Fast long from text parsing- Specified by:
atoi
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
length
- data length- Returns:
- long value
-
getByte
public byte getByte()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read byte from buffer at current position, without changing position- Specified by:
getByte
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- byte value
-
getByte
public byte getByte(int index)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read byte from buffer at indicated index, without changing position- Specified by:
getByte
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
index
- index- Returns:
- byte value
-
getUnsignedByte
public short getUnsignedByte()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned byte value at current position, without changing position- Specified by:
getUnsignedByte
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- short value
-
readLongLengthEncodedNotNull
public long readLongLengthEncodedNotNull()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read encoded length value that cannot be null see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integers- Specified by:
readLongLengthEncodedNotNull
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- encoded length
-
readIntLengthEncodedNotNull
public int readIntLengthEncodedNotNull()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read encoded length value that cannot be null see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integersthis is readLongLengthEncodedNotNull limited to 32 bits
- Specified by:
readIntLengthEncodedNotNull
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- encoded length
-
skipIdentifier
public int skipIdentifier()
Identifier can have a max length of 256 (alias) So no need to check whole length encoding.- Specified by:
skipIdentifier
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- current pos
-
readLength
public Integer readLength()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read encoded length value see https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integers- Specified by:
readLength
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- encoded length
-
readByte
public byte readByte()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read byte at current position, incrementing position- Specified by:
readByte
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- byte at current position
-
readUnsignedByte
public short readUnsignedByte()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned byte value at current position- Specified by:
readUnsignedByte
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- short value
-
readShort
public short readShort()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read signed 2 bytes value (little endian) at current position- Specified by:
readShort
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- short value
-
readUnsignedShort
public int readUnsignedShort()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned 2 bytes value (little endian) at current position- Specified by:
readUnsignedShort
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- short value
-
readMedium
public int readMedium()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read signed 3 bytes value (little endian) at current position- Specified by:
readMedium
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- int value
-
readUnsignedMedium
public int readUnsignedMedium()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned 3 bytes value (little endian) at current position- Specified by:
readUnsignedMedium
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- int value
-
readInt
public int readInt()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read signed 4 bytes value (little endian) at current position- Specified by:
readInt
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- int value
-
readIntBE
public int readIntBE()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read signed 4 bytes value (big endian) at current position- Specified by:
readIntBE
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- int value
-
readUnsignedInt
public long readUnsignedInt()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned 4 bytes value (little endian) at current position- Specified by:
readUnsignedInt
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- long value
-
readLong
public long readLong()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read signed 8 bytes value (little endian) at current position- Specified by:
readLong
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- long value
-
readLongBE
public long readLongBE()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read unsigned 4 bytes value (big endian) at current position- Specified by:
readLongBE
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- long value
-
readBytes
public void readBytes(byte[] dst)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read as many bytes to fill destination array- Specified by:
readBytes
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
dst
- destination array
-
readBytesNullEnd
public byte[] readBytesNullEnd()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read null-ended encoded bytes. 0x00 null value won't be in return byte, so position is incremented to returned byte array length + 1- Specified by:
readBytesNullEnd
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- byte array
-
readLengthBuffer
public StandardReadableByteBuf readLengthBuffer()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Return a length encoded buffer- Specified by:
readLengthBuffer
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- new buffer
-
readString
public String readString(int length)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read utf-8 encoded string from length bytes- Specified by:
readString
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
length
- length byte to read- Returns:
- string value
-
readAscii
public String readAscii(int length)
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read ascii encoded string from length bytes- Specified by:
readAscii
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Parameters:
length
- length byte to read- Returns:
- string value
-
readStringNullEnd
public String readStringNullEnd()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read null-ended utf-8 encoded string. 0x00 = null represent string ending. Position is incremented to returned string corresponding bytes + 1- Specified by:
readStringNullEnd
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- corresponding string
-
readStringEof
public String readStringEof()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Return the utf-8 string represented by current position to the limit of buffer- Specified by:
readStringEof
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- string value
-
readFloat
public float readFloat()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read float encoded on 4 bytes value at current position- Specified by:
readFloat
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- float value
-
readDouble
public double readDouble()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read double encoded on 8 bytes value at current position- Specified by:
readDouble
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- double value
-
readDoubleBE
public double readDoubleBE()
Description copied from interface:org.mariadb.jdbc.client.ReadableByteBuf
Read double encoded on 8 bytes (big endian) value at current position- Specified by:
readDoubleBE
in interfaceorg.mariadb.jdbc.client.ReadableByteBuf
- Returns:
- double value
-
-