Skip to content
Merged
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
4 changes: 2 additions & 2 deletions zerompk/benches/deserialize_large_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ fn deserialize_large_array_msgpacker(b: &mut test::Bencher) {
b.iter(|| {
let data = test::black_box(&msgpack);
for _ in 0..N {
let mut buf = data.clone();
let (_, deserialized): (usize, Vec<Point>) = msgpacker::unpack_array(&mut buf).unwrap();
let buf = data.clone();
let (_, deserialized): (usize, Vec<Point>) = msgpacker::unpack_array(&buf).unwrap();
test::black_box(deserialized);
}
});
Expand Down
8 changes: 4 additions & 4 deletions zerompk/src/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ where
}
}

impl<'a> ToMessagePack for &'a str {
impl ToMessagePack for &str {
#[inline(always)]
fn write<W: Write>(&self, writer: &mut W) -> crate::Result<()> {
writer.write_string(*self)
writer.write_string(self)
}
}

Expand Down Expand Up @@ -278,13 +278,13 @@ impl<T: Clone + ToMessagePack> ToMessagePack for alloc::borrow::Cow<'_, [T]> {
impl<T: ToMessagePack + ?Sized> ToMessagePack for &T {
#[inline(always)]
fn write<W: Write>(&self, writer: &mut W) -> crate::Result<()> {
T::write(&self, writer)
T::write(self, writer)
}
}

impl<T: ToMessagePack + ?Sized> ToMessagePack for &mut T {
fn write<W: Write>(&self, writer: &mut W) -> crate::Result<()> {
T::write(&self, writer)
T::write(self, writer)
}
}

Expand Down
3 changes: 1 addition & 2 deletions zerompk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pub trait ToMessagePack {
/// ```
pub fn from_msgpack<'a, T: FromMessagePack<'a>>(data: &'a [u8]) -> Result<T> {
let mut reader = read::SliceReader::new(data);
let result = T::read(&mut reader);
result
T::read(&mut reader)
}

/// Serializes a value of type `T` into a `Vec<u8>` containing its MessagePack representation.
Expand Down
4 changes: 1 addition & 3 deletions zerompk/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,7 @@ impl<R: std::io::Read> IOReader<R> {

#[inline(always)]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> {
self.reader
.read_exact(buf)
.map_err(|err| Error::IoError(err))
self.reader.read_exact(buf).map_err(Error::IoError)
}

#[inline(always)]
Expand Down
34 changes: 15 additions & 19 deletions zerompk/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a> Write for SliceWriter<'a> {
let buf = self.take_array::<5>()?;
let [head, tail @ ..] = buf;
*head = UINT32_MARKER;
*tail = (u as u32).to_be_bytes();
*tail = u.to_be_bytes();
Ok(())
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a> Write for SliceWriter<'a> {
let buf = self.take_array::<9>()?;
let [head, tail @ ..] = buf;
*head = UINT64_MARKER;
*tail = (u as u64).to_be_bytes();
*tail = u.to_be_bytes();
Ok(())
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<'a> Write for SliceWriter<'a> {
let buf = self.take_array::<3>()?;
let [head, tail @ ..] = buf;
*head = INT16_MARKER;
*tail = (i as i16).to_be_bytes();
*tail = i.to_be_bytes();
Ok(())
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ impl<'a> Write for SliceWriter<'a> {
let buf = self.take_array::<5>()?;
let [head, tail @ ..] = buf;
*head = INT32_MARKER;
*tail = (i as i32).to_be_bytes();
*tail = i.to_be_bytes();
Ok(())
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ impl<'a> Write for SliceWriter<'a> {
let buf = self.take_array::<9>()?;
let [head, tail @ ..] = buf;
*head = INT64_MARKER;
*tail = (i as i64).to_be_bytes();
*tail = i.to_be_bytes();
Ok(())
}
}
Expand Down Expand Up @@ -521,11 +521,7 @@ impl<'a> Write for SliceWriter<'a> {
unsafe {
let tail_ptr = tail.as_mut_ptr();
core::ptr::copy_nonoverlapping(nanoseconds.to_be_bytes().as_ptr(), tail_ptr, 4);
core::ptr::copy_nonoverlapping(
(seconds as i64).to_be_bytes().as_ptr(),
tail_ptr.add(4),
8,
);
core::ptr::copy_nonoverlapping(seconds.to_be_bytes().as_ptr(), tail_ptr.add(4), 8);
}
Ok(())
}
Expand Down Expand Up @@ -888,7 +884,7 @@ impl Write for VecWriter {
let ptr = self.buffer.as_mut_ptr().add(self.buffer.len());
*ptr = INT16_MARKER;
ptr.add(1)
.copy_from_nonoverlapping((i as i16).to_be_bytes().as_ptr(), 2);
.copy_from_nonoverlapping(i.to_be_bytes().as_ptr(), 2);
self.buffer.set_len(self.buffer.len() + 3);
}
Ok(())
Expand Down Expand Up @@ -934,7 +930,7 @@ impl Write for VecWriter {
let ptr = self.buffer.as_mut_ptr().add(self.buffer.len());
*ptr = INT32_MARKER;
ptr.add(1)
.copy_from_nonoverlapping((i as i32).to_be_bytes().as_ptr(), 4);
.copy_from_nonoverlapping(i.to_be_bytes().as_ptr(), 4);
self.buffer.set_len(self.buffer.len() + 5);
}
Ok(())
Expand Down Expand Up @@ -1168,7 +1164,7 @@ impl Write for VecWriter {
ptr.add(3)
.copy_from_nonoverlapping(nanoseconds.to_be_bytes().as_ptr(), 4);
ptr.add(7)
.copy_from_nonoverlapping((seconds as i64).to_be_bytes().as_ptr(), 8);
.copy_from_nonoverlapping(seconds.to_be_bytes().as_ptr(), 8);
self.buffer.set_len(self.buffer.len() + 15);
}
Ok(())
Expand Down Expand Up @@ -1352,7 +1348,7 @@ impl<W: std::io::Write> IOWriter<W> {

#[inline(always)]
fn write_all(&mut self, data: &[u8]) -> Result<()> {
self.writer.write_all(data).map_err(|e| Error::IoError(e))
self.writer.write_all(data).map_err(Error::IoError)
}
}

Expand Down Expand Up @@ -1392,7 +1388,7 @@ impl<W: std::io::Write> Write for IOWriter<W> {
Ok(())
}
_ => {
let len_bytes = (u as u16).to_be_bytes();
let len_bytes = u.to_be_bytes();
self.write_all(&[UINT16_MARKER, len_bytes[0], len_bytes[1]])?;
Ok(())
}
Expand Down Expand Up @@ -1508,7 +1504,7 @@ impl<W: std::io::Write> Write for IOWriter<W> {
Ok(())
}
_ => {
let len_bytes = (i as i16).to_be_bytes();
let len_bytes = i.to_be_bytes();
self.write_all(&[INT16_MARKER, len_bytes[0], len_bytes[1]])?;
Ok(())
}
Expand Down Expand Up @@ -1536,7 +1532,7 @@ impl<W: std::io::Write> Write for IOWriter<W> {
Ok(())
}
_ => {
let len_bytes = (i as i32).to_be_bytes();
let len_bytes = i.to_be_bytes();
self.write_all(&[
INT32_MARKER,
len_bytes[0],
Expand Down Expand Up @@ -1581,7 +1577,7 @@ impl<W: std::io::Write> Write for IOWriter<W> {
Ok(())
}
_ => {
let len_bytes = (i as i64).to_be_bytes();
let len_bytes = i.to_be_bytes();
self.write_all(&[
INT64_MARKER,
len_bytes[0],
Expand Down Expand Up @@ -1732,7 +1728,7 @@ impl<W: std::io::Write> Write for IOWriter<W> {
}

// timestamp 96
let sec_bytes = (seconds as i64).to_be_bytes();
let sec_bytes = seconds.to_be_bytes();
let nsec_bytes = nanoseconds.to_be_bytes();
self.write_all(&[
TIMESTAMP96_MARKER,
Expand Down
5 changes: 1 addition & 4 deletions zerompk/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ struct VecPayloadAsBinExplicit {
}

fn recursive_node_msgpack(depth: usize) -> Vec<u8> {
let mut out = Vec::with_capacity(depth + 1);
for _ in 0..depth {
out.push(0x91); // [next]
}
let mut out = vec![0x91; depth]; // [next]
Comment thread
paq marked this conversation as resolved.
out.push(0xc0); // None
out
}
Expand Down
Loading