mirror of https://git.sr.ht/~stygianentity/bincode
parent
53b2b29829
commit
10bdbbff33
|
|
@ -31,7 +31,7 @@ library.
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
|
|
||||||
use bincode::{serialize, deserialize, Infinite};
|
use bincode::{serialize, deserialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
struct Entity {
|
struct Entity {
|
||||||
|
|
@ -45,7 +45,7 @@ struct World(Vec<Entity>);
|
||||||
fn main() {
|
fn main() {
|
||||||
let world = World(vec![Entity { x: 0.0, y: 4.0 }, Entity { x: 10.0, y: 20.5 }]);
|
let world = World(vec![Entity { x: 0.0, y: 4.0 }, Entity { x: 10.0, y: 20.5 }]);
|
||||||
|
|
||||||
let encoded: Vec<u8> = serialize(&world, Infinite).unwrap();
|
let encoded: Vec<u8> = serialize(&world).unwrap();
|
||||||
|
|
||||||
// 8 bytes for the length of the vector, 4 bytes per float.
|
// 8 bytes for the length of the vector, 4 bytes per float.
|
||||||
assert_eq!(encoded.len(), 8 + 4 * 4);
|
assert_eq!(encoded.len(), 8 + 4 * 4);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue