Skip to content

Commit cf88001

Browse files
committed
Drop byteorder dep
1 parent c2b0787 commit cf88001

6 files changed

Lines changed: 15 additions & 62 deletions

File tree

rmp-serde/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "rmp-serde"
33
version = "1.3.1"
44
authors = ["Evgeny Safronov <division494@gmail.com>"]
55
license = "MIT"
6-
description = "Serde bindings for RMP"
6+
description = "Serde support for MessagePack"
77
repository = "https://github.com/3Hren/msgpack-rust"
88
documentation = "https://docs.rs/rmp-serde"
99
readme = "README.md"
@@ -16,7 +16,6 @@ rust-version = "1.85"
1616
tag-prefix = "{{crate_name}}/"
1717

1818
[dependencies]
19-
byteorder = "1.5.0"
2019
serde = "1.0.228"
2120
rmp = { version = "0.8.14", path = "../rmp" }
2221

rmp-serde/src/decode.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::marker::PhantomData;
99
use std::num::TryFromIntError;
1010
use std::str::{self, Utf8Error};
1111

12-
use byteorder::{self, ReadBytesExt};
13-
1412
use serde;
1513
use serde::de::value::SeqDeserializer;
1614
use serde::de::{self, Deserialize, DeserializeOwned, DeserializeSeed, Unexpected, Visitor};
@@ -382,17 +380,21 @@ fn read_bin_data<'a, 'de, R: ReadSlice<'de>>(rd: &'a mut R, len: u32) -> Result<
382380
}
383381

384382
fn read_u8<R: Read>(rd: &mut R) -> Result<u8, Error> {
385-
byteorder::ReadBytesExt::read_u8(rd).map_err(Error::InvalidDataRead)
383+
let mut buf = [0; 1];
384+
rd.read_exact(&mut buf).map_err(Error::InvalidDataRead)?;
385+
Ok(buf[0])
386386
}
387387

388388
fn read_u16<R: Read>(rd: &mut R) -> Result<u16, Error> {
389-
rd.read_u16::<byteorder::BigEndian>()
390-
.map_err(Error::InvalidDataRead)
389+
let mut buf = [0; 2];
390+
rd.read_exact(&mut buf).map_err(Error::InvalidDataRead)?;
391+
Ok(u16::from_be_bytes(buf))
391392
}
392393

393394
fn read_u32<R: Read>(rd: &mut R) -> Result<u32, Error> {
394-
rd.read_u32::<byteorder::BigEndian>()
395-
.map_err(Error::InvalidDataRead)
395+
let mut buf = [0; 4];
396+
rd.read_exact(&mut buf).map_err(Error::InvalidDataRead)?;
397+
Ok(u32::from_be_bytes(buf))
396398
}
397399

398400
fn ext_len<R: Read>(rd: &mut R, marker: Marker) -> Result<u32, Error> {

rmp/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ edition = "2024"
1313
rust-version = "1.85"
1414

1515
[dependencies]
16-
byteorder = { version = "1.5.0", default-features = false }
1716
num-traits = { version = "0.2.19", default-features = false }
18-
# This is macro_only ;)
19-
paste = "1.0"
2017

2118
[features]
2219
default = ["std"]
23-
std = ["byteorder/std", "num-traits/std"]
20+
std = ["num-traits/std"]
2421

2522
[[example]]
2623
name = "inspect"

rmp/src/decode/mod.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ macro_rules! read_byteorder_utils {
6262
const SIZE: usize = core::mem::size_of::<$tp>();
6363
let mut buf: [u8; SIZE] = [0u8; SIZE];
6464
self.read_exact_buf(&mut buf).map_err(ValueReadError::InvalidDataRead)?;
65-
Ok(paste::paste! {
66-
<byteorder::BigEndian as byteorder::ByteOrder>::[<read_ $tp>](&mut buf)
67-
})
65+
Ok($tp::from_be_bytes(buf))
6866
}
6967
)*
7068
};
@@ -83,8 +81,6 @@ mod sealed {
8381
/// The methods of this trait should be considered an implementation detail (for now).
8482
/// It is currently sealed (can not be implemented by the user).
8583
///
86-
/// See also [`std::io::Read`] and [`byteorder::ReadBytesExt`]
87-
///
8884
/// Its primary implementations are [`std::io::Read`] and [Bytes].
8985
pub trait RmpRead: sealed::Sealed {
9086
type Error: RmpReadErr;
@@ -130,40 +126,6 @@ pub trait RmpRead: sealed::Sealed {
130126
);
131127
}
132128

133-
/*
134-
* HACK: rmpv & rmp-erde used the internal read_data_* functions.
135-
*
136-
* Since adding no_std support moved these functions to the RmpRead trait,
137-
* this broke compatiblity (despite changing no public APIs).
138-
*
139-
* In theory, we could update rmpv and rmp-serde to use the new APIS,
140-
* but that would be needless churn (and might surprise users who just want to update rmp proper).
141-
*
142-
* Instead, we emulate these internal APIs for now,
143-
* so that rmpv and rmp-serde continue to compile without issue.
144-
*
145-
*
146-
* TODO: Remove this hack once we release a new version of rmp proper
147-
*/
148-
149-
macro_rules! wrap_data_funcs_for_compatibility {
150-
($($tp:ident),* $(,)?) => {
151-
$(paste::paste! {
152-
#[cfg(feature = "std")]
153-
#[doc(hidden)]
154-
#[deprecated(note = "internal function. rmpv & rmp-serde need to switch to RmpRead")]
155-
pub fn [<read_data_ $tp>] <R: std::io::Read>(buf: &mut R) -> Result<$tp, ValueReadError> {
156-
buf.[<read_data_ $tp>]()
157-
}
158-
})*
159-
};
160-
}
161-
wrap_data_funcs_for_compatibility!(
162-
u8, u16, u32, u64,
163-
i8, i16, i32, i64,
164-
f32, f64
165-
);
166-
167129
#[cfg(feature = "std")]
168130
impl<T: std::io::Read> RmpRead for T {
169131
type Error = std::io::Error;

rmp/src/encode/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ macro_rules! write_byteorder_utils {
119119
#[inline]
120120
#[doc(hidden)]
121121
fn $name(&mut self, val: $tp) -> Result<(), DataWriteError<Self::Error>> where Self: Sized {
122-
const SIZE: usize = core::mem::size_of::<$tp>();
123-
let mut buf: [u8; SIZE] = [0u8; SIZE];
124-
paste::paste! {
125-
<byteorder::BigEndian as byteorder::ByteOrder>::[<write_ $tp>](&mut buf, val);
126-
}
127-
self.write_bytes(&buf).map_err(DataWriteError)
122+
self.write_bytes(&val.to_be_bytes()).map_err(DataWriteError)
128123
}
129124
)*
130125
};
@@ -135,8 +130,6 @@ macro_rules! write_byteorder_utils {
135130
/// The methods of this trait should be considered an implementation detail (for now).
136131
/// It is currently sealed (can not be implemented by the user).
137132
///
138-
/// See also [`std::io::Write`] and [`byteorder::WriteBytesExt`]
139-
///
140133
/// Its primary implementations are [`std::io::Write`] and [`ByteBuf`].
141134
pub trait RmpWrite: sealed::Sealed {
142135
type Error: RmpWriteErr;

rmpv/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "rmpv"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
authors = ["Evgeny Safronov <division494@gmail.com>"]
55
license = "MIT"
6-
description = "Value variant for RMP"
6+
description = "Decoding/Encoding MessagePack values without schema"
77
repository = "https://github.com/3Hren/msgpack-rust"
88
documentation = "https://docs.rs/rmpv"
99
readme = "README.md"

0 commit comments

Comments
 (0)