Yrs EndOfBuffer error

UPDATE. I figured it out. I don’t actually need to decode those messages at this stage. I just need to broadcast them to the other connected users.

I will try this again later when I implement a persistence layer. I’ve had a suspicion that I wasn’t able to run updates on those CRDTs because they expect to be run against a document.

Hiyo -

I’m trying to implement the sync protocol in Rust, for a Quill / Yjs collaborative editor. I haven’t added a persistence layer yet - I really just have a thin wrapper around the DefaultProtocol Yrs implementation and want to use it to allow collaborative editing.

So far I’ve gotten the initial handshake set up - I receive a Step1, reply with Step2, follow up by sending a Step1, etc. Those requests all seem to work fine through the websocket connection. Awareness updates also seem not to cause problems.

I hit an error when I try decoding the binary I get from typing into my text editor. The ongoing updates. I’m calling out to Rust from Elixir using the Rustler library. My handle_update function looks like this:

fn handle_update<'a>(env: Env<'a>, update_bin: Binary<'a>) -> Term<'a> {
    let update = Update::decode_v1(&update_bin).unwrap();

In Elixir I’m able to pattern match on the incoming binary to ensure that only <<0, 2, ...tail>> binary values are getting passed to this handle_update function. I am sending the entire received binary into the handle_update function. I tried removing the first bit, then the second bit (in case the decoder func doesn’t like the protocol prefix), and I get UnexpectedValue errors in both cases.

But that Update::decode_v1 call keeps resulting in an EndOfBuffer error. The full formatted message is “while trying to read more data (expected: 1 bytes), an unexpected end of buffer was reached”.

I’m especially confused because I’m using that same decoder function in handle_sync_step_2, and as far as I can tell, handle_update is the same as handle_sync_step_2. Or at least, they both accept the same kind of update struct.

Is there a different decoder function I’m supposed to use for handle_update? A different way to create an Update struct to pass to the DefaultProtocol.handle_update? I’ve been trying to crack this for a few coding sessions now and I keep coming up empty handed. My guess is I’m just way off track in how I’m trying to do this. Any help would be appreciated!

Thank you!

1 Like

Hi @eileen,

GitHub - y-crdt/yrs-warp: Yrs web socket data exchange protocol implementation for tokio warp server might also be a good starting point for a custom websocket server written in rust.