detectPacketType static method

MySQLGenericPacketType detectPacketType(
  1. Uint8List buffer
)

Implementation

static MySQLGenericPacketType detectPacketType(Uint8List buffer) {
  final byteData = ByteData.sublistView(buffer);
  int offset = 0;

  final header = MySQLPacket.decodePacketHeader(buffer);
  offset += 4;

  final payloadLength = header.item1;
  final type = byteData.getUint8(offset);

  if (type == 0x00 && payloadLength >= 7) {
    // OK packet
    return MySQLGenericPacketType.ok;
  } else if (type == 0xfe && payloadLength < 9) {
    // EOF packet
    return MySQLGenericPacketType.eof;
  } else if (type == 0xff) {
    return MySQLGenericPacketType.error;
  } else {
    return MySQLGenericPacketType.other;
  }
}