send method

Future<void> send(
  1. Uint8List buffer,
  2. PacketNumber packetNum, {
  3. bool compress = false,
})

Implementation

Future<void> send(Uint8List buffer, PacketNumber packetNum, {bool compress = false}) async {
  if (buffer.length > maxPacketSize!) {
    throw MySqlClientError("Buffer length exceeds limit!");
  }

  if (compress) {
    _header[0] = buffer.length & 0xFF;
    _header[1] = (buffer.length & 0xFF00) >> 8;
    _header[2] = (buffer.length & 0xFF0000) >> 16;
    _header[3] = ++packetNum.packNum;
    var encodedHeader = zlib.encode(_header.data);
    var encodedBuffer = zlib.encode(buffer);
    _compressedHeader.uint24 = encodedHeader.length + encodedBuffer.length;
    _compressedHeader.byte = ++packetNum.compressedPackNum;
    _compressedHeader.uint24 = 4 + buffer.length;
    return _socket.writeBuffer(_compressedHeader.data);
  } else {
    return _sendBufferPart(buffer, 0, packetNum);
  }
}