Update README, monkey patch generator.rs

This commit is contained in:
2026-05-03 13:31:39 -07:00
parent 31476485cf
commit 79f2cbf640
2 changed files with 10 additions and 2 deletions
+8
View File
@@ -12,6 +12,14 @@ 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.
### Design
The `protoc` command generates a CodeGeneratorRequest message; `protoc-gen-roto` (from src/bin/protoc-gen-roto.rs)
reads this message from stdin, and generated a CodeGeneratorResponse, which it sends to stdout.
The generated files get written to disk by protoc; these should be included in the Rust code being developed to
use the protobuffers in question.
### Sample usage
```rust
+2 -2
View File
@@ -32,7 +32,7 @@ fn map_type_to_rust_accessor(field_type: i32, label: i32) -> (String, String) {
), // TYPE_STRING
1 => (
"f64".to_string(),
"f64::from_le_bytes(bytes.try_into().map_err(|_| RotoError::WireFormatViolation)?)".to_string(),
"Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| RotoError::WireFormatViolation)?))".to_string(),
), // TYPE_DOUBLE
2 => (
"f32".to_string(),
@@ -77,7 +77,7 @@ fn map_type_to_rust_builder(field_type: i32) -> (String, String) {
pub fn generate_rust_code(set: &FileDescriptorSet) -> String {
let mut output = String::new();
output.push_str("use crate::{ProtoAccessor, ProtoBuilder, Result, RotoError};\n");
output.push_str("use crate::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator};\n");
output.push_str("use std::str;\n\n");
for file_res in set.file() {