use btmgmt_packet_helper::commands; use btmgmt_packet_helper::pack::{Pack, Unpack}; #[commands(name = Commands, trait = Command, codes = CommandCode)] mod commands { use super::*; #[derive(Debug, Pack)] #[command(code = 0x0001, reply = MyCommandReply)] pub struct MyCommand { pub f1: u16, } #[derive(Debug, Unpack, PartialEq, Eq)] pub struct MyCommandReply; } fn main() { use commands::*; fn assert_command() where C: Command {} assert_command::(); assert_eq!(CommandCode::MyCommand, ::CODE); let b = vec![]; let r = ::Reply::unpack(&mut &b[..]).unwrap(); assert_eq!(MyCommandReply, r); assert!(matches!(Commands::from(MyCommand { f1: 0 }), Commands::MyCommand(MyCommand { f1: 0 }))); assert_eq!(Commands::from(MyCommand { f1: 0 }).code(), CommandCode::MyCommand); let mut b = vec![]; Commands::from(MyCommand { f1: 0 }).pack_inner(&mut b).unwrap(); assert_eq!(b, &[0x00, 0x00]); }