encode method

  1. @override
Uint8List encode()
override

Implementation

@override
Uint8List encode() {
  final buffer = ByteDataWriter(endian: Endian.little);

  if (database != null) {
    capabilityFlags = capabilityFlags | mysqlCapFlagClientConnectWithDB;
  }

  buffer.writeUint32(capabilityFlags);
  buffer.writeUint32(maxPacketSize);
  buffer.writeUint8(characterSet);
  buffer.write(List.filled(23, 0));
  buffer.write(utf8.encode(username));
  buffer.writeUint8(0);

  if (capabilityFlags & mysqlCapFlagClientSecureConnection != 0) {
    buffer.writeVariableEncInt(authResponse.lengthInBytes);
    buffer.write(authResponse);
  }

  if (database != null &&
      capabilityFlags & mysqlCapFlagClientConnectWithDB != 0) {
    buffer.write(utf8.encode(database!));
    buffer.writeUint8(0);
  }

  if (capabilityFlags & mysqlCapFlagClientPluginAuth != 0) {
    buffer.write(utf8.encode(authPluginName));
    buffer.writeUint8(0);
  }

  return buffer.toBytes();
}