encodePayload static method

dynamic encodePayload(
  1. List packets, {
  2. bool supportsBinary = false,
  3. required dynamic callback(
    1. dynamic t
    ),
})

Implementation

static encodePayload(List packets,
    {bool supportsBinary = false,
    required dynamic Function(dynamic t) callback}) {
  if (supportsBinary && hasBinary(packets)) {
    return encodePayloadAsBinary(packets, callback);
  }

  if (packets.isEmpty) {
    return callback('0:');
  }

  encodeOne(packet, dynamic Function(dynamic t) doneCallback) {
    encodePacket(packet, supportsBinary: supportsBinary, utf8encode: false,
        callback: (message) {
      doneCallback(_setLengthHeader(message));
    });
  }

  map(packets, encodeOne, (results) {
    return callback(results.join(''));
  });
}