decodeEnvelope method

  1. @override
dynamic decodeEnvelope (ByteData envelope)
override

Decodes the specified result envelope from binary.

Throws PlatformException, if envelope represents an error, otherwise returns the enveloped result.

Implementation

@override
dynamic decodeEnvelope(ByteData envelope) {
  final dynamic decoded = const JSONMessageCodec().decodeMessage(envelope);
  if (decoded is! List)
    throw FormatException('Expected envelope List, got $decoded');
  if (decoded.length == 1)
    return decoded[0];
  if (decoded.length == 3
      && decoded[0] is String
      && (decoded[1] == null || decoded[1] is String))
    throw PlatformException(
      code: decoded[0],
      message: decoded[1],
      details: decoded[2],
    );
  throw FormatException('Invalid envelope: $decoded');
}