Skip to content

CsrpMessage

A CsrpMessage object represents a message that uses the CSRP specification.

Constructors

CsrpMessage new

CsrpMessage.new = function(sender: string?, recipients: {string} | string?, interactionId: string, fragment: number?, fragmentCount: number?, options: {[string]: any} | string?, body: string?): CsrpMessage

Returns a CsrpMessage. Throws an error if an argument is invalid.

Arguments:

  1. string? sender - The message sender's JobId.
  2. {string} or string? recipients - The message recipients' JobIds.
  3. string interactionId - The message interaction ID. Required for fragmented messages.
  4. number? fragment - The message fragment number.
  5. number? fragmentCount - The message fragment count. If nil, will be interpreted as 1.
  6. {[string]: any} or string? options - The message options.
  7. string? body - The message body.

Note

The first 6 arguments that form the message header must not contain semicolons (;). Additionally, the options argument must not contain equals signs (=) or commas (,). The message body can contain any characters.

CsrpMessage fromString

CsrpMessage.fromString = function(message: string): CsrpMessage

Parse a string into a CsrpMessage. Throws an error if the string is not a valid CSRP message.

Arguments:

  1. string message - The message string.

Properties

string? Sender

The message sender's JobId. Can be nil.

string? Recipients

A comma-separated list of the message recipients' JobIds. Can be nil. An empty string indicates that the message is broadcasted to all servers. Prefixing a recipient with a - indicates that the recipient should not process the message.

string InteractionId

The message interaction ID. Used to identify fragments of the same message. Can also be used to identify request-response pairs.

number? Fragment

The message fragment number. If nil, it will be interpreted as equal to FragmentCount if FragmentCount is not nil, otherwise 1.

number? FragmentCount

The total number of fragments in the message. If nil, it will be interpreted as 1.

string? Options

A comma-separated list of the message options. Can be nil. Each option is in the format key=value. Not used by Router, but can be used by the user to store additional information about the message.

string? Body

The message body. Can be nil and can contain any characters.


Serialization

A CsrpMessage object can be serialized into a string using the built-in tostring function.

local message = CsrpMessage.new("sender", "recipient", "interactionId", 1, 2, "option1=value1,option2=value2", "body")
print(tostring(message)) -- sender;recipient;interactionId;1;2;option1=value1,option2=value2;body