Skip to content

Commit c1c981c

Browse files
authored
Merge pull request #335 from ably/objects-encoding
Add spec for `ObjectMessage` encoding and decoding
2 parents f595d0c + f7d43ff commit c1c981c

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

specifications/features.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,8 @@ Presence ops.
18601860
- `(OM3d)` The size of the `extras` property is the string length of its JSON representation
18611861
- `(OM3f)` The size of the `clientId` property is its string length
18621862
- `(OM3e)` The size of a `null` or omitted property is zero
1863+
- `(OM4)` For `ObjectMessage` encoding see `ObjectData` [OD4](#OD4) and `ObjectOperation` [OOP5](#OOP5) encoding
1864+
- `(OM5)` For `ObjectMessage` decoding see `ObjectData` [OD5](#OD5) decoding
18631865

18641866
#### ObjectOperation
18651867

@@ -1872,16 +1874,23 @@ Presence ops.
18721874
- `(OOP3d)` `counterOp` `ObjectsCounterOp` object - the payload for the operation if it is an operation on an `ObjectsCounter` object type
18731875
- `(OOP3e)` `map` `ObjectsMap` object - the payload for the operation if the operation is `MAP_CREATE`. Defines the initial value for the `ObjectsMap` object
18741876
- `(OOP3f)` `counter` `ObjectsCounter` object - the payload for the operation if the operation is `COUNTER_CREATE`. Defines the initial value for the `ObjectsCounter` object
1875-
- `(OOP3g)` `nonce` string - the nonce, must be present on `COUNTER_CREATE` and `MAP_CREATE` operations sent to the server
1876-
- `(OOP3h)` `initialValue` binary - the initial value bytes for the object
1877-
- `(OOP3i)` `initialValueEncoding` string - defines how the `initialValue` should be interpreted. Should be `msgpack` or `json`
1877+
- `(OOP3g)` `nonce` string - the nonce. Must be present on `COUNTER_CREATE` and `MAP_CREATE` operations sent to the server. Should not be accessed by the client library if received from the server
1878+
- `(OOP3h)` `initialValue` binary - the initial value bytes for the object. Must be present on `COUNTER_CREATE` and `MAP_CREATE` operations sent to the server. Should not be accessed by the client library if received from the server
1879+
- `(OOP3i)` `initialValueEncoding` string - defines how the `initialValue` should be interpreted by the server. Must be `msgpack` or `json`. Must be present on `COUNTER_CREATE` and `MAP_CREATE` operations sent to the server. Should not be accessed by the client library if received from the server
18781880
- `(OOP4)` The size of the `ObjectOperation` is calculated as follows:
18791881
- `(OOP4a)` The size is the sum of the sizes of the `mapOp`, `counterOp`, `map`, and `counter` properties
18801882
- `(OOP4b)` The size of the `mapOp` property is calculated per [OMO3](#OMO3)
18811883
- `(OOP4c)` The size of the `counterOp` property is calculated per [OCO3](#OCO3)
18821884
- `(OOP4d)` The size of the `map` property is calculated per [OMP4](#OMP4)
18831885
- `(OOP4e)` The size of the `counter` property is calculated per [OCN3](#OCN3)
18841886
- `(OOP4f)` The size of a `null` or omitted property is zero
1887+
- `(OOP5)` `ObjectOperation` encoding:
1888+
- `(OOP5a)` When the MessagePack protocol is used:
1889+
- `(OOP5a1)` A binary `ObjectOperation.initialValue` is encoded as a MessagePack binary type
1890+
- `(OOP5a2)` Set `ObjectOperation.initialValueEncoding` to `msgpack`
1891+
- `(OOP5b)` When the JSON protocol is used:
1892+
- `(OOP5b1)` A binary `ObjectOperation.initialValue` is Base64-encoded and represented as a JSON string
1893+
- `(OOP5b2)` Set `ObjectOperation.initialValueEncoding` to `json`
18851894

18861895
#### ObjectState
18871896

@@ -1960,18 +1969,41 @@ Presence ops.
19601969
- `(OD1)` An `ObjectData` represents a value in an object on a channel
19611970
- `(OD2)` The attributes available in an `ObjectData` are:
19621971
- `(OD2a)` `objectId` string - a reference to another object
1963-
- `(OD2b)` `encoding` string - can be set by the client to indicate that value in `string` or `bytes` field have an encoding
1964-
- `(OD2c)` `boolean` boolean - a primitive boolean leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - can be set at a time
1965-
- `(OD2d)` `bytes` binary - a primitive binary leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - can be set at a time
1966-
- `(OD2e)` `number` number - a primitive number leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - can be set at a time
1967-
- `(OD2f)` `string` string - a primitive string leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - can be set at a time
1972+
- `(OD2b)` `encoding` string - may be set by the client library to indicate that value in `string` field have an encoding
1973+
- `(OD2c)` `boolean` boolean - a primitive boolean leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - must be set at a time
1974+
- `(OD2d)` `bytes` binary \| string - a primitive binary leaf value in the object graph. It is sent to and received from the server as a Base64-encoded string when using the JSON protocol. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - must be set at a time
1975+
- `(OD2e)` `number` number - a primitive number leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - must be set at a time
1976+
- `(OD2f)` `string` string - a primitive string leaf value in the object graph. Only one of the value fields - `boolean`, `bytes`, `number` or `string` - must be set at a time
19681977
- `(OD3)` The size of the `ObjectData` is calculated as follows:
19691978
- `(OD3a)` The size is the sum of the sizes of the `boolean`, `bytes`, `number`, and `string` properties
19701979
- `(OD3b)` If set, the size of a `boolean` property is 1
19711980
- `(OD3c)` If set, the size of a `bytes` property is its size in bytes (of the actual binary, not the base64 representation, regardless of whether the binary protocol is in use)
19721981
- `(OD3d)` If set, the size of a `number` property is 8
19731982
- `(OD3e)` If set, the size of a `string` property is its length
19741983
- `(OD3f)` The size of a `null` or omitted property is zero
1984+
- `(OD4)` `ObjectData` encoding:
1985+
- `(OD4a)` Payloads must be booleans, binary, numbers, strings, or JSON-encodable objects or arrays. Any other data type must not be permitted and result in an error with code 40013
1986+
- `(OD4b)` `ObjectData.encoding` must be left unset unless specified otherwise by the payload encoding procedure in [OD4c](#OD4c) and [OD4d](#OD4d)
1987+
- `(OD4c)` When the MessagePack protocol is used:
1988+
- `(OD4c1)` A boolean payload is encoded as a MessagePack boolean type, and the result is set on the `ObjectData.boolean` attribute
1989+
- `(OD4c2)` A binary payload is encoded as a MessagePack binary type, and the result is set on the `ObjectData.bytes` attribute
1990+
- `(OD4c3)` A number payload is encoded as a MessagePack float64 type, and the result is set on the `ObjectData.number` attribute
1991+
- `(OD4c4)` A string payload is encoded as a MessagePack string type, and the result is set on the `ObjectData.string` attribute
1992+
- `(OD4c5)` A payload consisting of a JSON-encodable object or array is stringified as a JSON object or array, encoded as a MessagePack string type, and the result is set on the `ObjectData.string` attribute. The `ObjectData.encoding` attribute is then set to "json"
1993+
- `(OD4d)` When the JSON protocol is used:
1994+
- `(OD4d1)` A boolean payload is represented as a JSON boolean and set on the `ObjectData.boolean` attribute
1995+
- `(OD4d2)` A binary payload is Base64-encoded and represented as a JSON string; the result is set on the `ObjectData.bytes` attribute
1996+
- `(OD4d3)` A number payload is represented as a JSON number and set on the `ObjectData.number` attribute
1997+
- `(OD4d4)` A string payload is represented as a JSON string and set on the `ObjectData.string` attribute
1998+
- `(OD4d5)` A payload consisting of a JSON-encodable object or array is stringified as a JSON object or array, represented as a JSON string and the result is set on the `ObjectData.string` attribute. The `ObjectData.encoding` attribute is then set to "json"
1999+
- `(OD5)` `ObjectData` decoding:
2000+
- `(OD5a)` When the MessagePack protocol is used:
2001+
- `(OD5a1)` The payloads in `ObjectData.boolean`, `ObjectData.bytes`, `ObjectData.number`, and `ObjectData.string` are decoded as their corresponding MessagePack types
2002+
- `(OD5a2)` If `ObjectData.encoding` is set to "json", the `ObjectData.string` content is decoded by parsing the string as JSON
2003+
- `(OD5b)` When the JSON protocol is used:
2004+
- `(OD5b1)` The payloads in `ObjectData.boolean`, `ObjectData.number`, and `ObjectData.string` are decoded as their corresponding JSON types
2005+
- `(OD5b2)` The `ObjectData.bytes` payload is Base64-decoded into a binary value
2006+
- `(OD5b3)` If `ObjectData.encoding` is set to "json", the `ObjectData.string` content is decoded by parsing the string as JSON
19752007

19762008
#### Annotation
19772009

@@ -2983,7 +3015,7 @@ Each type, method, and attribute is labelled with the name of one or more clause
29833015
objectId: String? // OD2a
29843016
encoding: String? // OD2b
29853017
boolean: Boolean? // OD2c
2986-
bytes: Binary? // OD2d
3018+
bytes: Binary? | String? // OD2d
29873019
number: Number? // OD2e
29883020
string: String? // OD2f
29893021

0 commit comments

Comments
 (0)