Skip to content

SerializedMessages

Thomas Schwotzer edited this page Aug 14, 2021 · 6 revisions

Messages are disseminated in your ASAP P2P system. The actual message structure is opaque to the system. Your message content is of type byte[]. It is your task to produce this byte array and to deserialize received messages. You can implement both methods as you please. Nevertheless, there are some experiences we have made after implementing several apps. We want to share this best practise.

Implement a message class

public class YourMessage {
    public static YourMessage produceYourMessage(/* your message parts */) { ... }
    public static YourMessage produceYourMessage(byte[]) { ... }
    public byte[] serialize() { ..}
}

This code sketches a message class. It provides two static factory methods: one produces a message object by your parameters. The other one produces a message object from its serialized format. The third – and only non static – method serializes this message.

Clone this wiki locally