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

Remove byteorder dependency #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion rmp-serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ edition = "2021"
tag-prefix = "{{crate_name}}/"

[dependencies]
byteorder = "1.4.3"
serde = "1.0.136"
rmp = { version = "0.8.11", path = "../rmp" }

Expand Down
19 changes: 12 additions & 7 deletions rmp-serde/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::io::{self, Cursor, ErrorKind, Read};
use std::num::TryFromIntError;
use std::str::{self, Utf8Error};

use byteorder::{self, ReadBytesExt};

use serde;
use serde::de::{self, Deserialize, DeserializeOwned, DeserializeSeed, Unexpected, Visitor};

Expand Down Expand Up @@ -362,17 +360,24 @@ fn read_bin_data<'a, 'de, R: ReadSlice<'de>>(rd: &'a mut R, len: u32) -> Result<
}

fn read_u8<R: Read>(rd: &mut R) -> Result<u8, Error> {
byteorder::ReadBytesExt::read_u8(rd).map_err(Error::InvalidDataRead)
let mut data = [0; 1];
rd.read_exact(&mut data)
.map_err(Error::InvalidDataRead)?;
Ok(u8::from_be_bytes(data))
}

fn read_u16<R: Read>(rd: &mut R) -> Result<u16, Error> {
rd.read_u16::<byteorder::BigEndian>()
.map_err(Error::InvalidDataRead)
let mut data = [0; 2];
rd.read_exact(&mut data)
.map_err(Error::InvalidDataRead)?;
Ok(u16::from_be_bytes(data))
}

fn read_u32<R: Read>(rd: &mut R) -> Result<u32, Error> {
rd.read_u32::<byteorder::BigEndian>()
.map_err(Error::InvalidDataRead)
let mut data = [0; 4];
rd.read_exact(&mut data)
.map_err(Error::InvalidDataRead)?;
Ok(u32::from_be_bytes(data))
}

fn ext_len<R: Read>(rd: &mut R, marker: Marker) -> Result<u32, Error> {
Expand Down
3 changes: 1 addition & 2 deletions rmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ categories = ["encoding"]
edition = "2021"

[dependencies]
byteorder = { version = "1.4.2", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
# This is macro_only ;)
paste = "1.0"


[features]
default = ["std"]
std = ["byteorder/std", "num-traits/std"]
std = ["num-traits/std"]

[dev-dependencies]
quickcheck = "1.0.2"
Expand Down
6 changes: 2 additions & 4 deletions rmp/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ macro_rules! read_byteorder_utils {
const SIZE: usize = core::mem::size_of::<$tp>();
let mut buf: [u8; SIZE] = [0u8; SIZE];
self.read_exact_buf(&mut buf).map_err(ValueReadError::InvalidDataRead)?;
Ok(paste::paste! {
<byteorder::BigEndian as byteorder::ByteOrder>::[<read_ $tp>](&mut buf)
})
Ok($tp::from_be_bytes(buf))
}
)*
};
Expand All @@ -80,7 +78,7 @@ mod sealed{
/// The methods of this trait should be considered an implementation detail (for now).
/// It is currently sealed (can not be implemented by the user).
///
/// See also [std::io::Read] and [byteorder::ReadBytesExt]
/// See also [std::io::Read]
///
/// Its primary implementations are [std::io::Read] and [Bytes].
pub trait RmpRead: sealed::Sealed {
Expand Down
9 changes: 2 additions & 7 deletions rmp/src/encode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ macro_rules! write_byteorder_utils {
#[inline]
#[doc(hidden)]
fn $name(&mut self, val: $tp) -> Result<(), DataWriteError<Self::Error>> where Self: Sized {
const SIZE: usize = core::mem::size_of::<$tp>();
let mut buf: [u8; SIZE] = [0u8; SIZE];
paste::paste! {
<byteorder::BigEndian as byteorder::ByteOrder>::[<write_ $tp>](&mut buf, val);
}
self.write_bytes(&buf).map_err(DataWriteError)
self.write_bytes(&val.to_be_bytes()).map_err(DataWriteError)
}
)*
};
Expand All @@ -138,7 +133,7 @@ macro_rules! write_byteorder_utils {
/// The methods of this trait should be considered an implementation detail (for now).
/// It is currently sealed (can not be implemented by the user).
///
/// See also [std::uo::Write] and [byteorder::WriteBytesExt]
/// See also [std::uo::Write]
///
/// Its primary implementations are [std::io::Write] and [ByteBuf].
pub trait RmpWrite: sealed::Sealed {
Expand Down