First pass at runtime

This commit is contained in:
2026-04-30 23:13:24 -07:00
parent ae567e5798
commit 6912ff37d3
3 changed files with 484 additions and 2 deletions
+12 -2
View File
@@ -1,6 +1,6 @@
# roto
Rust protos without the P.
Rust protos without the pointers.
The codegen is different; we don't create data structures.
We mark what where each field is, and only read it when asked.
@@ -28,7 +28,7 @@ message Hello {
fn parse_proto(data: &[u8]) -> Result<String> {
// Scans the data, marks where each flag is as an offset
// into the proto.
let accessor = HelloProto::new(accessor)?;
let accessor = HelloProto::new(data)?;
// Load the hello world string; returns bytes, not
// a Rust string.
let hello_world = accessor.hello_world()?;
@@ -40,6 +40,16 @@ fn parse_proto(data: &[u8]) -> Result<String> {
}
```
### Sample builder usage
```rust
let mut buf = [0u8; 1024];
let mut builder = ProtoBuilder::new(&mut buf);
builder.write_string(1, "hello world")?;
builder.write_int32(2, 42)?;
let data = builder.finish()?; // returns the used slice of the buffer
```
### High level design
The runtime library offers an iterator over the fields in a message, using the protobuf wire format provide