1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#![deny(missing_docs)] //! Reading and writing of binary data. pub mod read; pub mod write; /// Calculate the length required to 32-bit (long) align data of length `len` /// /// Example: /// /// ``` /// use allsorts::binary::long_align; /// /// let length = 123; /// let padded_length = long_align(length); /// assert_eq!(padded_length, 124); /// ``` pub const fn long_align(len: usize) -> usize { (len + 3) / 4 * 4 } /// Calculate the length required to 16-bit (word) align data of length `len` /// /// Example: /// /// ``` /// use allsorts::binary::word_align; /// /// let length = 123; /// let padded_length = word_align(length); /// assert_eq!(padded_length, 124); /// ``` pub const fn word_align(len: usize) -> usize { (len + 1) / 2 * 2 } /// Unsigned 8-bit binary type. #[derive(Copy, Clone)] pub enum U8 {} /// Signed 8-bit binary type. #[derive(Copy, Clone)] pub enum I8 {} /// Unsigned 16-bit big endian binary type. #[derive(Copy, Clone)] pub enum U16Be {} /// Signed 16-bit big endian binary type. #[derive(Copy, Clone)] pub enum I16Be {} /// Unsigned 24-bit (3 bytes) big endian binary type. #[derive(Copy, Clone)] pub enum U24Be {} /// Unsigned 32-bit big endian binary type. #[derive(Copy, Clone)] pub enum U32Be {} /// Signed 32-bit big endian binary type. #[derive(Copy, Clone)] pub enum I32Be {} /// Signed 64-bit binary type. #[derive(Copy, Clone)] pub enum I64Be {}