MySQLPacketStmtPrepareOK.decode constructor
MySQLPacketStmtPrepareOK.decode(
- Uint8List buffer
Decodifica um buffer Uint8List recebido do servidor e retorna uma instância de MySQLPacketStmtPrepareOK.
A estrutura do pacote segue a especificação do protocolo MySQL para COM_STMT_PREPARE:
- Header: 1 byte (geralmente 0x00).
- Statement ID (stmtID): 4 bytes (little-endian).
- Number of columns: 2 bytes (little-endian).
- Number of parameters: 2 bytes (little-endian).
- Filler: 1 byte (valor ignorado).
- Number of warnings: 2 bytes (little-endian).
Implementation
factory MySQLPacketStmtPrepareOK.decode(Uint8List buffer) {
final byteData = ByteData.sublistView(buffer);
int offset = 0;
// 1) Leitura do header (1 byte)
final header = byteData.getUint8(offset);
offset += 1;
// 2) Leitura do Statement ID (4 bytes, little-endian)
final statementID = byteData.getUint32(offset, Endian.little);
offset += 4;
// 3) Leitura do número de colunas (2 bytes, little-endian)
final numColumns = byteData.getUint16(offset, Endian.little);
offset += 2;
// 4) Leitura do número de parâmetros (2 bytes, little-endian)
final numParams = byteData.getUint16(offset, Endian.little);
offset += 2;
// 5) Pula 1 byte de filler (não utilizado)
offset += 1;
// 6) Leitura do número de warnings (2 bytes, little-endian)
final numWarnings = byteData.getUint16(offset, Endian.little);
offset += 2;
return MySQLPacketStmtPrepareOK(
header: header,
stmtID: statementID,
numOfCols: numColumns,
numOfParams: numParams,
numOfWarnings: numWarnings,
);
}