Update README, monkey patch generator.rs
This commit is contained in:
@@ -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
|
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.
|
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
|
### Sample usage
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
|||||||
+2
-2
@@ -32,7 +32,7 @@ fn map_type_to_rust_accessor(field_type: i32, label: i32) -> (String, String) {
|
|||||||
), // TYPE_STRING
|
), // TYPE_STRING
|
||||||
1 => (
|
1 => (
|
||||||
"f64".to_string(),
|
"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
|
), // TYPE_DOUBLE
|
||||||
2 => (
|
2 => (
|
||||||
"f32".to_string(),
|
"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 {
|
pub fn generate_rust_code(set: &FileDescriptorSet) -> String {
|
||||||
let mut output = String::new();
|
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");
|
output.push_str("use std::str;\n\n");
|
||||||
|
|
||||||
for file_res in set.file() {
|
for file_res in set.file() {
|
||||||
|
|||||||
Reference in New Issue
Block a user