Skip to main content

source2_demo/reader/
bits.rs

1pub trait BitsReader {
2    /// Refills the internal lookahead buffer.
3    /// Must be called before `read_bits_unchecked` to ensure sufficient bits
4    /// are available in the lookahead buffer.
5    fn refill(&mut self);
6
7    fn read_bits(&mut self, amount: u32) -> u32;
8
9    /// Reads bits without refilling the buffer (unchecked).
10    ///
11    /// The caller must ensure `refill()` was called and sufficient bits remain.
12    ///
13    /// # Arguments
14    /// * `amount` - Number of bits to read (must be ≤ 32)
15    fn read_bits_unchecked(&mut self, amount: u32) -> u32;
16
17    fn read_bytes(&mut self, amount: u32) -> Vec<u8>;
18
19    fn read_bool(&mut self) -> bool;
20
21    fn read_f32(&mut self) -> f32;
22
23    fn read_var_u32(&mut self) -> u32;
24
25    fn read_var_u64(&mut self) -> u64;
26
27    fn read_var_i32(&mut self) -> i32;
28
29    fn read_ubit_var(&mut self) -> u32;
30
31    fn read_ubit_var_fp(&mut self) -> i32;
32
33    /// Reads a variable-length unsigned integer (field path encoding) without refilling.
34    ///
35    /// The caller must ensure sufficient bits are available in the lookahead buffer.
36    fn read_ubit_var_fp_unchecked(&mut self) -> i32;
37
38    fn read_normal(&mut self) -> f32;
39
40    /// Reads a compressed 3D normal vector.
41    ///
42    /// The vector components are encoded with selective precision,
43    /// and the third component is derived from the unit length constraint.
44    fn read_normal_vec3(&mut self) -> [f32; 3];
45
46    /// Reads a little-endian 64-bit unsigned integer.
47    fn read_u64_le(&mut self) -> u64;
48
49    /// Reads a null-terminated C-style string.
50    fn read_cstring(&mut self) -> String;
51
52    fn read_coordinate(&mut self) -> f32;
53
54    fn read_angle(&mut self, n: u32) -> f32;
55
56    fn read_bits_as_bytes(&mut self, n: u32) -> Vec<u8>;
57
58    /// Returns the number of bytes remaining in the buffer.
59    fn remaining_bytes(&self) -> usize;
60
61    /// Seeks to a specific byte offset from the start.
62    ///
63    /// # Arguments
64    /// * `offset` - Byte offset from the start of the data
65    fn seek(&mut self, offset: usize);
66}
67