Permalink
Browse files

Use serde-protobuf (DOESN'T WORK YET)

  • Loading branch information...
sevagh committed Mar 29, 2017
1 parent 7334e07 commit c8cfbaa0b04bf0240f393d71a9745f632a579320
Showing with 163 additions and 201 deletions.
  1. +125 −3 Cargo.lock
  2. +4 −5 Cargo.toml
  3. +1 −5 src/main.rs
  4. +21 −15 src/protob.rs
  5. +0 −173 src/unknown.rs
  6. +6 −0 testdata/address.fdset
  7. +6 −0 testdata/address.proto
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -6,8 +6,7 @@ authors = ["Sevag Hanssian <sevag.hanssian@gmail.com>"]
[dependencies]
docopt = "0.7"
rustc-serialize = "0.3"
[dependencies.protobuf]
git = "https://github.com/stepancheg/rust-protobuf.git"
[dev-dependencies.protobuf]
git = "https://github.com/stepancheg/rust-protobuf.git"
serde-protobuf = "0.5"
serde = "0.9.12"
serde-value = "0.4.0"
protobuf = "1.2.1"
View
@@ -1,19 +1,15 @@
#![crate_type = "bin"]
extern crate protobuf;
extern crate rustc_serialize;
extern crate docopt;
mod protob;
mod unknown;
use docopt::Docopt;
use protob::{process_single, process_stream};
use std::io::{self, Read, BufReader};
use std::fs::File;
use protob::{process_single, process_stream};
const USAGE: &'static str = "
pq - Protobuf pretty-printer
View
@@ -1,34 +1,40 @@
use protobuf::CodedInputStream;
use unknown::Unknown;
extern crate serde;
extern crate protobuf;
extern crate serde_protobuf;
extern crate serde_value;
use std::fs;
use std::io::Read;
use self::serde::de::Deserialize;
use self::serde_protobuf::descriptor::Descriptors;
use self::serde_protobuf::de::Deserializer;
use self::serde_value::Value;
pub fn process_single(read: &mut Read) {
let mut buffer = Vec::new();
read.read(&mut buffer).unwrap();
let mut byte_is = CodedInputStream::from_bytes(&buffer);
let mut byte_is = protobuf::CodedInputStream::from_bytes(&buffer);
match byte_is.read_message::<Unknown>() {
Err(e) => panic!(e),
Ok(x) => println!("{:?}", x),
}
let mut file = fs::File::open("testdata/address.fdset").unwrap();
let proto = protobuf::parse_from_reader(&mut file).unwrap();
let descriptors = Descriptors::from_proto(&proto);
let mut deserializer = Deserializer::for_named_message(&descriptors, "pq-rs", byte_is).unwrap();
let value = Value::deserialize(&mut deserializer).unwrap();
println!("{:?}", value);
}
pub fn process_stream(read: &mut Read) {
let mut stream = CodedInputStream::new(read);
let mut stream = protobuf::stream::CodedInputStream::new(read);
loop {
match stream.eof() {
Err(e) => panic!(e),
Ok(true) => break,
Ok(false) => {
match stream.read_message::<Unknown>() {
Err(e) => println!("{}", e),
Ok(x) => println!("{:?}", x),
}
}
Ok(false) => break,
//todo: actually do deserialization here
}
}
}
Oops, something went wrong.

0 comments on commit c8cfbaa

Please sign in to comment.