mirror of
https://github.com/Drop-OSS/native_model.git
synced 2026-01-30 20:55:19 +01:00
fix: update zerocopy usage in header and wrapper modules to use new traits
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use zerocopy::little_endian::U32;
|
||||
use zerocopy::{AsBytes, FromBytes, FromZeroes};
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
#[derive(FromZeroes, FromBytes, AsBytes, Debug)]
|
||||
#[derive(FromBytes, IntoBytes, Immutable, KnownLayout, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct Header {
|
||||
pub(crate) id: U32,
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
use crate::header::Header;
|
||||
use zerocopy::little_endian::U32;
|
||||
use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, Ref};
|
||||
use zerocopy::{SplitByteSlice, SplitByteSliceMut, Ref, IntoBytes};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Wrapper<T: ByteSlice> {
|
||||
header: Ref<T, Header>, // Deprecated: Rename LayoutVerified to Ref #203
|
||||
pub struct Wrapper<T: SplitByteSlice> {
|
||||
header: Ref<T, Header>,
|
||||
value: T,
|
||||
}
|
||||
|
||||
impl<T: ByteSlice> Wrapper<T> {
|
||||
impl<T: SplitByteSlice> Wrapper<T> {
|
||||
pub fn deserialize(packed: T) -> Option<Self> {
|
||||
let (header_lv, rest) = Ref::<_, Header>::new_from_prefix(packed)?;
|
||||
let (header_lv, rest) = Ref::<_, Header>::from_prefix(packed).ok()?;
|
||||
let native_model = Self {
|
||||
header: header_lv,
|
||||
value: rest,
|
||||
@@ -35,7 +34,7 @@ impl<T: ByteSlice> Wrapper<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ByteSliceMut> Wrapper<T> {
|
||||
impl<T: SplitByteSliceMut> Wrapper<T> {
|
||||
pub fn set_type_id(&mut self, type_id: u32) {
|
||||
self.header.id = U32::new(type_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user