Crates.io | pbuf |
lib.rs | pbuf |
version | 0.3.31 |
source | src |
created_at | 2016-07-01 15:46:44.54838 |
updated_at | 2016-12-24 15:31:08.239311 |
description | Read/Write to/from anything that implements Read/Write to/from protobuf. |
homepage | |
repository | https://github.com/durch/pbuf |
max_upload_size | |
id | 5556 |
size | 6,165 |
Reads/Writes to anything that implements Read/Write to/from protobuf...
Examples assume Msg
is your protobuf and msg.rs is where it lives, see rust-protobuf on how to generate .rs
from .proto
files.
pbuf = "0.3.2"
extern crate pbuf;
extern crate protobuf;
use std::io::prelude::*;
use std::io::{BufReader, self};
use std::fs::File;
mod msg;
use msg::Msg;
use pbuf::read_pbuf;
let mut reader = Box::new(BufReader::new(io::stdin()));
// To read from file
// let mut reader = Box::new(BufReader::new(File::open (&<file pointer>).unwrap()))
// Reads entire buffer and fill
let mut msgs: Vec<Msg> = read_pbuf(&mut reader);
extern crate pbuf;
extern crate protobuf;
use std::io::prelude::*;
use std::io::{BufWriter, self};
use std::fs::File;
mod msg;
use msg::Msg;
use pbuf::write_pbuf;
let mut writer = Box::new(BufWriter::new(io::stdout()));
// To write to file
// let mut writer = Box::new(BufWriter::new(File::create(&<file pointer>).unwrap()))
for msg in msgs.iter() {
write_pbuf(msg, &mut writer);
}