44import java .lang .reflect .Type ;
55import java .util .Map ;
66
7+ import com .google .gson .annotations .JsonAdapter ;
8+ import io .ably .lib .objects .LiveObjectSerializer ;
9+ import io .ably .lib .objects .LiveObjectsHelper ;
10+ import io .ably .lib .objects .LiveObjectsJsonSerializer ;
11+ import org .jetbrains .annotations .Nullable ;
712import org .msgpack .core .MessageFormat ;
813import org .msgpack .core .MessagePacker ;
914import org .msgpack .core .MessageUnpacker ;
@@ -123,6 +128,14 @@ public ProtocolMessage(Action action, String channel) {
123128 public AuthDetails auth ;
124129 public Map <String , String > params ;
125130 public Annotation [] annotations ;
131+ /**
132+ * This will be null if we skipped decoding this property due to user not requesting Objects functionality
133+ * JsonAdapter annotation supports java version (1.8) mentioned in build.gradle
134+ * This is targeted and specific to the state field, so won't affect other fields
135+ */
136+ @ Nullable
137+ @ JsonAdapter (LiveObjectsJsonSerializer .class )
138+ public Object [] state ;
126139
127140 public boolean hasFlag (final Flag flag ) {
128141 return (flags & flag .getMask ()) == flag .getMask ();
@@ -147,6 +160,7 @@ void writeMsgpack(MessagePacker packer) throws IOException {
147160 if (params != null ) ++fieldCount ;
148161 if (channelSerial != null ) ++fieldCount ;
149162 if (annotations != null ) ++fieldCount ;
163+ if (state != null && LiveObjectsHelper .getLiveObjectSerializer () != null ) ++fieldCount ;
150164 packer .packMapHeader (fieldCount );
151165 packer .packString ("action" );
152166 packer .packInt (action .getValue ());
@@ -186,6 +200,15 @@ void writeMsgpack(MessagePacker packer) throws IOException {
186200 packer .packString ("annotations" );
187201 AnnotationSerializer .writeMsgpackArray (annotations , packer );
188202 }
203+ if (state != null ) {
204+ LiveObjectSerializer liveObjectsSerializer = LiveObjectsHelper .getLiveObjectSerializer ();
205+ if (liveObjectsSerializer != null ) {
206+ packer .packString ("state" );
207+ liveObjectsSerializer .writeMsgpackArray (state , packer );
208+ } else {
209+ Log .w (TAG , "Skipping 'state' field msgpack serialization because LiveObjectsSerializer not found" );
210+ }
211+ }
189212 }
190213
191214 ProtocolMessage readMsgpack (MessageUnpacker unpacker ) throws IOException {
@@ -248,6 +271,15 @@ ProtocolMessage readMsgpack(MessageUnpacker unpacker) throws IOException {
248271 case "annotations" :
249272 annotations = AnnotationSerializer .readMsgpackArray (unpacker );
250273 break ;
274+ case "state" :
275+ LiveObjectSerializer liveObjectsSerializer = LiveObjectsHelper .getLiveObjectSerializer ();
276+ if (liveObjectsSerializer != null ) {
277+ state = liveObjectsSerializer .readMsgpackArray (unpacker );
278+ } else {
279+ Log .w (TAG , "Skipping 'state' field msgpack deserialization because LiveObjectsSerializer not found" );
280+ unpacker .skipValue ();
281+ }
282+ break ;
251283 default :
252284 Log .v (TAG , "Unexpected field: " + fieldName );
253285 unpacker .skipValue ();
0 commit comments