类 NativePacketPayload

  • 所有已实现的接口:
    Message

    public class NativePacketPayload
    extends Object
    implements Message
    PacketPayload is the content of a full single packet (independent from on-wire splitting) communicated with the server. We can manipulate the packet's underlying buffer when sending commands with writeInteger(), writeBytes(), etc. We can check the packet type with isEOFPacket(), etc predicates. A position is maintained for reading/writing data. A payload length is maintained allowing the PacketPayload to be decoupled from the size of the underlying buffer.
    • 字段详细资料

      • NULL_LENGTH

        public static final long NULL_LENGTH
        另请参阅:
        常量字段值
      • TYPE_ID_ERROR

        public static final short TYPE_ID_ERROR
        另请参阅:
        常量字段值
      • TYPE_ID_EOF

        public static final short TYPE_ID_EOF
        另请参阅:
        常量字段值
      • TYPE_ID_AUTH_SWITCH

        public static final short TYPE_ID_AUTH_SWITCH
        It has the same signature as EOF, but may be issued by server only during handshake phase
        另请参阅:
        常量字段值
      • TYPE_ID_LOCAL_INFILE

        public static final short TYPE_ID_LOCAL_INFILE
        另请参阅:
        常量字段值
      • TYPE_ID_OK

        public static final short TYPE_ID_OK
        另请参阅:
        常量字段值
      • TYPE_ID_AUTH_MORE_DATA

        public static final short TYPE_ID_AUTH_MORE_DATA
        另请参阅:
        常量字段值
      • TYPE_ID_AUTH_NEXT_FACTOR

        public static final short TYPE_ID_AUTH_NEXT_FACTOR
        另请参阅:
        常量字段值
    • 构造器详细资料

      • NativePacketPayload

        public NativePacketPayload​(byte[] buf)
      • NativePacketPayload

        public NativePacketPayload​(int size)
    • 方法详细资料

      • toSuperString

        public String toSuperString()
      • getCapacity

        public int getCapacity()
      • ensureCapacity

        public final void ensureCapacity​(int additionalData)
        Checks that underlying buffer has enough space to store additionalData bytes starting from current position. If buffer size is smaller than required then it is re-allocated with bigger size.
        参数:
        additionalData - additional data size in bytes
      • getByteBuffer

        public byte[] getByteBuffer()
        从接口复制的说明: Message
        Returns the array of bytes this Buffer is using to read from.
        指定者:
        getByteBuffer 在接口中 Message
        返回:
        byte array being read from
      • setByteBuffer

        public void setByteBuffer​(byte[] byteBufferToSet)
        Sets the array of bytes to use as a buffer to read from.
        参数:
        byteBufferToSet - the array of bytes to use as a buffer
      • getPayloadLength

        public int getPayloadLength()
        Get the actual length of payload the buffer contains. It can be smaller than underlying buffer size because it can be reused after a big packet.
        返回:
        payload length
      • setPayloadLength

        public void setPayloadLength​(int bufLengthToSet)
        Set the actual length of payload written to buffer. It can be smaller or equal to underlying buffer size.
        参数:
        bufLengthToSet - length
      • getPosition

        public int getPosition()
        从接口复制的说明: Message
        Returns the current position to write to/ read from
        指定者:
        getPosition 在接口中 Message
        返回:
        the current position to write to/ read from
      • setPosition

        public void setPosition​(int positionToSet)
        Set the current position to write to/ read from
        参数:
        positionToSet - the position (0-based index)
      • isErrorPacket

        public boolean isErrorPacket()
        Is it a ERROR packet.
        返回:
        true if it is a ERROR packet
      • isEOFPacket

        public final boolean isEOFPacket()
        Is it a EOF packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_eof_packet.html
        返回:
        true if it is a EOF packet
      • isAuthMethodSwitchRequestPacket

        public final boolean isAuthMethodSwitchRequestPacket()
        Is it a Protocol::AuthSwitchRequest packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_auth_switch_request.html
        返回:
        true if it is a Protocol::AuthSwitchRequest packet
      • isOKPacket

        public final boolean isOKPacket()
        Is it an OK packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_ok_packet.html
        返回:
        true if it is an OK packet
      • isResultSetOKPacket

        public final boolean isResultSetOKPacket()
        Is it an OK packet for ResultSet. Unlike usual 0x00 signature it has 0xfe signature. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_ok_packet.html
        返回:
        true if it is an OK packet for ResultSet
      • isAuthMoreDataPacket

        public final boolean isAuthMoreDataPacket()
        Is it a Protocol::AuthMoreData packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_auth_more_data.html
        返回:
        true if it is a Protocol::AuthMoreData packet
      • isAuthNextFactorPacket

        public final boolean isAuthNextFactorPacket()
        Is it a Protocol::AuthNextFactor packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_auth_next_factor_request.html
        返回:
        true if it is a Protocol::AuthNextFactor packet
      • writeBytes

        public final void writeBytes​(NativeConstants.StringSelfDataType type,
                                     byte[] b)
        Write all bytes from given byte array into internal buffer starting with current buffer position.
        参数:
        type - on-wire data type
        b - from byte array
      • writeBytes

        public final void writeBytes​(NativeConstants.StringLengthDataType type,
                                     byte[] b)
        Write all bytes from given byte array into internal buffer starting with current buffer position.
        参数:
        type - on-wire data type
        b - from byte array
      • writeBytes

        public void writeBytes​(NativeConstants.StringSelfDataType type,
                               byte[] b,
                               int offset,
                               int len)
        Write len bytes from given byte array into internal buffer. Read starts from given offset, write starts with current buffer position.
        参数:
        type - on-wire data type
        b - from byte array
        offset - starting index of b
        len - number of bytes to be written
      • writeBytes

        public void writeBytes​(NativeConstants.StringLengthDataType type,
                               byte[] b,
                               int offset,
                               int len)
        Write len bytes from given byte array into internal buffer. Read starts from given offset, write starts with current buffer position.
        参数:
        type - on-wire data type
        b - from byte array
        offset - starting index of b
        len - number of bytes to be written
      • extractSqlFromPacket

        public static String extractSqlFromPacket​(String possibleSqlQuery,
                                                  NativePacketPayload packet,
                                                  int endOfQueryPacketPosition,
                                                  int maxQuerySizeToLog)
      • setTag

        public int setTag​(String key)
        Tag current position with the given key for future reference.
        参数:
        key - the position tag key name.
        返回:
        the previous value of this tag, if there was one, or -1.
      • getTag

        public int getTag​(String key)
        Gets the value of the position tag for the given key.
        参数:
        key - the position tag key name.
        返回:
        the position value of this tag, if there was one, or -1.