encodeBuffer static method
dynamic
encodeBuffer(
- dynamic packet,
- dynamic supportsBinary,
- dynamic callback, {
- 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.
final newData = new Uint8List(data.length + 1);
newData
..setAll(0, [PacketTypeMap[packet['type']]!]..length = 1)
..setAll(1, data);
if (fromClient) {
return callback(newData.buffer);
} else {
return callback(newData);
}
}