Skip to content

Commit f1ae6ee

Browse files
committed
[AIT-208] feat: update LiveObjects messages fields to support protocol v6
- Update `ObjectOperation` fields to protocol v6 names (`mapCreate`, `mapSet`, `mapRemove`, `counterCreate`, `counterInc`). Internally and externally - Remove previous field names on `ObjectOperation`
1 parent f57632f commit f1ae6ee

21 files changed

Lines changed: 602 additions & 364 deletions

File tree

lib/src/main/java/io/ably/lib/transport/Defaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Defaults {
1212
* spec: G4
1313
* </p>
1414
*/
15-
public static final String ABLY_PROTOCOL_VERSION = "5";
15+
public static final String ABLY_PROTOCOL_VERSION = "6";
1616

1717
public static final String ABLY_AGENT_VERSION = String.format("%s/%s", "ably-java", BuildConfig.VERSION);
1818

lib/src/test/java/io/ably/lib/test/realtime/RealtimeHttpHeaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void realtime_websocket_param_test() {
8181
* Defaults.ABLY_VERSION_PARAM, as ultimately the request param has been derived from those values.
8282
*/
8383
assertEquals("Verify correct version", requestParameters.get("v"),
84-
Collections.singletonList("5"));
84+
Collections.singletonList("6"));
8585

8686
/* Spec RSC7d3
8787
* This test should not directly validate version against Defaults.ABLY_AGENT_VERSION, nor

lib/src/test/java/io/ably/lib/test/rest/HttpHeaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void header_lib_channel_publish() {
8181
* from those values.
8282
*/
8383
Assert.assertNotNull("Expected headers", headers);
84-
Assert.assertEquals(headers.get("x-ably-version"), "5");
84+
Assert.assertEquals(headers.get("x-ably-version"), "6");
8585
Assert.assertEquals(headers.get("ably-agent"), expectedAblyAgentHeader);
8686
// RSA7e2
8787
Assert.assertNull("Shouldn't include 'x-ably-clientid' if `clientId` is not specified", headers.get("x-ably-clientid"));

lib/src/test/java/io/ably/lib/transport/DefaultsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DefaultsTest {
99

1010
@Test
1111
public void protocol_version_CSV2() {
12-
assertThat(Defaults.ABLY_PROTOCOL_VERSION, is("5"));
12+
assertThat(Defaults.ABLY_PROTOCOL_VERSION, is("6"));
1313
}
1414

1515
@Test

liveobjects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ internal class DefaultRealtimeObjects(internal val channelName: String, internal
126126
operation = ObjectOperation(
127127
action = ObjectOperationAction.MapCreate,
128128
objectId = objectId,
129-
map = initialMapValue.map,
130-
nonce = nonce,
131-
initialValue = initialValueJSONString,
129+
mapCreate = initialMapValue,
130+
mapCreateWithObjectId = MapCreateWithObjectId(nonce = nonce, initialValue = initialValueJSONString),
132131
)
133132
)
134133

@@ -161,9 +160,8 @@ internal class DefaultRealtimeObjects(internal val channelName: String, internal
161160
operation = ObjectOperation(
162161
action = ObjectOperationAction.CounterCreate,
163162
objectId = objectId,
164-
counter = initialCounterValue.counter,
165-
nonce = nonce,
166-
initialValue = initialValueJSONString
163+
counterCreate = initialCounterValue,
164+
counterCreateWithObjectId = CounterCreateWithObjectId(nonce = nonce, initialValue = initialValueJSONString),
167165
)
168166
)
169167

liveobjects/src/main/kotlin/io/ably/lib/objects/Helpers.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,3 @@ internal fun Binary.size(): Int {
177177
return data.size
178178
}
179179

180-
internal data class CounterCreatePayload(
181-
val counter: ObjectsCounter
182-
)
183-
184-
internal data class MapCreatePayload(
185-
val map: ObjectsMap
186-
)

liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt

Lines changed: 140 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,70 @@ internal sealed class ObjectValue {
6666
}
6767

6868
/**
69-
* A MapOp describes an operation to be applied to a Map object.
70-
* Spec: OMO1
69+
* Payload for MAP_CREATE operation.
70+
* Spec: MCR*
7171
*/
72-
internal data class ObjectsMapOp(
73-
/**
74-
* The key of the map entry to which the operation should be applied.
75-
* Spec: OMO2a
76-
*/
77-
val key: String,
72+
internal data class MapCreate(
73+
val semantics: ObjectsMapSemantics, // MCR2a
74+
val entries: Map<String, ObjectsMapEntry> // MCR2b
75+
)
7876

79-
/**
80-
* The data that the map entry should contain if the operation is a MAP_SET operation.
81-
* Spec: OMO2b
82-
*/
83-
val data: ObjectData? = null
77+
/**
78+
* Payload for MAP_SET operation.
79+
* Spec: MST*
80+
*/
81+
internal data class MapSet(
82+
val key: String, // MST2a
83+
val value: ObjectData // MST2b - REQUIRED
8484
)
8585

8686
/**
87-
* A CounterOp describes an operation to be applied to a Counter object.
88-
* Spec: OCO1
87+
* Payload for MAP_REMOVE operation.
88+
* Spec: MRM*
8989
*/
90-
internal data class ObjectsCounterOp(
91-
/**
92-
* The data value that should be added to the counter
93-
* Spec: OCO2a
94-
*/
95-
val amount: Double? = null
90+
internal data class MapRemove(
91+
val key: String // MRM2a
92+
)
93+
94+
/**
95+
* Payload for COUNTER_CREATE operation.
96+
* Spec: CCR*
97+
*/
98+
internal data class CounterCreate(
99+
val count: Double // CCR2a - REQUIRED
100+
)
101+
102+
/**
103+
* Payload for COUNTER_INC operation.
104+
* Spec: CIN*
105+
*/
106+
internal data class CounterInc(
107+
val number: Double // CIN2a - REQUIRED
108+
)
109+
110+
/**
111+
* Payload for OBJECT_DELETE operation.
112+
* Spec: ODE*
113+
* No fields - action is sufficient
114+
*/
115+
internal object ObjectDelete
116+
117+
/**
118+
* Payload for MAP_CREATE_WITH_OBJECT_ID operation.
119+
* Spec: MCRO*
120+
*/
121+
internal data class MapCreateWithObjectId(
122+
val initialValue: String, // MCRO2a
123+
val nonce: String // MCRO2b
124+
)
125+
126+
/**
127+
* Payload for COUNTER_CREATE_WITH_OBJECT_ID operation.
128+
* Spec: CCRO*
129+
*/
130+
internal data class CounterCreateWithObjectId(
131+
val initialValue: String, // CCRO2a
132+
val nonce: String // CCRO2b
96133
)
97134

98135
/**
@@ -175,48 +212,52 @@ internal data class ObjectOperation(
175212
val objectId: String,
176213

177214
/**
178-
* The payload for the operation if it is an operation on a Map object type.
179-
* i.e. MAP_SET, MAP_REMOVE.
180-
* Spec: OOP3c
215+
* Payload for MAP_CREATE operation.
216+
* Spec: OOP3j
181217
*/
182-
val mapOp: ObjectsMapOp? = null,
218+
val mapCreate: MapCreate? = null,
183219

184220
/**
185-
* The payload for the operation if it is an operation on a Counter object type.
186-
* i.e. COUNTER_INC.
187-
* Spec: OOP3d
221+
* Payload for MAP_SET operation.
222+
* Spec: OOP3k
188223
*/
189-
val counterOp: ObjectsCounterOp? = null,
224+
val mapSet: MapSet? = null,
190225

191226
/**
192-
* The payload for the operation if the operation is MAP_CREATE.
193-
* Defines the initial value for the Map object.
194-
* Spec: OOP3e
227+
* Payload for MAP_REMOVE operation.
228+
* Spec: OOP3l
195229
*/
196-
val map: ObjectsMap? = null,
230+
val mapRemove: MapRemove? = null,
231+
232+
/**
233+
* Payload for COUNTER_CREATE operation.
234+
* Spec: OOP3m
235+
*/
236+
val counterCreate: CounterCreate? = null,
237+
238+
/**
239+
* Payload for COUNTER_INC operation.
240+
* Spec: OOP3n
241+
*/
242+
val counterInc: CounterInc? = null,
197243

198244
/**
199-
* The payload for the operation if the operation is COUNTER_CREATE.
200-
* Defines the initial value for the Counter object.
201-
* Spec: OOP3f
245+
* Payload for OBJECT_DELETE operation.
246+
* Spec: OOP3o
202247
*/
203-
val counter: ObjectsCounter? = null,
248+
val objectDelete: ObjectDelete? = null,
204249

205250
/**
206-
* The nonce, must be present on create operations. This is the random part
207-
* that has been hashed with the type and initial value to create the object ID.
208-
* Spec: OOP3g
251+
* Payload for MAP_CREATE_WITH_OBJECT_ID operation.
252+
* Spec: OOP3p
209253
*/
210-
val nonce: String? = null,
254+
val mapCreateWithObjectId: MapCreateWithObjectId? = null,
211255

212256
/**
213-
* The initial value json string for the object. This value should be used along with the nonce
214-
* and timestamp to create the object ID. Frontdoor will use this to verify the object ID.
215-
* After verification the json string will be decoded into the Map or Counter objects and
216-
* the initialValue and nonce will be removed.
217-
* Spec: OOP3h
257+
* Payload for COUNTER_CREATE_WITH_OBJECT_ID operation.
258+
* Spec: OOP3q
218259
*/
219-
val initialValue: String? = null,
260+
val counterCreateWithObjectId: CounterCreateWithObjectId? = null,
220261
)
221262

222263
/**
@@ -362,12 +403,17 @@ internal fun ObjectMessage.size(): Int {
362403
* Spec: OOP4
363404
*/
364405
private fun ObjectOperation.size(): Int {
365-
val mapOpSize = mapOp?.size() ?: 0 // Spec: OOP4b, OMO3
366-
val counterOpSize = counterOp?.size() ?: 0 // Spec: OOP4c, OCO3
367-
val mapSize = map?.size() ?: 0 // Spec: OOP4d, OMP4
368-
val counterSize = counter?.size() ?: 0 // Spec: OOP4e, OCN3
369-
370-
return mapOpSize + counterOpSize + mapSize + counterSize
406+
val mapCreateSize = mapCreate?.size() ?: 0
407+
val mapSetSize = mapSet?.size() ?: 0
408+
val mapRemoveSize = mapRemove?.size() ?: 0
409+
val counterCreateSize = counterCreate?.size() ?: 0
410+
val counterIncSize = counterInc?.size() ?: 0
411+
val mapCreateWithObjectIdSize = mapCreateWithObjectId?.size() ?: 0
412+
val counterCreateWithObjectIdSize = counterCreateWithObjectId?.size() ?: 0
413+
414+
return mapCreateSize + mapSetSize + mapRemoveSize +
415+
counterCreateSize + counterIncSize +
416+
mapCreateWithObjectIdSize + counterCreateWithObjectIdSize
371417
}
372418

373419
/**
@@ -383,22 +429,52 @@ private fun ObjectState.size(): Int {
383429
}
384430

385431
/**
386-
* Calculates the size of an ObjectMapOp in bytes.
387-
* Spec: OMO3
432+
* Calculates the size of a MapCreate payload in bytes.
433+
*/
434+
private fun MapCreate.size(): Int {
435+
return entries.entries.sumOf { it.key.length + it.value.size() }
436+
}
437+
438+
/**
439+
* Calculates the size of a MapSet payload in bytes.
440+
*/
441+
private fun MapSet.size(): Int {
442+
return key.length + value.size()
443+
}
444+
445+
/**
446+
* Calculates the size of a MapRemove payload in bytes.
447+
*/
448+
private fun MapRemove.size(): Int {
449+
return key.length
450+
}
451+
452+
/**
453+
* Calculates the size of a CounterCreate payload in bytes.
454+
*/
455+
private fun CounterCreate.size(): Int {
456+
return 8 // Double is 8 bytes
457+
}
458+
459+
/**
460+
* Calculates the size of a CounterInc payload in bytes.
461+
*/
462+
private fun CounterInc.size(): Int {
463+
return 8 // Double is 8 bytes
464+
}
465+
466+
/**
467+
* Calculates the size of a MapCreateWithObjectId payload in bytes.
388468
*/
389-
private fun ObjectsMapOp.size(): Int {
390-
val keySize = key.length // Spec: OMO3d - Size of the key
391-
val dataSize = data?.size() ?: 0 // Spec: OMO3b - Size of the data, calculated per "OD3"
392-
return keySize + dataSize
469+
private fun MapCreateWithObjectId.size(): Int {
470+
return initialValue.length + nonce.length
393471
}
394472

395473
/**
396-
* Calculates the size of a CounterOp in bytes.
397-
* Spec: OCO3
474+
* Calculates the size of a CounterCreateWithObjectId payload in bytes.
398475
*/
399-
private fun ObjectsCounterOp.size(): Int {
400-
// Size is 8 if amount is a number, 0 if amount is null or omitted
401-
return if (amount != null) 8 else 0 // Spec: OCO3a, OCO3b
476+
private fun CounterCreateWithObjectId.size(): Int {
477+
return initialValue.length + nonce.length
402478
}
403479

404480
/**

0 commit comments

Comments
 (0)