Skip to content

Allow encoding awareness values as binary in updates #26

@Myrannas

Description

@Myrannas

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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions