Skip to content

Commit 0ecbdd6

Browse files
committed
Add spec tags for ObjectMessage encoding/decoding
Based on the spec added in [1] [1] ably/specification#335
1 parent 3b358b9 commit 0ecbdd6

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/plugins/objects/livemap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
200200
!client.Platform.BufferUtils.isBuffer(value) &&
201201
!(value instanceof LiveObject)
202202
) {
203-
throw new client.ErrorInfo('Map value data type is unsupported', 40013, 400);
203+
throw new client.ErrorInfo('Map value data type is unsupported', 40013, 400); // OD4a
204204
}
205205
}
206206

@@ -237,7 +237,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
237237
objectId,
238238
nonce,
239239
initialValue: encodedInitialValue,
240-
initialValueEncoding: format,
240+
initialValueEncoding: format, // OOP5a2, OOP5b2
241241
} as ObjectOperation,
242242
},
243243
client.Utils,

src/plugins/objects/objectmessage.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface ObjectData {
3434
/** A reference to another object, used to support composable object structures. */
3535
objectId?: string; // OD2a
3636

37-
/** Can be set by the client to indicate that value in `string` or `bytes` field have an encoding. */
37+
/** May be set by the client to indicate that value in `string` field have an encoding. */
3838
encoding?: string; // OD2b
3939
/** A primitive boolean leaf value in the object graph. Only one value field can be set. */
4040
boolean?: boolean; // OD2c
@@ -213,6 +213,8 @@ export class ObjectMessage {
213213
* Mutates the provided ObjectMessage.
214214
*
215215
* Uses encoding functions from regular `Message` processing.
216+
*
217+
* @spec OM4
216218
*/
217219
static encode(message: ObjectMessage, client: BaseClient): ObjectMessage {
218220
const encodeInitialValueFn: EncodeInitialValueFunction = (data, encoding) => {
@@ -260,6 +262,8 @@ export class ObjectMessage {
260262
* Format is used to decode the bytes value as it's implicitly encoded depending on the protocol used:
261263
* - json: bytes are base64 encoded string
262264
* - msgpack: bytes have a binary representation and don't need to be decoded
265+
*
266+
* @spec OM5
263267
*/
264268
static async decode(
265269
message: ObjectMessage,
@@ -367,6 +371,7 @@ export class ObjectMessage {
367371
}
368372
}
369373

374+
/** @spec OD5 */
370375
private static async _decodeObjectData(
371376
objectData: ObjectData,
372377
client: BaseClient,
@@ -379,11 +384,12 @@ export class ObjectMessage {
379384
// - if connection is json - "bytes" was received as a base64 string, need to decode it to a buffer
380385

381386
if (format !== 'msgpack' && objectData.bytes != null) {
382-
// connection is using JSON protocol, decode bytes value
387+
// OD5b2 - connection is using JSON protocol, decode bytes value
383388
objectData.bytes = client.Platform.BufferUtils.base64Decode(String(objectData.bytes));
384389
}
385390
}
386391

392+
/** @spec OOP5 */
387393
private static _encodeObjectOperation(
388394
objectOperation: ObjectOperation,
389395
encodeObjectDataFn: EncodeObjectDataFunction,
@@ -449,6 +455,7 @@ export class ObjectMessage {
449455
return objectStateCopy;
450456
}
451457

458+
/** @spec OD4 */
452459
private static _encodeObjectData(data: ObjectData, encodeFn: EncodeObjectDataFunction): ObjectData {
453460
const encodedData = encodeFn(data);
454461
return encodedData;
@@ -468,6 +475,7 @@ export class ObjectMessage {
468475
objectState?: ObjectState;
469476
} {
470477
const encodeInitialValueFn: EncodeInitialValueFunction = (data, encoding) => {
478+
// OOP5a1, OOP5b1 - initialValue encoded based on the protocol used
471479
const { data: encodedData, encoding: newEncoding } = messageEncoding.encodeDataForWire(data, encoding, format);
472480
return {
473481
data: encodedData,
@@ -484,6 +492,7 @@ export class ObjectMessage {
484492

485493
let encodedBytes: any = data.bytes;
486494
if (data.bytes != null) {
495+
// OD4c2, OD4d2
487496
const result = messageEncoding.encodeDataForWire(data.bytes, data.encoding, format);
488497
encodedBytes = result.data;
489498
// no need to change the encoding

0 commit comments

Comments
 (0)