xref: /linux/rust/zerocopy/benches/formats/coco_dynamic_padding.rs (revision 056a5087d87ead77dedbe9cf5bde53b7cd4b4651)
1 use zerocopy_derive::*;
2 
3 // The only valid value of this type are the bytes `0xC0C0`.
4 #[derive(TryFromBytes, KnownLayout, Immutable)]
5 #[repr(u16)]
6 pub enum C0C0 {
7     _XC0C0 = 0xC0C0,
8 }
9 
10 #[derive(FromBytes, KnownLayout, Immutable, SplitAt)]
11 #[repr(C, align(4))]
12 pub struct Packet<Magic> {
13     magic_number: Magic,
14     milk: u8,
15     mug_size: u8,
16     temperature: [u8; 5],
17     marshmallows: [[u8; 3]],
18 }
19 
20 /// A packet begining with the magic number `0xC0C0`.
21 pub type CocoPacket = Packet<C0C0>;
22 
23 /// A packet beginning with any two initialized bytes.
24 pub type LocoPacket = Packet<[u8; 2]>;
25