Skip to content

Commit

Permalink
Update to zerocopy 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjm committed Dec 31, 2024
1 parent e7989e7 commit 116a506
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ serde = { version = "1.0.204", features = ["derive"], optional = true }
serde_json = { version = "1.0.121", optional = true }
time = "0.3.36"
toml = { version = "0.8.19", optional = true }
zerocopy = { version = "0.7.35", features = ["derive"] }
zerocopy = { version = "0.8.14", features = ["derive"] }
10 changes: 5 additions & 5 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use embedded_graphics::{
Drawable,
};
use time::OffsetDateTime;
use zerocopy::{AsBytes, BigEndian, FromBytes, FromZeroes, U16};
use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U16};

/// Message style configuration
/// ```
Expand Down Expand Up @@ -197,7 +197,7 @@ const MSG_PADDING_ALIGN: usize = 64;

const MAGIC: [u8; 6] = *b"wang\0\0";

#[derive(FromZeroes, FromBytes, AsBytes)]
#[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(C)]
struct Header {
magic: [u8; 6],
Expand All @@ -210,7 +210,7 @@ struct Header {
_padding_2: [u8; 20],
}

#[derive(FromZeroes, FromBytes, AsBytes)]
#[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
#[repr(C)]
struct Timestamp {
year: u8,
Expand Down Expand Up @@ -297,7 +297,7 @@ impl PayloadBuffer {
}

fn header_mut(&mut self) -> &mut Header {
Header::mut_from_prefix(&mut self.data).unwrap()
Header::mut_from_prefix(&mut self.data).unwrap().0
}

/// Return the current number of messages
Expand Down Expand Up @@ -359,7 +359,7 @@ impl PayloadBuffer {

let start = self.data.len();
self.data.resize(start + count * 11, 0);
MessageBuffer(FromBytes::mut_slice_from(&mut self.data[start..]).unwrap())
MessageBuffer(FromBytes::mut_from_bytes(&mut self.data[start..]).unwrap())
}

/// Get the current payload as bytes (without padding)
Expand Down

0 comments on commit 116a506

Please sign in to comment.