readResponseBuffer method

void readResponseBuffer(
  1. Buffer response
)

Implementation

void readResponseBuffer(Buffer response) {
  response.seek(0);
  protocolVersion = response.readByte();
  if (protocolVersion != 10) {
    throw MySqlClientError('Protocol not supported');
  }
  serverVersion = response.readNullTerminatedString();
  threadId = response.readUint32();
  var scrambleBuffer1 = response.readList(8);
  response.skip(1);
  serverCapabilities = response.readUint16();
  if (response.hasMore) {
    serverLanguage = response.readByte();
    serverStatus = response.readUint16();
    serverCapabilities += (response.readUint16() << 0x10);

    //var secure = serverCapabilities & CLIENT_SECURE_CONNECTION;
    //var plugin = serverCapabilities & CLIENT_PLUGIN_AUTH;

    scrambleLength = response.readByte();
    response.skip(10);
    if (serverCapabilities & CLIENT_SECURE_CONNECTION > 0) {
      var scrambleBuffer2 =
          response.readList(math.max(13, scrambleLength! - 8) - 1);

      // read null-terminator
      response.readByte();
      scrambleBuffer =
          List<int>.from([...scrambleBuffer1, ...scrambleBuffer2]);
    } else {
      scrambleBuffer = scrambleBuffer1;
    }

    if (serverCapabilities & CLIENT_PLUGIN_AUTH > 0) {
      var pluginName = response.readStringToEnd();
      if (pluginName.codeUnitAt(pluginName.length - 1) == 0) {
        pluginName = pluginName.substring(0, pluginName.length - 1);
      }
      _authPlugin = authPluginFromString(pluginName);
    }
  }
}