I have a mmap
ped file from which I read (and write) Message
s. I have a byte slice (&[u8]
) of the mmap's contents. My current struct definition of a Message
is:
struct Message<'a> {
bytes: &'a [u8]
id: &'a MessageId(u64),
// ... some fields omitted ...
}
What I'd like is to map the byte slice to the message's fields, but I can't seem to get this right.
I've been looking into mem::transmute
but I keep doing something wrong here:
error: transmute called with differently sized types: *const [u8] (128 bits) to u64 (64 bits) [E0512]
let offset: u64 = unsafe { mem::transmute(self.bytes) };
From my understanding transmute "reinterprets" the buffer as another type. How should I go about fixing this? How about mapping subsequent fields (as e.g. u32
, &'a str
, etc.)?