Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
Created March 8, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrubeck/61ca4a5af956f1be6a2f2d3a458dc55a to your computer and use it in GitHub Desktop.
Save mbrubeck/61ca4a5af956f1be6a2f2d3a458dc55a to your computer and use it in GitHub Desktop.
extern crate protobuf_codegen_pure;
fn main() {
protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
out_dir: ".",
input: &["./user_data.proto"],
includes: &["."],
customize: protobuf_codegen_pure::Customize::default(),
}).expect("protoc");
}
[package]
name = "pb"
version = "0.1.0"
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
edition = "2018"
[[bin]]
name = "pb"
path = "main.rs"
[dependencies]
protobuf = "2.4"
[build-dependencies]
protobuf-codegen-pure = "2.4"
mod user_data;
use protobuf::Message;
fn main() {
let mut rmsg = user_data::user_data::new();
rmsg.set_id("1234".into());
rmsg.set_nick("test".into());
let msg = rmsg.write_to_bytes().unwrap();
println!("{:?}", msg);
let test: user_data::user_data = protobuf::parse_from_bytes(&msg).unwrap();
println!("serialized: {:?}\noriginal: {:?}", test, rmsg);
}
message user_data {
required string id = 1;
optional string nick = 2;
optional string theme = 3;
optional string admin_id = 4;
optional string lang = 5;
optional double credit = 6;
optional double bonus_credit = 7;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment