decodePayloadAsBinary static method
dynamic
decodePayloadAsBinary(})
Implementation
static decodePayloadAsBinary(List<int> data,
{bool? binaryType, required callback(err, [foo, bar])}) {
var bufferTail = data;
var buffers = [];
var i;
while (bufferTail.length > 0) {
var strLen = '';
var isString = bufferTail[0] == 0;
for (i = 1;; i++) {
if (bufferTail[i] == 255) break;
// 310 = char length of Number.MAX_VALUE
if (strLen.length > 310) {
return callback(ERROR_PACKET, 0, 1);
}
strLen += '${bufferTail[i]}';
}
bufferTail = bufferTail.skip(strLen.length + 1).toList();
var msgLength = int.parse(strLen);
dynamic msg = bufferTail.getRange(1, msgLength + 1);
if (isString == true) msg = new String.fromCharCodes(msg);
buffers.add(msg);
bufferTail = bufferTail.skip(msgLength + 1).toList();
}
var total = buffers.length;
for (i = 0; i < total; i++) {
var buffer = buffers[i];
callback(decodePacket(buffer, binaryType, true),
i, total);
}
}