类 NativePacketPayload
- java.lang.Object
-
- com.mysql.cj.protocol.a.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.
-
-
字段概要
字段 修饰符和类型 字段 说明 static longNULL_LENGTHstatic shortTYPE_ID_AUTH_MORE_DATAstatic shortTYPE_ID_AUTH_NEXT_FACTORstatic shortTYPE_ID_AUTH_SWITCHIt has the same signature as EOF, but may be issued by server only during handshake phasestatic shortTYPE_ID_EOFstatic shortTYPE_ID_ERRORstatic shortTYPE_ID_LOCAL_INFILEstatic shortTYPE_ID_OK
-
构造器概要
构造器 构造器 说明 NativePacketPayload(byte[] buf)NativePacketPayload(int size)
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidensureCapacity(int additionalData)Checks that underlying buffer has enough space to store additionalData bytes starting from current position.static StringextractSqlFromPacket(String possibleSqlQuery, NativePacketPayload packet, int endOfQueryPacketPosition, int maxQuerySizeToLog)byte[]getByteBuffer()Returns the array of bytes this Buffer is using to read from.intgetCapacity()intgetPayloadLength()Get the actual length of payload the buffer contains.intgetPosition()Returns the current position to write to/ read fromintgetTag(String key)Gets the value of the position tag for the given key.booleanisAuthMethodSwitchRequestPacket()Is it a Protocol::AuthSwitchRequest packet.booleanisAuthMoreDataPacket()Is it a Protocol::AuthMoreData packet.booleanisAuthNextFactorPacket()Is it a Protocol::AuthNextFactor packet.booleanisEOFPacket()Is it a EOF packet.booleanisErrorPacket()Is it a ERROR packet.booleanisOKPacket()Is it an OK packet.booleanisResultSetOKPacket()Is it an OK packet for ResultSet.byte[]readBytes(NativeConstants.StringLengthDataType type, int len)Read len bytes from internal buffer starting from current position into the new byte array.byte[]readBytes(NativeConstants.StringSelfDataType type)Read bytes from internal buffer starting from current position into the new byte array.longreadInteger(NativeConstants.IntegerDataType type)Read data according to provided Integer type.StringreadString(NativeConstants.StringLengthDataType type, String encoding, int len)Read len bytes from internal buffer starting from current position decoding them into String using the specified character encoding.StringreadString(NativeConstants.StringSelfDataType type, String encoding)Read bytes from internal buffer starting from current position decoding them into String using the specified character encoding.voidsetByteBuffer(byte[] byteBufferToSet)Sets the array of bytes to use as a buffer to read from.voidsetPayloadLength(int bufLengthToSet)Set the actual length of payload written to buffer.voidsetPosition(int positionToSet)Set the current position to write to/ read fromintsetTag(String key)Tag current position with the given key for future reference.voidskipBytes(NativeConstants.StringSelfDataType type)Set position to next value in internal buffer skipping the current value according toNativeConstants.StringSelfDataType.StringtoString()StringtoSuperString()voidwriteBytes(NativeConstants.StringLengthDataType type, byte[] b)Write all bytes from given byte array into internal buffer starting with current buffer position.voidwriteBytes(NativeConstants.StringLengthDataType type, byte[] b, int offset, int len)Write len bytes from given byte array into internal buffer.voidwriteBytes(NativeConstants.StringSelfDataType type, byte[] b)Write all bytes from given byte array into internal buffer starting with current buffer position.voidwriteBytes(NativeConstants.StringSelfDataType type, byte[] b, int offset, int len)Write len bytes from given byte array into internal buffer.voidwriteInteger(NativeConstants.IntegerDataType type, long l)Write data according to provided Integer type.
-
-
-
字段详细资料
-
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
- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
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()
从接口复制的说明:MessageReturns 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()
从接口复制的说明:MessageReturns 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
-
writeInteger
public void writeInteger(NativeConstants.IntegerDataType type, long l)
Write data according to provided Integer type.- 参数:
type-NativeConstants.IntegerDataTypel- value
-
readInteger
public final long readInteger(NativeConstants.IntegerDataType type)
Read data according to provided Integer type.- 参数:
type-NativeConstants.IntegerDataType- 返回:
- long
-
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 typeb- 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 typeb- 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 typeb- from byte arrayoffset- starting index of blen- 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 typeb- from byte arrayoffset- starting index of blen- number of bytes to be written
-
readBytes
public byte[] readBytes(NativeConstants.StringSelfDataType type)
Read bytes from internal buffer starting from current position into the new byte array. The length of data to read depends onNativeConstants.StringSelfDataType.- 参数:
type-NativeConstants.StringSelfDataType- 返回:
- bytes
-
skipBytes
public void skipBytes(NativeConstants.StringSelfDataType type)
Set position to next value in internal buffer skipping the current value according toNativeConstants.StringSelfDataType.- 参数:
type-NativeConstants.StringSelfDataType
-
readBytes
public byte[] readBytes(NativeConstants.StringLengthDataType type, int len)
Read len bytes from internal buffer starting from current position into the new byte array.- 参数:
type-NativeConstants.StringLengthDataTypelen- length- 返回:
- bytes
-
readString
public String readString(NativeConstants.StringSelfDataType type, String encoding)
Read bytes from internal buffer starting from current position decoding them into String using the specified character encoding. The length of data to read depends onNativeConstants.StringSelfDataType.- 参数:
type-NativeConstants.StringSelfDataTypeencoding- if null then platform default encoding is used- 返回:
- string
-
readString
public String readString(NativeConstants.StringLengthDataType type, String encoding, int len)
Read len bytes from internal buffer starting from current position decoding them into String using the specified character encoding.- 参数:
type-NativeConstants.StringLengthDataTypeencoding- if null then platform default encoding is usedlen- length- 返回:
- string
-
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.
-
-