#protocols #loro #crdt

loro-protocol

Rust implementation of the Loro Syncing Protocol encoder/decoder

1 unstable release

0.1.0 Nov 30, 2025

#1660 in Encoding


Used in 2 crates

MIT license

34KB
706 lines

loro-protocol (Rust)

Rust implementation of the Loro syncing protocol encoder/decoder. Mirrors the TypeScript package in packages/loro-protocol and follows the wire format described in protocol.md and the end-to-end encrypted flow in protocol-e2ee.md.

Features

  • Encode/decode Join, DocUpdate, FragmentHeader/Fragment, UpdateError, and Leave messages
  • 256 KiB message size guard to match the wire spec
  • Bytes utilities (BytesWriter, BytesReader) for varint/varbytes/varstring
  • %ELO container parsing; Rust-side encryption helpers are WIP and may evolve

Usage

Add the crate to your workspace (published crate name matches the package):

cargo add loro-protocol

Encode and decode messages:

use loro_protocol::{encode, decode, ProtocolMessage, CrdtType};

let msg = ProtocolMessage::JoinRequest {
    crdt: CrdtType::Loro,
    room_id: "room-123".to_string(),
    auth: vec![],
    version: vec![],
};

let bytes = encode(&msg)?;
let roundtrip = decode(&bytes)?;
assert_eq!(roundtrip, msg);

Streaming-friendly decode:

use loro_protocol::try_decode;

let buf = /* bytes from the wire */;
if let Some(msg) = try_decode(&buf) {
    // valid message
} else {
    // malformed or incomplete buffer
}

Tests

cargo test -p loro-protocol

Spec References

  • protocol.md for the wire format and message semantics
  • protocol-e2ee.md for %ELO encryption details

No runtime deps