createRequest method

Uint8List createRequest()
override

Constructs and returns a request command packet.

Implementation

Uint8List createRequest() {
  List<int> encodedUsername = username == null ? [] : utf8.encode(username!);
  List<int>? encodedDb;

  int size = pwdHash.length + encodedUsername.length + 2 + 32;
  int clientFlags = this.clientFlags;
  if (db != null) {
    encodedDb = utf8.encode(db!);
    size += encodedDb.length + 1;
    clientFlags |= CLIENT_CONNECT_WITH_DB;
  }

  var buffer = FixedWriteBuffer(size);
  buffer.seekWrite(0);
  buffer.uint32 = clientFlags;
  buffer.uint32 = maxPacketSize!;
  buffer.byte = characterSet!;
  buffer.fill(23, 0);
  buffer.nullTerminatedList = encodedUsername;
  buffer.byte = pwdHash.length;
  buffer.writeList(pwdHash);

  if (db != null) buffer.nullTerminatedList = encodedDb!;

  return buffer.data;
}