Class ReadableByteBuf


  • public final class ReadableByteBuf
    extends java.lang.Object
    Packet buffer
    • Field Detail

      • buf

        public byte[] buf
        buffer
      • pos

        public int pos
        current position reading buffer
      • limit

        private int limit
        row data limit
    • Constructor Detail

      • ReadableByteBuf

        public ReadableByteBuf​(byte[] buf,
                               int limit)
        Packet buffer constructor
        Parameters:
        buf - buffer
        limit - buffer limit
      • ReadableByteBuf

        public ReadableByteBuf​(byte[] buf)
        Packet buffer constructor, limit being the buffer length
        Parameters:
        buf - buffer
    • 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)
        Read length bytes into a new array. The length is not checked here: a caller passing a server-declared length must first check it against readableBytes(), 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()
      • 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()