Update ObjectData value properties spec to match latest implementation#327
Update ObjectData value properties spec to match latest implementation#327
Conversation
textile/features.textile
Outdated
| ** @(OD2b)@ @encoding@ string - the encoding the client library should use to interpret the @value@ | ||
| ** @(OD2c)@ @value@ string, number, boolean or binary - a concrete value of the object | ||
| ** @(OD2b)@ @encoding@ string - can be set by the client to indicate that value in @string@ or @bytes@ field have an encoding | ||
| ** @(OD2c)@ This clause has been deleted |
There was a problem hiding this comment.
I believe there was a discussion recently about how strictly we should adhere to the rules regarding deleting/updating spec points in order to minimaze polluting the spec with "This clause has been deleted" statements. @lawrence-forooghian
Do you think it makes sense to add this statement now in this case and for OD3a? The development in other SDKs just started but I assume you may already have references to those spec points
There was a problem hiding this comment.
I think we should make a interface/class for ObjectValue, that way it's easy to interpret, instead of 4 top level fields for value.
There was a problem hiding this comment.
export class ObjectValue {
public value: boolean | Bufferlike | number | string;
constructor(value: boolean | Bufferlike | number | string) {
// runtime type checks can be added if used as a part of public API
this.value = value
}
getSize(): number {
if (typeof this.value === 'boolean') {
return 1;
}
if (typeof this.value === 'number') {
return 8;
}
if (typeof this.value === 'string') {
return this.value.length;
}
// bytes (Bufferlike)
if (this.value && typeof this.value === 'object' && 'byteLength' in this.value) {
return (this.value as any).byteLength;
}
if (this.value && typeof this.value === 'object' && 'length' in this.value) {
return (this.value as any).length;
}
return 0;
}
}
There was a problem hiding this comment.
So ObjectData becomes
export interface ObjectData {
/** A reference to another object, used to support composable object structures. */
objectId?: string;
/** Can be set by the client to indicate that value in `string` or `bytes` field have an encoding. */
encoding?: string;
/** The value stored in this ObjectData. */
value?: ObjectValue;
}
This way it's easy to read with better checks, and we encapsulate business logic as a part of ObjectValue
There was a problem hiding this comment.
In other languages, we can have four different constructors that initializes ObjectValue with given type.
There was a problem hiding this comment.
I am happy for it to be replaced ( also true for subsequent specs ), since it's not implemented in any other SDKs yet
There was a problem hiding this comment.
From an ably-cocoa point of view, implementing these spec points is still a WIP so am happy for them just to be replaced, will leave Sachin to decide.
I'd prefer spec points to be replaced without the "This clause has been deleted" statement to keep it cleaner while we still can and it's WIP.
So @sacOO7 it's your call since you may have some code already written for this - can I just replace the spec for the value property and not include the "This clause has been deleted"?
There was a problem hiding this comment.
I am happy for it to be replaced ( also true for subsequent specs ), since it's not implemented in any other SDKs yet
oh, I see, thanks! You replied while I was writing a comment so I didn't see it
There was a problem hiding this comment.
Sachin said above that he's happy for it to be replaced
There was a problem hiding this comment.
will update the PR and merge it
This was changed in ably-js PR [1] [1] ably/ably-js#2026
7f845c3 to
c2f155a
Compare
…Message class Based on the spec added in [1], and updates to the spec made in [2] and [3] [1] ably/specification#298 [2] ably/specification#327 [3] ably/specification#328
…Message class Based on the spec added in [1], and updates to the spec made in [2] and [3] [1] ably/specification#298 [2] ably/specification#327 [3] ably/specification#328
This was changed in ably-js PR [1]
[1] ably/ably-js#2026