@@ -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 */
364421private 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