diff options
author | Joey Sacchini <joey@sacchini.net> | 2020-10-20 18:20:45 -0400 |
---|---|---|
committer | Joey Sacchini <joey@sacchini.net> | 2020-10-20 18:20:45 -0400 |
commit | 9facbf7d8a9c00b2413be325b23aeed786d7a7c1 (patch) | |
tree | f5260368a63f4202523ef4ab54c69eab55814220 /src/byte_order.rs | |
parent | fc08a93b6109373652d6775fe1bfb7d18cdb7575 (diff) | |
download | mcproto-rs-9facbf7d8a9c00b2413be325b23aeed786d7a7c1.tar.gz mcproto-rs-9facbf7d8a9c00b2413be325b23aeed786d7a7c1.tar.bz2 mcproto-rs-9facbf7d8a9c00b2413be325b23aeed786d7a7c1.zip |
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)
Diffstat (limited to 'src/byte_order.rs')
-rw-r--r-- | src/byte_order.rs | 8 |
1 files changed, 8 insertions, 0 deletions
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<u8> { 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<i8> { Ok(Self::read_ubyte(data)?.map(move |b| b as i8)) } |