From 9facbf7d8a9c00b2413be325b23aeed786d7a7c1 Mon Sep 17 00:00:00 2001 From: Joey Sacchini Date: Tue, 20 Oct 2020 18:20:45 -0400 Subject: lots of macro and type refactoring to simplify common patterns such as: position/location/rotation, counted array types (macro -> generics), rename some macros, and use macros to implement primitives (and other things in types.rs inc: VarInt/VarNum) --- src/byte_order.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/byte_order.rs') diff --git a/src/byte_order.rs b/src/byte_order.rs index f1c40e3..2f65ca8 100644 --- a/src/byte_order.rs +++ b/src/byte_order.rs @@ -53,6 +53,10 @@ pub trait ByteOrder { Ok(Self::read_ushort(data)?.map(move |data| data as i16)) } + fn write_ubyte(v: u8) -> [u8; 1] { + [v] + } + fn read_ubyte(data: &[u8]) -> DeserializeResult { match data.split_first() { Some((byte, rest)) => Deserialized::ok(*byte, rest), @@ -60,6 +64,10 @@ pub trait ByteOrder { } } + fn write_byte(v: i8) -> [u8; 1] { + [v as u8] + } + fn read_byte(data: &[u8]) -> DeserializeResult { Ok(Self::read_ubyte(data)?.map(move |b| b as i8)) } -- cgit