Crates.io | protobuf_message_factory |
lib.rs | protobuf_message_factory |
version | 0.1.3 |
source | src |
created_at | 2019-09-08 06:13:15.89575 |
updated_at | 2019-09-10 15:19:13.926407 |
description | generate a message factory to create message by message name |
homepage | https://github.com/egmkang/protobuf_message_factory |
repository | https://github.com/egmkang/protobuf_message_factory |
max_upload_size | |
id | 163163 |
size | 11,415 |
this repo provide you a way to generate a message factory to create a message instance by message name.
//use can do this in cpp
google::protobuf::Descriptor* desc =
google::protobuf::DescriptorPool::generated_pool()
->FindMessageTypeByName("mypkg.MyType");
google::protobuf::Message* message =
google::protobuf::MessageFactory::generated_factory()
->GetPrototype(desc)->New();
extern crate proto;
use proto::factory::*;
//now you can do this in rust
let desc = get_descriptor(&"mypkg.MyType".to_string()).unwrap();
let message = desc.new_instance();
API Docs: https://docs.rs/protobuf_message_factory
create a project to generate proto
$ cargo new proto
Add this to Cargo.toml:
[dependencies]
protobuf = "2.8.0"
[build-dependencies]
protoc-rust = "2.8.0"
protobuf_message_factory = "0.1.3"
add .proto
file into src/
add codes to build.rs
extern crate protobuf_message_factory;
use protobuf_message_factory::*;
...
fn main() {
let proto_path = "src/";
let proto_files = get_protos_info(proto_path);
let proto_messages = get_proto_list(&proto_files);
//!!! this is importent. !!!
protoc_rust::run(protoc_rust::Args {
out_dir: proto_path,
input: &protos,
includes: &[proto_path],
customize: Customize {
..Default::default()
},
}).expect("protoc");
//now generate factory codes
generate_factory_file(proto_path, &proto_files);
}
add proto
deps into your project's toml
[dependencies]
proto = {version="^0", path="proto_path"}
step 1 create a proj named proto
, replace proto_path
into yours
MIT