From ae567e579897b87c63e297472f207cec05939594 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 30 Apr 2026 22:01:41 -0700 Subject: [PATCH] Add README --- .gitignore | 1 + Cargo.toml | 6 ++++++ README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 4 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3a4d09e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "roto" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..a08dc6e --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# roto + +Rust protos without the P. + +The codegen is different; we don't create data structures. +We mark what where each field is, and only read it when asked. +The binary blob is never decompressed by the library; it is your +job to figure out how to store the data if you need to access it +more than once. + +And building protos? You use a builder. We don't make some fancy +structure and give you a marshal function, nah. You give us a blob +to write data into, and we write what you tell us, no questions asked. + +### Sample usage + +```rust +/* +message Hello { + string hello_world = 1; + message InnerWorld { + string thought = 1; + } + InnerWorld inner_world = 2; +} + */ + +fn parse_proto(data: &[u8]) -> Result { + // Scans the data, marks where each flag is as an offset + // into the proto. + let accessor = HelloProto::new(accessor)?; + // Load the hello world string; returns bytes, not + // a Rust string. + let hello_world = accessor.hello_world()?; + // Inspect a nested message; accessing inner_world scans it + // for flag locations and returns a similiar access struct + let inner_world = accessor.inner_world()?.thought()?; + + format!("{} is about {}", hello_world, inner_world) +} +``` + +### High level design + +The runtime library offers an iterator over the fields in a message, using the protobuf wire format provide +objects of flag and type. Codegen creates a 'wrapper' that iterates over the message, and records the +byte offset of each element. Helper methods in the wrapper give the user access to the name fields, +casted to the appropriate data type. + +### Literature + +https://protobuf.dev/programming-guides/encoding/ diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}