decodePacket static method
dynamic
decodePacket(
- dynamic encodedPacket,
- dynamic binaryType
Implementation
static decodePacket(dynamic encodedPacket, binaryType) {
if (encodedPacket is! String) {
return {'type': "message", 'data': mapBinary(encodedPacket, binaryType)};
}
var type = encodedPacket[0];
if (type == 'b') {
var buffer =
base64.decode(utf8.decode(encodedPacket.substring(1).codeUnits));
return {'type': "message", 'data': mapBinary(buffer, binaryType)};
}
var typeNumber = int.parse(type);
var pt = PacketTypeList[typeNumber];
if (pt == null) {
return ERROR_PACKET;
}
if (encodedPacket.length > 1) {
return {'type': pt, 'data': encodedPacket.substring(1)};
} else {
return {'type': pt};
}
}