encodeOneBinaryPacket static method
dynamic
encodeOneBinaryPacket(
- dynamic p,
- dynamic doneCallback(
- dynamic _
Implementation
static encodeOneBinaryPacket(p, doneCallback(dynamic _)) {
var onBinaryPacketEncode = (packet) {
var encodingLength = '${packet.length}';
var sizeBuffer;
if (packet is String) {
sizeBuffer = new Uint8List(encodingLength.length + 2);
sizeBuffer[0] = 0; // is a string (not true binary = 0)
for (var i = 0; i < encodingLength.length; i++) {
sizeBuffer[i + 1] = int.parse(encodingLength[i]);
}
sizeBuffer[sizeBuffer.length - 1] = 255;
return doneCallback(new List.from(sizeBuffer)..addAll(stringToBuffer(packet)));
}
sizeBuffer = new Uint8List(encodingLength.length + 2);
sizeBuffer[0] = 1; // is binary (true binary = 1)
for (var i = 0; i < encodingLength.length; i++) {
sizeBuffer[i + 1] = int.parse(encodingLength[i]);
}
sizeBuffer[sizeBuffer.length - 1] = 255;
doneCallback(new List.from(sizeBuffer)..addAll(packet));
};
encodePacket(p,
supportsBinary: true, utf8encode: true, callback: onBinaryPacketEncode);
}