deserialize method

  1. @override
AbstractMessage? deserialize(
  1. Uint8List? msgPack
)
override

Converts a uint8 msgpack message into a WAMP message object

Implementation

@override
AbstractMessage? deserialize(Uint8List? msgPack) {
  Object? message = msgpack_dart.deserialize(msgPack!);
  if (message is List) {
    int messageId = message[0];
    if (messageId == MessageTypes.codeChallenge) {
      return Challenge(
          message[1],
          Extra(
              challenge: message[2]['challenge'],
              salt: message[2]['salt'],
              keyLen: message[2]['keylen'],
              iterations: message[2]['iterations'],
              memory: message[2]['memory'],
              kdf: message[2]['kdf'],
              nonce: message[2]['nonce']));
    }
    if (messageId == MessageTypes.codeWelcome) {
      final details = Details();
      details.realm = message[2]['realm'] ?? '';
      details.authid = message[2]['authid'] ?? '';
      details.authprovider = message[2]['authprovider'] ?? '';
      details.authmethod = message[2]['authmethod'] ?? '';
      details.authrole = message[2]['authrole'] ?? '';
      if (message[2]['authextra'] != null) {
        (message[2]['authextra'] as Map).forEach((key, value) {
          details.authextra ??= <String, dynamic>{};
          details.authextra![key] = value;
        });
      }
      if (message[2]['roles'] != null) {
        details.roles = Roles();
        if (message[2]['roles']['dealer'] != null) {
          details.roles!.dealer = Dealer();
          if (message[2]['roles']['dealer']['features'] != null) {
            details.roles!.dealer!.features = DealerFeatures();
            details.roles!.dealer!.features!.callerIdentification = message[2]
                        ['roles']['dealer']['features']
                    ['caller_identification'] ??
                false;
            details.roles!.dealer!.features!.callTrustLevels = message[2]
                    ['roles']['dealer']['features']['call_trustlevels'] ??
                false;
            details.roles!.dealer!.features!.patternBasedRegistration =
                message[2]['roles']['dealer']['features']
                        ['pattern_based_registration'] ??
                    false;
            details.roles!.dealer!.features!.registrationMetaApi = message[2]
                        ['roles']['dealer']['features']
                    ['registration_meta_api'] ??
                false;
            details.roles!.dealer!.features!.sharedRegistration = message[2]
                    ['roles']['dealer']['features']['shared_registration'] ??
                false;
            details.roles!.dealer!.features!.sessionMetaApi = message[2]
                    ['roles']['dealer']['features']['session_meta_api'] ??
                false;
            details.roles!.dealer!.features!.callTimeout = message[2]['roles']
                    ['dealer']['features']['call_timeout'] ??
                false;
            details.roles!.dealer!.features!.callCanceling = message[2]
                    ['roles']['dealer']['features']['call_canceling'] ??
                false;
            details.roles!.dealer!.features!.progressiveCallResults =
                message[2]['roles']['dealer']['features']
                        ['progressive_call_results'] ??
                    false;
            details.roles!.dealer!.features!.payloadPassThruMode = message[2]
                        ['roles']['dealer']['features']
                    ['payload_passthru_mode'] ??
                false;
          }
        }
        if (message[2]['roles']['broker'] != null) {
          details.roles!.broker = Broker();
          if (message[2]['roles']['broker']['features'] != null) {
            details.roles!.broker!.features = BrokerFeatures();
            details.roles!.broker!.features!.publisherIdentification =
                message[2]['roles']['broker']['features']
                        ['publisher_identification'] ??
                    false;
            details.roles!.broker!.features!.publicationTrustLevels =
                message[2]['roles']['broker']['features']
                        ['publication_trustlevels'] ??
                    false;
            details.roles!.broker!.features!.patternBasedSubscription =
                message[2]['roles']['broker']['features']
                        ['pattern_based_subscription'] ??
                    false;
            details.roles!.broker!.features!.subscriptionMetaApi = message[2]
                        ['roles']['broker']['features']
                    ['subscription_meta_api'] ??
                false;
            details.roles!.broker!.features!.subscriberBlackWhiteListing =
                message[2]['roles']['broker']['features']
                        ['subscriber_blackwhite_listing'] ??
                    false;
            details.roles!.broker!.features!.sessionMetaApi = message[2]
                    ['roles']['broker']['features']['session_meta_api'] ??
                false;
            details.roles!.broker!.features!.publisherExclusion = message[2]
                    ['roles']['broker']['features']['publisher_exclusion'] ??
                false;
            details.roles!.broker!.features!.eventHistory = message[2]
                    ['roles']['broker']['features']['event_history'] ??
                false;
            details.roles!.broker!.features!.payloadPassThruMode = message[2]
                        ['roles']['broker']['features']
                    ['payload_passthru_mode'] ??
                false;
          }
        }
      }
      return Welcome(message[1], details);
    }
    if (messageId == MessageTypes.codeRegistered) {
      return Registered(message[1], message[2]);
    }
    if (messageId == MessageTypes.codeUnregistered) {
      return Unregistered(message[1]);
    }
    if (messageId == MessageTypes.codeInvocation) {
      return _addPayload(
          Invocation(
              message[1],
              message[2],
              InvocationDetails(message[3]['caller'], message[3]['procedure'],
                  message[3]['receive_progress'])),
          message,
          4);
    }
    if (messageId == MessageTypes.codeResult) {
      return _addPayload(
          Result(
              message[1],
              ResultDetails(
                  progress: message[2]['progress'],
                  pptScheme: message[2]['ppt_scheme'],
                  pptSerializer: message[2]['ppt_serializer'],
                  pptCipher: message[2]['ppt_cipher'],
                  pptKeyId: message[2]['ppt_keyid'])),
          message,
          3);
    }
    if (messageId == MessageTypes.codePublished) {
      return Published(message[1], message[2]);
    }
    if (messageId == MessageTypes.codeSubscribed) {
      return Subscribed(message[1], message[2]);
    }
    if (messageId == MessageTypes.codeUnsubscribed) {
      return Unsubscribed(
          message[1],
          message.length == 2
              ? null
              : UnsubscribedDetails(
                  message[2]['subscription'], message[2]['reason']));
    }
    if (messageId == MessageTypes.codeEvent) {
      return _addPayload(
          Event(
              message[1],
              message[2],
              EventDetails(
                  publisher: message[3]['publisher'],
                  trustlevel: message[3]['trustlevel'],
                  topic: message[3]['topic'])),
          message,
          4);
    }
    if (messageId == MessageTypes.codeError) {
      return _addPayload(
          Error(message[1], message[2], Map<String, Object>.from(message[3]),
              message[4]),
          message,
          5);
    }
    if (messageId == MessageTypes.codeAbort) {
      return Abort(message[2],
          message: message[1] == null ? null : message[1]['message']);
    }
    if (messageId == MessageTypes.codeGoodbye) {
      return Goodbye(
          message[1] == null ? null : GoodbyeMessage(message[1]['message']),
          message[2]);
    }
  }
  _logger.shout('Could not deserialize the message: $msgPack');
  // TODO respond with an error
  return null;
}