Replies: 2 comments 1 reply
-
@zyddnys tonic includes a utility (as does Prost): Take a look at tonic's examples: |
Beta Was this translation helpful? Give feedback.
-
This imports generated protobuf code, but I want to load actual data into a generated protobuf struct. syntax = "proto3";
package testproto;
message TestData {
string hello = 1;
}
message TestFile {
repeated TestData data = 1;
} Actual data (hello_data.txt)
I want something to parse hello_data.txt pub mod test_proto {
tonic::include_proto!("testproto");
}
fn readfile() {
let fileio = std::fs::File::open("hello_data.txt").unwrap();
let test_file: test_proto::TestFile = prost::from_file(fileio).unwrap();
assert_eq!(test_file.data.first().unwrap().hello, "hello world 1");
} The above example can be parsed using google.protobuf.text_format in Python, can I do this in rust? |
Beta Was this translation helpful? Give feedback.
-
I am using tonic gRPC library which uses prost to generate the underlying protobuf rust structs. Now I have a protobuf text format file which I want to load its data to a generate strcut. Can I do this? Do I need to use some other libraries?
Beta Was this translation helpful? Give feedback.
All reactions