API reference / @node-ts/bus-core / MessageSerializer
Class: MessageSerializer
Defined in: packages/bus-core/src/serialization/message-serializer.ts:16
This a wrapper around the real serializer. Unlike JsonSerializer, whose sole job is parsing data, this class will do some plumbing work to look up the Handler Registry for the message constructor.
Normally, transports will use this instead of the real serializer. Each bus has its own, which restores messages with that bus' handlers and message types.
Constructors
Constructor
new MessageSerializer(
serializer,
handlerRegistry,
messageTypes
): MessageSerializer;Defined in: packages/bus-core/src/serialization/message-serializer.ts:22
Parameters
| Parameter | Type | Description |
|---|---|---|
serializer | Serializer | the serializer the bus is configured with |
handlerRegistry | HandlerRegistry | the handlers of the bus, which give the class of each message |
messageTypes | MessageTypes | the message types the bus is configured with |
Returns
MessageSerializer
Methods
deserialize()
deserialize<MessageType>(serializedMessage): MessageType;Defined in: packages/bus-core/src/serialization/message-serializer.ts:41
Parses a message. A message that has a handler registered is created from its message class, or as a plain object for a message declared with defineCommand or defineEvent. With the default JsonSerializer, a message without one, such as one handled by a custom handler, is still restored as a plain object when the bus' message types have it, e.g. for a message declared as an interface. A custom serializer only gets the messages that have a handler, since it may not use message types.
Type Parameters
| Type Parameter |
|---|
MessageType extends Message |
Parameters
| Parameter | Type | Description |
|---|---|---|
serializedMessage | string | the message as it was received |
Returns
MessageType
the message
serialize()
serialize<MessageType>(message): string;Defined in: packages/bus-core/src/serialization/message-serializer.ts:28
Type Parameters
| Type Parameter |
|---|
MessageType extends Message |
Parameters
| Parameter | Type |
|---|---|
message | MessageType |
Returns
string