parseMessages method
Creates an array of {@link @microsoft/signalr.HubMessage} objects from the specified serialized representation.
If transferFormat is 'Text', the input parameter must be a string, otherwise it must be an ArrayBuffer.
input A string (json), or Uint8List (binary) containing the serialized representation.
Logger logger A logger that will be used to log messages that occur during parsing.
Implementation
@override
List<HubMessageBase> parseMessages(Object input, Logger logger) {
if (input is! Uint8List) {
throw SignalRException(
message:
"Invalid input for MessagePack hub protocol. Expected an Uint8List.",
type: SignalRExceptionType.invalidPayload);
}
final binaryInput = input;
final List<HubMessageBase> hubMessages = [];
final messages = BinaryMessageFormat.parse(binaryInput);
if (messages.isEmpty) {
throw SignalRException(
message: 'No MessagePack frames in payload.',
type: SignalRExceptionType.invalidPayload);
}
for (var message in messages) {
if (message.isEmpty) {
throw SignalRException(
message: 'Empty MessagePack frame in payload.',
type: SignalRExceptionType.invalidPayload);
}
final unpackedData = msgpack.deserialize(message);
List<dynamic> unpackedList;
if (unpackedData == null) {
throw SignalRException(
message: 'MessagePack deserialized to null.',
type: SignalRExceptionType.invalidPayload);
}
try {
unpackedList = List<dynamic>.from(unpackedData as List<dynamic>);
} catch (_) {
throw SignalRException(
message: "Invalid payload.",
type: SignalRExceptionType.invalidPayload);
}
if (unpackedList.isEmpty) {
throw SignalRException(
message: 'MessagePack message array is empty.',
type: SignalRExceptionType.invalidPayload);
}
final messageObj = _parseMessage(unpackedList, logger);
if (messageObj != null) {
hubMessages.add(messageObj);
}
}
return hubMessages;
}