loro-protocol 0.1.0

Rust implementation of the Loro Syncing Protocol encoder/decoder
Documentation
  • Coverage
  • 20.44%
    28 out of 137 items documented1 out of 44 items with examples
  • Size
  • Source code size: 48.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.05 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • loro-dev/protocol
    21 4 6
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zxch3n

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