Top Description Fields Constructors Methods
com.mysql.cj.protocol.a

public Class NativePacketPayload

extends Object
implements Message
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.Message
Imports
java.util.HashMap, .Map, com.mysql.cj.Constants, .Messages, com.mysql.cj.exceptions.ExceptionFactory, .WrongArgumentException, com.mysql.cj.protocol.Message, com.mysql.cj.protocol.a.NativeConstants.IntegerDataType, .NativeConstants.StringLengthDataType, .NativeConstants.StringSelfDataType, com.mysql.cj.util.StringUtils

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.

Field Summary

Modifier and TypeField and Description
private byte[]
pack-priv static final int
pack-priv static final int
public static final long
private int
private int
private Map<String, Integer>
public static final short
public static final short
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

public static final short
public static final short
public static final short
public static final short

Constructor Summary

AccessConstructor and Description
public
NativePacketPayload(byte[] buf)

public

Method Summary

Modifier and TypeMethod and Description
private void
adjustPayloadLength()

To be called after write operations to ensure that payloadLength contains the real size of written data.

public final void
ensureCapacity(int
additional data size in bytes
additionalData
)

Checks that underlying buffer has enough space to store additionalData bytes starting from current position.

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

public byte[]
getByteBuffer()

Implements com.mysql.cj.protocol.Message.getByteBuffer.

Returns the array of bytes this Buffer is using to read from.

public int
public int

Returns:

payload length
getPayloadLength
()

Get the actual length of payload the buffer contains.

public int
getPosition()

Implements com.mysql.cj.protocol.Message.getPosition.

Returns the current position to write to/ read from

public int

Returns:

the position value of this tag, if there was one, or -1.
getTag
(String
the position tag key name.
key
)

Gets the value of the position tag for the given key.

public final boolean

Returns:

true if it is a Protocol::AuthSwitchRequest packet
isAuthMethodSwitchRequestPacket
()

Is it a Protocol::AuthSwitchRequest packet.

public final boolean

Returns:

true if it is a Protocol::AuthMoreData packet
isAuthMoreDataPacket
()

Is it a Protocol::AuthMoreData packet.

public final boolean

Returns:

true if it is a Protocol::AuthNextFactor packet
isAuthNextFactorPacket
()

Is it a Protocol::AuthNextFactor packet.

public final boolean

Returns:

true if it is a EOF packet
isEOFPacket
()

Is it a EOF packet.

public boolean

Returns:

true if it is a ERROR packet
isErrorPacket
()

Is it a ERROR packet.

public final boolean

Returns:

true if it is an OK packet
isOKPacket
()

Is it an OK packet.

public final boolean

Returns:

true if it is an OK packet for ResultSet
isResultSetOKPacket
()

Is it an OK packet for ResultSet.

public byte[]

Returns:

bytes
readBytes
(NativeConstants.StringSelfDataType type)

Read bytes from internal buffer starting from current position into the new byte array.

public byte[]

Returns:

bytes
readBytes
(NativeConstants.StringLengthDataType type, int
length
len
)

Read len bytes from internal buffer starting from current position into the new byte array.

public final long

Returns:

long
readInteger
(NativeConstants.IntegerDataType type)

Read data according to provided Integer type.

public String

Returns:

string
readString
(NativeConstants.StringSelfDataType type, String
if null then platform default encoding is used
encoding
)

Read bytes from internal buffer starting from current position decoding them into String using the specified character encoding.

public String

Returns:

string
readString
(NativeConstants.StringLengthDataType type, String
if null then platform default encoding is used
encoding
,
int
length
len
)

Read len bytes from internal buffer starting from current position decoding them into String using the specified character encoding.

public void
setByteBuffer(byte[]
the array of bytes to use as a buffer
byteBufferToSet
)

Sets the array of bytes to use as a buffer to read from.

public void
setPayloadLength(int
length
bufLengthToSet
)

Set the actual length of payload written to buffer.

public void
setPosition(int
the position (0-based index)
positionToSet
)

Set the current position to write to/ read from

public int

Returns:

the previous value of this tag, if there was one, or -1.
setTag
(String
the position tag key name.
key
)

Tag current position with the given key for future reference.

public void
skipBytes(NativeConstants.StringSelfDataType type)

Set position to next value in internal buffer skipping the current value according to StringSelfDataType.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
public final void
writeBytes(NativeConstants.StringSelfDataType
on-wire data type
type
,
byte[]
from byte array
b
)

Write all bytes from given byte array into internal buffer starting with current buffer position.

public final void
writeBytes(NativeConstants.StringLengthDataType
on-wire data type
type
,
byte[]
from byte array
b
)

Write all bytes from given byte array into internal buffer starting with current buffer position.

public void
writeBytes(NativeConstants.StringSelfDataType
on-wire data type
type
,
byte[]
from byte array
b
,
int
starting index of b
offset
,
int
number of bytes to be written
len
)

Write len bytes from given byte array into internal buffer.

public void
writeBytes(NativeConstants.StringLengthDataType
on-wire data type
type
,
byte[]
from byte array
b
,
int
starting index of b
offset
,
int
number of bytes to be written
len
)

Write len bytes from given byte array into internal buffer.

public void
writeInteger(NativeConstants.IntegerDataType type, long
value
l
)

Write data according to provided Integer type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

byteBufferback to summary
private byte[] byteBuffer
MAX_BYTES_TO_DUMPback to summary
pack-priv static final int MAX_BYTES_TO_DUMP
NO_LENGTH_LIMITback to summary
pack-priv static final int NO_LENGTH_LIMIT
NULL_LENGTHback to summary
public static final long NULL_LENGTH
payloadLengthback to summary
private int payloadLength
positionback to summary
private int position
tagsback to summary
private Map<String, Integer> tags
TYPE_ID_AUTH_MORE_DATAback to summary
public static final short TYPE_ID_AUTH_MORE_DATA
TYPE_ID_AUTH_NEXT_FACTORback to summary
public static final short TYPE_ID_AUTH_NEXT_FACTOR
TYPE_ID_AUTH_SWITCHback to summary
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_EOFback to summary
public static final short TYPE_ID_EOF
TYPE_ID_ERRORback to summary
public static final short TYPE_ID_ERROR
TYPE_ID_LOCAL_INFILEback to summary
public static final short TYPE_ID_LOCAL_INFILE
TYPE_ID_OKback to summary
public static final short TYPE_ID_OK

Constructor Detail

NativePacketPayloadback to summary
public NativePacketPayload(byte[] buf)
NativePacketPayloadback to summary
public NativePacketPayload(int size)

Method Detail

adjustPayloadLengthback to summary
private void adjustPayloadLength()

To be called after write operations to ensure that payloadLength contains the real size of written data.

ensureCapacityback to summary
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.

Parameters
additionalData:int

additional data size in bytes

extractSqlFromPacketback to summary
public static String extractSqlFromPacket(String possibleSqlQuery, NativePacketPayload packet, int endOfQueryPacketPosition, int maxQuerySizeToLog)
getByteBufferback to summary
public byte[] getByteBuffer()

Implements com.mysql.cj.protocol.Message.getByteBuffer.

Doc from com.mysql.cj.protocol.Message.getByteBuffer.

Returns the array of bytes this Buffer is using to read from.

Returns:byte[]

byte array being read from

Annotations
@Override
getCapacityback to summary
public int getCapacity()
getPayloadLengthback to summary
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.

Returns:int

payload length

getPositionback to summary
public int getPosition()

Implements com.mysql.cj.protocol.Message.getPosition.

Doc from com.mysql.cj.protocol.Message.getPosition.

Returns the current position to write to/ read from

Returns:int

the current position to write to/ read from

Annotations
@Override
getTagback to summary
public int getTag(String key)

Gets the value of the position tag for the given key.

Parameters
key:String

the position tag key name.

Returns:int

the position value of this tag, if there was one, or -1.

isAuthMethodSwitchRequestPacketback to summary
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

Returns:boolean

true if it is a Protocol::AuthSwitchRequest packet

isAuthMoreDataPacketback to summary
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

Returns:boolean

true if it is a Protocol::AuthMoreData packet

isAuthNextFactorPacketback to summary
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

Returns:boolean

true if it is a Protocol::AuthNextFactor packet

isEOFPacketback to summary
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

Returns:boolean

true if it is a EOF packet

isErrorPacketback to summary
public boolean isErrorPacket()

Is it a ERROR packet.

Returns:boolean

true if it is a ERROR packet

isOKPacketback to summary
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

Returns:boolean

true if it is an OK packet

isResultSetOKPacketback to summary
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

Returns:boolean

true if it is an OK packet for ResultSet

readBytesback to summary
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 on StringSelfDataType.

Parameters
type:NativeConstants.StringSelfDataType

StringSelfDataType

Returns:byte[]

bytes

readBytesback to summary
public byte[] readBytes(NativeConstants.StringLengthDataType type, int len)

Read len bytes from internal buffer starting from current position into the new byte array.

Parameters
type:NativeConstants.StringLengthDataType

StringLengthDataType

len:int

length

Returns:byte[]

bytes

readIntegerback to summary
public final long readInteger(NativeConstants.IntegerDataType type)

Read data according to provided Integer type.

Parameters
type:NativeConstants.IntegerDataType

IntegerDataType

Returns:long

long

readStringback to summary
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 on StringSelfDataType.

Parameters
type:NativeConstants.StringSelfDataType

StringSelfDataType

encoding:String

if null then platform default encoding is used

Returns:String

string

readStringback to summary
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.

Parameters
type:NativeConstants.StringLengthDataType

StringLengthDataType

encoding:String

if null then platform default encoding is used

len:int

length

Returns:String

string

setByteBufferback to summary
public void setByteBuffer(byte[] byteBufferToSet)

Sets the array of bytes to use as a buffer to read from.

Parameters
byteBufferToSet:byte[]

the array of bytes to use as a buffer

setPayloadLengthback to summary
public void setPayloadLength(int bufLengthToSet)

Set the actual length of payload written to buffer. It can be smaller or equal to underlying buffer size.

Parameters
bufLengthToSet:int

length

setPositionback to summary
public void setPosition(int positionToSet)

Set the current position to write to/ read from

Parameters
positionToSet:int

the position (0-based index)

setTagback to summary
public int setTag(String key)

Tag current position with the given key for future reference.

Parameters
key:String

the position tag key name.

Returns:int

the previous value of this tag, if there was one, or -1.

skipBytesback to summary
public void skipBytes(NativeConstants.StringSelfDataType type)

Set position to next value in internal buffer skipping the current value according to StringSelfDataType.

Parameters
type:NativeConstants.StringSelfDataType

StringSelfDataType

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toSuperStringback to summary
public String toSuperString()
writeBytesback to summary
public final void writeBytes(NativeConstants.StringSelfDataType type, byte[] b)

Write all bytes from given byte array into internal buffer starting with current buffer position.

Parameters
type:NativeConstants.StringSelfDataType

on-wire data type

b:byte[]

from byte array

writeBytesback to summary
public final void writeBytes(NativeConstants.StringLengthDataType type, byte[] b)

Write all bytes from given byte array into internal buffer starting with current buffer position.

Parameters
type:NativeConstants.StringLengthDataType

on-wire data type

b:byte[]

from byte array

writeBytesback to summary
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.

Parameters
type:NativeConstants.StringSelfDataType

on-wire data type

b:byte[]

from byte array

offset:int

starting index of b

len:int

number of bytes to be written

writeBytesback to summary
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.

Parameters
type:NativeConstants.StringLengthDataType

on-wire data type

b:byte[]

from byte array

offset:int

starting index of b

len:int

number of bytes to be written

writeIntegerback to summary
public void writeInteger(NativeConstants.IntegerDataType type, long l)

Write data according to provided Integer type.

Parameters
type:NativeConstants.IntegerDataType

IntegerDataType

l:long

value