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