encodeBuffer static method

dynamic encodeBuffer(
  1. dynamic packet,
  2. dynamic supportsBinary,
  3. dynamic callback, {
  4. dynamic fromClient = false,
})

Encode Buffer data

Implementation

static encodeBuffer(packet, supportsBinary, callback,
    {fromClient = false /*use this to check whether is in client or not*/}) {
  if (!supportsBinary) {
    return encodeBase64Packet(packet, callback);
  }

  var data = packet['data'];
  // 'fromClient' is to check if the runtime is on server side or not,
  // because Dart server's websocket cannot send data with byte buffer.
  if (fromClient) {
    return callback(data.buffer);
  } else {
    return callback(data);
  }
}