I have a question about the updateHandler
functions that call systemProtocol.writeUpdate
I found two instances where this happens (sorry the platform won’t allow me more than 2 links):
yjs/y-websocket/blob/master/src/y-websocket.js#L252
yjs/y-websocket/blob/master/bin/utils.js#L82
In both cases, before the syncProtocol.writeUpdate(encoder, update)
call, encoding.writeVarUint(encoder, messageSync)
call happens. Which means messageSync
variable with value 0
is appended to the encoder.
This is the implementation of the writeUpdate
function. It also appends a varUint
to the encoder, but in this case it’s messageYjsUpdate
with the value 2
So in the end, we have an array with contents: [0, 2, ...actualUpdateData]
.
As I understand readSyncMessage
function expects a message with [messageType : varUint, ...updateData: Uint8Array]
structure, so that second element, 2
will be treated as a part of the data.
Is this a bug or am I missing something?
Edit: Simplified/inlined code of what seems to be happening:
const update = new Uint8Array([...someStateUpdate])
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, 0)
encoding.writeVarUint(encoder, 2)
encoding.writeVarUint8Array(encoder, update)
broadCastMessage(encoding.toUint8Array(encoder))