//! Port of the C++ `common.h`: shared payload type and demo constants. use omnivox::{Cereal, CodecError, Reader, write_byte_vec}; /// Wire-identical to the C++ `DatagramPayload` (cereal field order: /// `id`, `v1.qword`, `payload`; the `PackedValue64` union only ever /// serialized its `qword`, so it ports as a plain `u64`). #[derive(Debug, Default)] pub struct DatagramPayload { pub id: u16, pub v1: u64, pub payload: Vec, } impl Cereal for DatagramPayload { fn encode(&self, out: &mut Vec) { out.extend_from_slice(&self.id.to_le_bytes()); out.extend_from_slice(&self.v1.to_le_bytes()); write_byte_vec(out, &self.payload); } fn decode(bytes: &[u8]) -> Result { let mut r = Reader::new(bytes); Ok(Self { id: r.u16()?, v1: r.u64()?, payload: r.byte_vec()?, }) } } pub const PASSWORD: &str = "SecurePassword123"; pub const SALT: &[u8] = &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]; pub const SERVER_PORT: u16 = 8080; /// Only used by the client example. #[allow(dead_code)] pub const SERVER_ADDR: &str = "127.0.0.1";