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