diff --git a/Cargo.toml b/Cargo.toml index 50d96b6..729bcec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ bebop = { version = "2.4.9", optional = true } bincode1 = { package = "bincode", version = "1.3.3", optional = true } # Can't call it bincode2 because of a current issue of bincode2 bincode = { package = "bincode", version = "2.0.0-rc", optional = true } -bitcode = { version = "0.5.0", optional = true } +bitcode = { version = "0.6.0-alpha.2", optional = true } borsh = { version = "1.1.1", features = ["derive"], optional = true } # TODO: Unfork after bson adds support for pre-warmed serialization buffers # https://github.com/mongodb/bson-rust/pull/328 diff --git a/src/bench_bitcode.rs b/src/bench_bitcode.rs index 00dcab7..6d610ce 100644 --- a/src/bench_bitcode.rs +++ b/src/bench_bitcode.rs @@ -1,29 +1,29 @@ -use bitcode::{Decode, Encode}; +use bitcode::{DecodeOwned, Encode}; use criterion::{black_box, Criterion}; pub fn bench(name: &'static str, c: &mut Criterion, data: &T) where - T: Encode + Decode, + T: Encode + DecodeOwned, { let mut group = c.benchmark_group(format!("{}/bitcode", name)); - let mut buffer = bitcode::Buffer::with_capacity(10000000); + let mut buffer = bitcode::EncodeBuffer::::default(); group.bench_function("serialize", |b| { b.iter(|| { - buffer.encode(black_box(&data)).unwrap(); - black_box(()); + black_box(buffer.encode(black_box(data))); }) }); - let encoded = bitcode::encode(&data).unwrap(); + let encoded = buffer.encode(data); + let mut buffer = bitcode::DecodeBuffer::::default(); group.bench_function("deserialize", |b| { b.iter(|| { - black_box(buffer.decode::(black_box(&encoded)).unwrap()); + black_box(buffer.decode(black_box(&encoded)).unwrap()); }) }); - crate::bench_size(name, "bitcode", encoded.as_slice()); + crate::bench_size(name, "bitcode", encoded); group.finish(); } diff --git a/src/datasets/log/mod.rs b/src/datasets/log/mod.rs index 6c2afc5..43c891f 100644 --- a/src/datasets/log/mod.rs +++ b/src/datasets/log/mod.rs @@ -173,9 +173,7 @@ pub struct Log { pub userid: String, pub date: String, pub request: String, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "100..599"))] pub code: u16, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..100000000"))] pub size: u64, } diff --git a/src/datasets/mesh/mod.rs b/src/datasets/mesh/mod.rs index c7218ad..74fe303 100644 --- a/src/datasets/mesh/mod.rs +++ b/src/datasets/mesh/mod.rs @@ -33,7 +33,6 @@ use crate::Generate; #[cfg_attr(feature = "abomonation", derive(abomonation_derive::Abomonation))] #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))] -#[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] #[cfg_attr( feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) diff --git a/src/datasets/minecraft_savedata/mod.rs b/src/datasets/minecraft_savedata/mod.rs index 611f0d0..86de242 100644 --- a/src/datasets/minecraft_savedata/mod.rs +++ b/src/datasets/minecraft_savedata/mod.rs @@ -305,9 +305,7 @@ impl alkahest::Pack for &'_ Item { #[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct Abilities { - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub walk_speed: f32, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub fly_speed: f32, pub may_fly: bool, pub flying: bool, @@ -442,13 +440,9 @@ impl alkahest::Pack for Abilities { #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct Entity { pub id: String, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub pos: (f64, f64, f64), - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub motion: (f64, f64, f64), - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub rotation: (f32, f32), - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub fall_distance: f32, pub fire: u16, pub air: u16, @@ -988,20 +982,16 @@ pub struct Player { pub spawn_z: i64, pub spawn_forced: Option, pub sleep_timer: u16, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub food_exhaustion_level: f32, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub food_saturation_level: f32, pub food_tick_timer: u32, pub xp_level: u32, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub xp_p: f32, pub xp_total: i32, pub xp_seed: i32, pub inventory: Vec, pub ender_items: Vec, pub abilities: Abilities, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0.0..1.0"))] pub entered_nether_position: Option<(f64, f64, f64)>, pub root_vehicle: Option<([u32; 4], Entity)>, pub shoulder_entity_left: Option, diff --git a/src/datasets/mk48/mod.rs b/src/datasets/mk48/mod.rs index fbee28e..96b1127 100644 --- a/src/datasets/mk48/mod.rs +++ b/src/datasets/mk48/mod.rs @@ -63,25 +63,15 @@ use crate::{generate_vec, Generate}; #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] #[repr(u8)] pub enum EntityType { - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 2.14))] ArleighBurke, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.52))] Bismarck, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.97))] Clemenceau, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 1.46))] Fletcher, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 13.16))] G5, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 1.55))] Iowa, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 0.83))] Kolkata, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 7.25))] Osa, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 4.06))] Yasen, - #[cfg_attr(feature = "bitcode", bitcode_hint(frequency = 12.92))] Zubr, } @@ -312,7 +302,6 @@ fn generate_velocity(rng: &mut impl Rng) -> i16 { #[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct Transform { - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))] pub altitude: i8, pub angle: u16, pub position: (f32, f32), @@ -543,13 +532,10 @@ impl alkahest::Pack for Guidance { #[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct Contact { - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..1"))] pub damage: u8, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..8000"))] pub entity_id: u32, pub entity_type: Option, pub guidance: Guidance, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..400"))] pub player_id: Option, pub reloads: Vec, pub transform: Transform, @@ -771,7 +757,6 @@ impl alkahest::Pack for &'_ Contact { #[cfg_attr(feature = "savefile", derive(savefile_derive::Savefile))] #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct TerrainUpdate { - #[cfg_attr(feature = "bitcode", bitcode_hint(gamma))] chunk_id: (i8, i8), data: Vec, } @@ -913,7 +898,6 @@ impl alkahest::Pack for &'_ TerrainUpdate { #[cfg_attr(feature = "nanoserde", derive(nanoserde::SerBin, nanoserde::DeBin))] pub struct Update { pub contacts: Vec, - #[cfg_attr(feature = "bitcode", bitcode_hint(expected_range = "0..5000"))] pub score: u32, pub world_radius: f32, pub terrain_updates: Vec,