-
-
Notifications
You must be signed in to change notification settings - Fork 52
Description
y-protocols/awareness currently encodes updates using a combination of writeVarString and JSON.stringify today.
The codebase I am working on uses a decent amount of single precision floating point numbers in awareness, and so would benefit from binary encoding. My understanding is that lib0 can encode arbitrary structures as binary using the writeAny method (used in yjs).
Backwards compatibility may be a little difficult with introducing binary encoding, as old clients would expect a JSON stringified value. To allow users of the library to control the rollout, it might be possible to introduce similar functionality to how YJS supports V1 and V2 updates - where an encoder is passed in as a parameter (with a default value).
For example:
class AwarenessEncoderV1 {
encodeAwareness(state, encoder) {
encoding.writeVarString(encoder, JSON.stringify(state));
}
}
...
export const applyAwarenessUpdate = (awareness, update, origin, encoder = new AwarenessEncoderV1()) => { ... }
Would you be open to accepting a contribution with these changes?