MySQLPacketEOF.decode constructor

MySQLPacketEOF.decode(
  1. Uint8List buffer
)

Decodifica um Uint8List recebido do servidor e retorna uma instância de MySQLPacketEOF.

O buffer deve conter os dados do pacote EOF conforme a seguinte estrutura:

  1. Header: 1 byte.
  2. Warnings count: 2 bytes (valor ignorado).
  3. Status flags: 2 bytes (little-endian).

Implementation

factory MySQLPacketEOF.decode(Uint8List buffer) {
  if (buffer.length < 5 || buffer.length >= 9) {
    throw MySQLProtocolException(
      'Invalid MySQLPacketEOF length: expected 5..8 bytes, got ${buffer.length}',
    );
  }
  final byteData = ByteData.sublistView(buffer);
  int offset = 0;

  // Leitura do header (1 byte).
  final header = byteData.getUint8(offset);
  if (header != 0xfe) {
    throw MySQLProtocolException(
      'Invalid MySQLPacketEOF header: expected 0xfe, got 0x${header.toRadixString(16)}',
    );
  }
  offset += 1;

  // Pula os 2 bytes referentes ao count de warnings (normalmente não utilizados).
  offset += 2;

  // Leitura dos status flags (2 bytes, little-endian).
  final statusFlags = byteData.getUint16(offset, Endian.little);
  offset += 2;

  return MySQLPacketEOF(header: header, statusFlags: statusFlags);
}