diff --git a/README.md b/README.md index 694c8ab..d64e445 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/generator.rs b/src/generator.rs index 77016c3..ca247b0 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -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() {