Skip to content

Commit

Permalink
Merge branch 'master' into no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopesculian committed Jan 22, 2020
2 parents b56b68e + 5f0516b commit 1c5f753
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
- test: Adding missing tests
- chore: Changes to the build process or auxiliary tools/libraries/documentation

## quick-protobuf 0.6.4
- feat: failible get byte

## pb-rs 0.8.3
- feat: allow rpc with `{ }`

## pb-rs 0.8.2
- feat: add optional Owned variant when generating Messages (relies on `Pin`)
- fix: propagate `dont_use_cow` to all messages
Expand All @@ -16,7 +22,6 @@
- feat: avoid Cow::Borrow when comparing `&str`

## pb-rs 0.8.0

- feat: Added the ability to use custom RPC generation code
- feat: Added the ability to modify custom derives such as derive-new
- feat: (Large change) Added the `dont_use_cow` method [v2 and v3 tested] which replaces lifetimes
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ It provides both:
- no need to use google `protoc` tool to generate the modules
- [**quick-protobuf**](quick-protobuf), a protobuf file parser:
- this is the crate that you will typically refer to in your library. The generated modules will assume it has been imported.
- it acts like an event parser, the logic to convert it into struct is handle by `pb-rs`
- it acts like an event parser, the logic to convert it into struct is handled by `pb-rs`

## Example: protobuf_example project

Expand Down Expand Up @@ -104,7 +104,7 @@ You can find basic examples in the [examples](examples) directory.

## Message <-> struct

The best way to check for all kind of generated code is to look for the codegen_example data:
The best way to check for all kinds of generated code is to look for the codegen_example data:
- definition: [data_types.proto](quick-protobuf/examples/pb_rs/data_types.proto)
- generated code: [data_types.rs](quick-protobuf/examples/pb_rs/data_types.rs)

Expand Down Expand Up @@ -229,7 +229,7 @@ This library is an alternative to the widely used [rust-protobuf](https://github
#### Pros / Cons

- Pros
- [Much faster](quick-protobuf/benches/rust-protobuf), in particular when working with string, bytes and repeated packed fixed size fields (no extra allocation)
- [Much faster](perftest), in particular when working with string, bytes and repeated packed fixed size fields (no extra allocation)
- No need to install `protoc` on your machine
- No trait objects: faster/simpler parser
- Very simple generated modules (~10x smaller) so you can easily understand what is happening
Expand All @@ -255,7 +255,7 @@ quick-protobuf is particularly good at reading large bytes.

## Contribution

Any help is welcomed! (Pull requests of course, bug report, missing functionality etc...)
Any help is welcome! (Pull requests of course, bug reports, missing functionality etc...)

## Licence

Expand Down
2 changes: 1 addition & 1 deletion pb-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pb-rs"
version = "0.8.2"
version = "0.8.3"
description = "A converter from proto files into quick-protobuf compatible rust module"
authors = ["Johann Tuffe <[email protected]>"]
keywords = ["protobuf", "parser", "quick-protobuf"]
Expand Down
21 changes: 19 additions & 2 deletions pb-rs/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ named!(
tag!("rpc")
>> many1!(br)
>> name: word
>> many0!(br)
>> tag!("(")
>> many0!(br)
>> arg: word
Expand All @@ -287,7 +288,19 @@ named!(
>> many0!(br)
>> ret: word
>> many0!(br)
>> tag!(");")
>> tag!(")")
>> many0!(br)
>> alt!(
do_parse!(
tuple!(
tag!("{"),
many0!(br),
many0!(alt!(option_ignore | map!(tag!(";"), |_| ()))),
many0!(br),
tag!("}")
) >> ()
) | map!(tag!(";"), |_| ())
)
>> many0!(br)
>> (RpcFunctionDeclaration { name, arg, ret })
)
Expand Down Expand Up @@ -632,6 +645,7 @@ mod test {
service RpcService {
rpc function0(InStruct0) returns (OutStruct0);
rpc function1(InStruct1) returns (OutStruct1);
rpc function2 ( InStruct2 ) returns ( OutStruct2 ) { }
}
"#;

Expand All @@ -641,13 +655,17 @@ mod test {
let service = &descriptor.rpc_services.get(0).expect("Service not found!");
let func0 = service.functions.get(0).expect("Function 0 not returned!");
let func1 = service.functions.get(1).expect("Function 1 not returned!");
let func2 = service.functions.get(2).expect("Function 2 not returned!");
assert_eq!("RpcService", service.service_name);
assert_eq!("function0", func0.name);
assert_eq!("InStruct0", func0.arg);
assert_eq!("OutStruct0", func0.ret);
assert_eq!("function1", func1.name);
assert_eq!("InStruct1", func1.arg);
assert_eq!("OutStruct1", func1.ret);
assert_eq!("function2", func2.name);
assert_eq!("InStruct2", func2.arg);
assert_eq!("OutStruct2", func2.ret);
}
other => panic!("Could not parse RPC Service: {:?}", other),
}
Expand All @@ -666,5 +684,4 @@ mod test {
other => panic!("Could not parse RPC Function Declaration: {:?}", other),
}
}

}
2 changes: 1 addition & 1 deletion quick-protobuf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "quick-protobuf"
description = "A pure Rust protobuf (de)serializer. Quick."
version = "0.6.3"
version = "0.6.4"
authors = ["Johann Tuffe <[email protected]>"]
keywords = ["protobuf", "parser"]
license = "MIT"
Expand Down
15 changes: 12 additions & 3 deletions quick-protobuf/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ impl BytesReader {
/// Reads fixed64 (little endian u64)
#[inline]
fn read_fixed<M, F: Fn(&[u8]) -> M>(&mut self, bytes: &[u8], len: usize, read: F) -> Result<M> {
let v = read(&bytes[self.start..self.start + len]);
let v = read(
&bytes
.get(self.start..self.start + len)
.ok_or_else(|| Error::UnexpectedEndOfBuffer)?,
);
self.start += len;
Ok(v)
}
Expand Down Expand Up @@ -341,14 +345,19 @@ impl BytesReader {
/// Reads bytes (Vec<u8>)
#[inline]
pub fn read_bytes<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a [u8]> {
self.read_len_varint(bytes, |r, b| Ok(&b[r.start..r.end]))
self.read_len_varint(bytes, |r, b| {
b.get(r.start..r.end)
.ok_or_else(|| Error::UnexpectedEndOfBuffer)
})
}

/// Reads string (String)
#[inline]
pub fn read_string<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a str> {
self.read_len_varint(bytes, |r, b| {
::core::str::from_utf8(&b[r.start..r.end]).map_err(|e| e.into())
b.get(r.start..r.end)
.ok_or_else(|| Error::UnexpectedEndOfBuffer)
.and_then(|x| ::core::str::from_utf8(x).map_err(|e| e.into()))
})
}

Expand Down
10 changes: 6 additions & 4 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ set -e

./generate_modules.sh

cargo run -p quick-protobuf --example pb_rs_example_v3_owned
cargo run -p quick-protobuf --example pb_rs_example
cargo run -p quick-protobuf --example pb_rs_example_v3
cargo run --no-default-features -p quick-protobuf --example pb_rs_example_nostd
pushd quick-protobuf
cargo run --example pb_rs_example_v3_owned
cargo run --example pb_rs_example
cargo run --example pb_rs_example_v3
cargo run --example pb_rs_example_nostd --no-default-features
popd

cargo test -p pb-rs -p quick-protobuf

0 comments on commit 1c5f753

Please sign in to comment.