readResponseBuffer method

void readResponseBuffer(
  1. ReadBuffer response
)

Implementation

void readResponseBuffer(ReadBuffer response) {
  response.seek(0);
  protocolVersion = response.byte;
  if (protocolVersion != 10) {
    throw MySqlClientError("Protocol not supported");
  }
  serverVersion = response.nullTerminatedUtf8String;
  threadId = response.uint32;
  var scrambleBuffer1 = response.readList(8);
  response.skip(1);
  serverCapabilities = response.uint16;
  if (response.hasMore) {
    serverLanguage = response.byte;
    serverStatus = response.uint16;
    serverCapabilities += (response.uint16 << 0x10);

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

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

      // read null-terminator
      response.byte;
      scrambleBuffer = List<int>.filled(scrambleBuffer1.length + scrambleBuffer2.length, 0, growable: false);
      scrambleBuffer!.setRange(0, 8, scrambleBuffer1);
      scrambleBuffer!.setRange(8, 8 + scrambleBuffer2.length, scrambleBuffer2);
    } else {
      scrambleBuffer = scrambleBuffer1;
    }

    if (serverCapabilities & CLIENT_PLUGIN_AUTH > 0) {
      pluginName = response.stringToEnd;
      if (pluginName!.codeUnitAt(pluginName!.length - 1) == 0) {
        pluginName = pluginName!.substring(0, pluginName!.length - 1);
      }
    }
  }
}