Created
March 8, 2019 19:26
-
-
Save mbrubeck/61ca4a5af956f1be6a2f2d3a458dc55a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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