serializeToString method
Converts a WAMP message object into a string json message
Implementation
String serializeToString(AbstractMessage message) {
if (message is Hello) {
return '[${MessageTypes.codeHello},${message.realm == null ? 'null' : '"${message.realm!}"'},${_serializeDetails(message.details)}]';
}
if (message is Authenticate) {
return '[${MessageTypes.codeAuthenticate},"${message.signature ?? ""}",${message.extra == null ? '{}' : json.encode(message.extra)}]';
}
if (message is Register) {
return '[${MessageTypes.codeRegister},${message.requestId},${_serializeRegisterOptions(message.options)},"${message.procedure}"]';
}
if (message is Unregister) {
return '[${MessageTypes.codeUnregister},${message.requestId},${message.registrationId}]';
}
if (message is Call) {
return '[${MessageTypes.codeCall},${message.requestId},${_serializeCallOptions(message.options)},"${message.procedure}"${_serializePayload(message)}]';
}
if (message is Yield) {
return '[${MessageTypes.codeYield},${message.invocationRequestId},${_serializeYieldOptions(message.options)}${_serializePayload(message)}]';
}
if (message is Invocation) {
// for serializer unit test only
return '[${MessageTypes.codeInvocation},${message.requestId},${message.registrationId},{}${_serializePayload(message)}]';
}
if (message is Publish) {
return '[${MessageTypes.codePublish},${message.requestId},${_serializePublish(message.options)},"${message.topic}"${_serializePayload(message)}]';
}
if (message is Event) {
return '[${MessageTypes.codeEvent},${message.subscriptionId},${message.publicationId}${_serializePayload(message)}]';
}
if (message is Subscribe) {
return '[${MessageTypes.codeSubscribe},${message.requestId},${_serializeSubscribeOptions(message.options)},"${message.topic}"]';
}
if (message is Unsubscribe) {
return '[${MessageTypes.codeUnsubscribe},${message.requestId},${message.subscriptionId}]';
}
if (message is Error) {
return '[${MessageTypes.codeError},${message.requestTypeId},${message.requestId},${json.encode(message.details)},"${message.error}"${_serializePayload(message)}]';
}
if (message is Abort) {
return '[${MessageTypes.codeAbort},${message.message != null ? '{"message":"${message.message!.message}"}' : "{}"},"${message.reason}"]';
}
if (message is Goodbye) {
return '[${MessageTypes.codeGoodbye},${message.message != null ? '{"message":"${message.message!.message ?? ""}"}' : "{}"},"${message.reason}"]';
}
_logger.shout('Could not serialize the message of type: $message');
throw Exception(''); // TODO think of something helpful here...
}