Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Based on #25] Have encode() take its writer by value #26

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ license = "MIT"

[dev-dependencies]
recycler="0.1.4"

[profile.bench]
# Multiple codegen units speed up compilation, but make compilation output less
# deteministic and generally decrease codegen quality through worse inlining.
# Let's turn it off for benchmarking.
codegen-units = 1
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A mortifying serialization library for Rust

Abomonation (spelling intentional) is a serialization library for Rust based on the very simple idea that if someone presents data for serialization it will copy those exact bits, and then follow any pointers and copy those bits, and so on. When deserializing it recovers the exact bits, and then corrects pointers to aim at the serialized forms of the chased data.

**Warning**: Abomonation should not be used on any data you care strongly about, or from any computer you value the data on. The `encode` and `decode` methods do things that may be undefined behavior, and you shouldn't stand for that. Specifically, `encode` exposes padding bytes to `memcpy`, and `decode` doesn't much respect alignment.
**Warning**: Abomonation should not be used on any data you care strongly about, or from any computer you value the data on. The `encode` and `decode` methods do things that may be undefined behavior, and you shouldn't stand for that. Specifically, `encode` exposes padding bytes to `memcpy`, and `decode` doesn't much respect alignment and may need to construct Rust references to invalid data.

Please consult the [abomonation documentation](https://frankmcsherry.github.com/abomonation) for more specific information.

Expand Down Expand Up @@ -49,7 +49,7 @@ Be warned that these numbers are not *goodput*, but rather the total number of b

## unsafe_abomonate!

Abomonation comes with the `unsafe_abomonate!` macro implementing `Abomonation` for structs which are essentially equivalent to a tuple of other `Abomonable` types. To use the macro, you must put the `#[macro_use]` modifier before `extern crate abomonation;`.
Abomonation comes with the `unsafe_abomonate!` macro implementing `Abomonation` for structs which are essentially equivalent to a tuple of other `Abomonation` types. To use the macro, you must put the `#[macro_use]` modifier before `extern crate abomonation;`.

Please note that `unsafe_abomonate!` synthesizes unsafe implementations of `Abomonation`, and it is should be considered unsafe to invoke.

Expand Down Expand Up @@ -82,4 +82,4 @@ if let Some((result, remaining)) = unsafe { decode::<MyStruct>(&mut bytes) } {
}
```

Be warned that implementing `Abomonable` for types can be a giant disaster and is entirely discouraged.
Be warned that implementing `Abomonation` for types can be a giant disaster and is entirely discouraged.
4 changes: 1 addition & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use test::Bencher;
#[bench] fn vec_u_vn_s_dec(bencher: &mut Bencher) { _bench_dec(bencher, vec![vec![(0u64, vec![(); 1 << 40], format!("grawwwwrr!")); 32]; 32]); }

fn _bench_enc<T: Abomonation>(bencher: &mut Bencher, record: T) {

// prepare encoded data for bencher.bytes
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand All @@ -40,12 +39,11 @@ fn _bench_enc<T: Abomonation>(bencher: &mut Bencher, record: T) {
bencher.bytes = bytes.len() as u64;
bencher.iter(|| {
bytes.clear();
unsafe { encode(&record, &mut bytes).unwrap(); }
unsafe { encode(&record, &mut bytes).unwrap() }
});
}

fn _bench_dec<T: Abomonation+Eq>(bencher: &mut Bencher, record: T) {

// prepare encoded data
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand Down
2 changes: 0 additions & 2 deletions benches/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use test::Bencher;
#[bench] fn vec_u_vn_s_cln(bencher: &mut Bencher) { _bench_cln(bencher, vec![vec![(0u64, vec![(); 1 << 40], format!("grawwwwrr!")); 32]; 32]); }

fn _bench_e_d<T: Abomonation>(bencher: &mut Bencher, record: T) {

// prepare encoded data for bencher.bytes
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand All @@ -43,7 +42,6 @@ fn _bench_e_d<T: Abomonation>(bencher: &mut Bencher, record: T) {
}

fn _bench_cln<T: Abomonation+Clone>(bencher: &mut Bencher, record: T) {

// prepare encoded data
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand Down
2 changes: 0 additions & 2 deletions benches/recycler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use test::Bencher;
// #[bench] fn vec_u_vn_s_rec(bencher: &mut Bencher) { _bench_rec(bencher, vec![vec![(0u64, vec![(); 1 << 40], format!("grawwwwrr!")); 32]; 32]); }

fn _bench_own<T: Abomonation+Clone>(bencher: &mut Bencher, record: T) {

// prepare encoded data
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand All @@ -43,7 +42,6 @@ fn _bench_own<T: Abomonation+Clone>(bencher: &mut Bencher, record: T) {


fn _bench_rec<T: Abomonation+Recyclable>(bencher: &mut Bencher, record: T) {

// prepare encoded data
let mut bytes = Vec::new();
unsafe { encode(&record, &mut bytes).unwrap(); }
Expand Down
Loading