Skip to content

Commit f819138

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 f819138

21 files changed

Lines changed: 607 additions & 331 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ internal class DefaultRealtimeObjects(internal val channelName: String, internal
126126
operation = ObjectOperation(
127127
action = ObjectOperationAction.MapCreate,
128128
objectId = objectId,
129-
map = initialMapValue.map,
129+
mapCreate = initialMapValue,
130130
nonce = nonce,
131131
initialValue = initialValueJSONString,
132132
)
@@ -161,7 +161,7 @@ internal class DefaultRealtimeObjects(internal val channelName: String, internal
161161
operation = ObjectOperation(
162162
action = ObjectOperationAction.CounterCreate,
163163
objectId = objectId,
164-
counter = initialCounterValue.counter,
164+
counterCreate = initialCounterValue,
165165
nonce = nonce,
166166
initialValue = initialValueJSONString
167167
)

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: 146 additions & 54 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,32 +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,
197231

198232
/**
199-
* The payload for the operation if the operation is COUNTER_CREATE.
200-
* Defines the initial value for the Counter object.
201-
* Spec: OOP3f
233+
* Payload for COUNTER_CREATE operation.
234+
* Spec: OOP3m
202235
*/
203-
val counter: ObjectsCounter? = null,
236+
val counterCreate: CounterCreate? = null,
237+
238+
/**
239+
* Payload for COUNTER_INC operation.
240+
* Spec: OOP3n
241+
*/
242+
val counterInc: CounterInc? = null,
243+
244+
/**
245+
* Payload for OBJECT_DELETE operation.
246+
* Spec: OOP3o
247+
*/
248+
val objectDelete: ObjectDelete? = null,
249+
250+
/**
251+
* Payload for MAP_CREATE_WITH_OBJECT_ID operation.
252+
* Spec: OOP3p
253+
*/
254+
val mapCreateWithObjectId: MapCreateWithObjectId? = null,
255+
256+
/**
257+
* Payload for COUNTER_CREATE_WITH_OBJECT_ID operation.
258+
* Spec: OOP3q
259+
*/
260+
val counterCreateWithObjectId: CounterCreateWithObjectId? = null,
204261

205262
/**
206263
* The nonce, must be present on create operations. This is the random part
@@ -362,12 +419,17 @@ internal fun ObjectMessage.size(): Int {
362419
* Spec: OOP4
363420
*/
364421
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
422+
val mapCreateSize = mapCreate?.size() ?: 0
423+
val mapSetSize = mapSet?.size() ?: 0
424+
val mapRemoveSize = mapRemove?.size() ?: 0
425+
val counterCreateSize = counterCreate?.size() ?: 0
426+
val counterIncSize = counterInc?.size() ?: 0
427+
val mapCreateWithObjectIdSize = mapCreateWithObjectId?.size() ?: 0
428+
val counterCreateWithObjectIdSize = counterCreateWithObjectId?.size() ?: 0
429+
430+
return mapCreateSize + mapSetSize + mapRemoveSize +
431+
counterCreateSize + counterIncSize +
432+
mapCreateWithObjectIdSize + counterCreateWithObjectIdSize
371433
}
372434

373435
/**
@@ -383,22 +445,52 @@ private fun ObjectState.size(): Int {
383445
}
384446

385447
/**
386-
* Calculates the size of an ObjectMapOp in bytes.
387-
* Spec: OMO3
448+
* Calculates the size of a MapCreate payload in bytes.
449+
*/
450+
private fun MapCreate.size(): Int {
451+
return entries.entries.sumOf { it.key.length + it.value.size() }
452+
}
453+
454+
/**
455+
* Calculates the size of a MapSet payload in bytes.
456+
*/
457+
private fun MapSet.size(): Int {
458+
return key.length + value.size()
459+
}
460+
461+
/**
462+
* Calculates the size of a MapRemove payload in bytes.
463+
*/
464+
private fun MapRemove.size(): Int {
465+
return key.length
466+
}
467+
468+
/**
469+
* Calculates the size of a CounterCreate payload in bytes.
470+
*/
471+
private fun CounterCreate.size(): Int {
472+
return 8 // Double is 8 bytes
473+
}
474+
475+
/**
476+
* Calculates the size of a CounterInc payload in bytes.
477+
*/
478+
private fun CounterInc.size(): Int {
479+
return 8 // Double is 8 bytes
480+
}
481+
482+
/**
483+
* Calculates the size of a MapCreateWithObjectId payload in bytes.
388484
*/
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
485+
private fun MapCreateWithObjectId.size(): Int {
486+
return initialValue.length + nonce.length
393487
}
394488

395489
/**
396-
* Calculates the size of a CounterOp in bytes.
397-
* Spec: OCO3
490+
* Calculates the size of a CounterCreateWithObjectId payload in bytes.
398491
*/
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
492+
private fun CounterCreateWithObjectId.size(): Int {
493+
return initialValue.length + nonce.length
402494
}
403495

404496
/**

0 commit comments

Comments
 (0)