@@ -46,9 +46,41 @@ public class Message extends BaseMessage {
4646 */
4747 public String connectionKey ;
4848
49+ /**
50+ * (TM2k) serial string – an opaque string that uniquely identifies the message. If a message received from Ably
51+ * (whether over realtime or REST, eg history) with an action of MESSAGE_CREATE does not contain a serial,
52+ * the SDK must set it equal to its version.
53+ */
54+ public String serial ;
55+
56+ /**
57+ * (TM2p) version string – an opaque string that uniquely identifies the message, and is different for different versions.
58+ * If a message received from Ably over a realtime transport does not contain a version,
59+ * the SDK must set it to <channelSerial>:<padded_index> from the channelSerial field of the enclosing ProtocolMessage,
60+ * and padded_index is the index of the message inside the messages array of the ProtocolMessage,
61+ * left-padded with 0s to three digits (for example, the second entry might be foo:001)
62+ */
63+ public String version ;
64+
65+ /**
66+ * (TM2j) action enum
67+ */
68+ public MessageAction action ;
69+
70+ /**
71+ * (TM2o) createdAt time in milliseconds since epoch. If a message received from Ably
72+ * (whether over realtime or REST, eg history) with an action of MESSAGE_CREATE does not contain a createdAt,
73+ * the SDK must set it equal to the TM2f timestamp.
74+ */
75+ public Long createdAt ;
76+
4977 private static final String NAME = "name" ;
5078 private static final String EXTRAS = "extras" ;
5179 private static final String CONNECTION_KEY = "connectionKey" ;
80+ private static final String SERIAL = "serial" ;
81+ private static final String VERSION = "version" ;
82+ private static final String ACTION = "action" ;
83+ private static final String CREATED_AT = "createdAt" ;
5284
5385 /**
5486 * Default constructor
@@ -128,6 +160,10 @@ void writeMsgpack(MessagePacker packer) throws IOException {
128160 int fieldCount = super .countFields ();
129161 if (name != null ) ++fieldCount ;
130162 if (extras != null ) ++fieldCount ;
163+ if (serial != null ) ++fieldCount ;
164+ if (version != null ) ++fieldCount ;
165+ if (action != null ) ++fieldCount ;
166+ if (createdAt != null ) ++fieldCount ;
131167 packer .packMapHeader (fieldCount );
132168 super .writeFields (packer );
133169 if (name != null ) {
@@ -138,6 +174,22 @@ void writeMsgpack(MessagePacker packer) throws IOException {
138174 packer .packString (EXTRAS );
139175 extras .write (packer );
140176 }
177+ if (serial != null ) {
178+ packer .packString (SERIAL );
179+ packer .packString (serial );
180+ }
181+ if (version != null ) {
182+ packer .packString (VERSION );
183+ packer .packString (version );
184+ }
185+ if (action != null ) {
186+ packer .packString (ACTION );
187+ packer .packInt (action .ordinal ());
188+ }
189+ if (createdAt != null ) {
190+ packer .packString (CREATED_AT );
191+ packer .packLong (createdAt );
192+ }
141193 }
142194
143195 Message readMsgpack (MessageUnpacker unpacker ) throws IOException {
@@ -157,6 +209,14 @@ Message readMsgpack(MessageUnpacker unpacker) throws IOException {
157209 name = unpacker .unpackString ();
158210 } else if (fieldName .equals (EXTRAS )) {
159211 extras = MessageExtras .read (unpacker );
212+ } else if (fieldName .equals (SERIAL )) {
213+ serial = unpacker .unpackString ();
214+ } else if (fieldName .equals (VERSION )) {
215+ version = unpacker .unpackString ();
216+ } else if (fieldName .equals (ACTION )) {
217+ action = MessageAction .tryFindByOrdinal (unpacker .unpackInt ());
218+ } else if (fieldName .equals (CREATED_AT )) {
219+ createdAt = unpacker .unpackLong ();
160220 } else {
161221 Log .v (TAG , "Unexpected field: " + fieldName );
162222 unpacker .skipValue ();
@@ -313,6 +373,12 @@ protected void read(final JsonObject map) throws MessageDecodeException {
313373 }
314374 extras = MessageExtras .read ((JsonObject ) extrasElement );
315375 }
376+
377+ serial = readString (map , SERIAL );
378+ version = readString (map , VERSION );
379+ Integer actionOrdinal = readInt (map , ACTION );
380+ action = actionOrdinal == null ? null : MessageAction .tryFindByOrdinal (actionOrdinal );
381+ createdAt = readLong (map , CREATED_AT );
316382 }
317383
318384 public static class Serializer implements JsonSerializer <Message >, JsonDeserializer <Message > {
@@ -328,6 +394,18 @@ public JsonElement serialize(Message message, Type typeOfMessage, JsonSerializat
328394 if (message .connectionKey != null ) {
329395 json .addProperty (CONNECTION_KEY , message .connectionKey );
330396 }
397+ if (message .serial != null ) {
398+ json .addProperty (SERIAL , message .serial );
399+ }
400+ if (message .version != null ) {
401+ json .addProperty (VERSION , message .version );
402+ }
403+ if (message .action != null ) {
404+ json .addProperty (ACTION , message .action .ordinal ());
405+ }
406+ if (message .createdAt != null ) {
407+ json .addProperty (CREATED_AT , message .createdAt );
408+ }
331409 return json ;
332410 }
333411
0 commit comments