@@ -34,15 +34,15 @@ pub fn BitReader(comptime ReaderType: type) type {
3434 return self ;
3535 }
3636
37- // Try to have `nice` bits are available in buffer. Reads from
38- // forward reader if there is no `nice` bits in buffer. Returns error
39- // if end of forward stream is reached and internal buffer is empty.
40- // It will not error if less than `nice` bits are in buffer, only when
41- // all bits are exhausted. During inflate we usually know what is the
42- // maximum bits for the next step but usually that step will need less
43- // bits to decode. So `nice` is not hard limit, it will just try to have
44- // that number of bits available. If end of forward stream is reached
45- // it may be some extra zero bits in buffer.
37+ /// Try to have `nice` bits are available in buffer. Reads from
38+ /// forward reader if there is no `nice` bits in buffer. Returns error
39+ /// if end of forward stream is reached and internal buffer is empty.
40+ /// It will not error if less than `nice` bits are in buffer, only when
41+ /// all bits are exhausted. During inflate we usually know what is the
42+ /// maximum bits for the next step but usually that step will need less
43+ /// bits to decode. So `nice` is not hard limit, it will just try to have
44+ /// that number of bits available. If end of forward stream is reached
45+ /// it may be some extra zero bits in buffer.
4646 pub inline fn fill (self : * Self , nice : u6 ) ! void {
4747 if (self .nbits >= nice ) {
4848 return ; // We have enought bits
@@ -67,7 +67,7 @@ pub fn BitReader(comptime ReaderType: type) type {
6767 return error .EndOfStream ;
6868 }
6969
70- // Read exactly buf.len bytes into buf.
70+ /// Read exactly buf.len bytes into buf.
7171 pub fn readAll (self : * Self , buf : []u8 ) ! void {
7272 assert (self .alignBits () == 0 ); // internal bits must be at byte boundary
7373
@@ -87,17 +87,17 @@ pub fn BitReader(comptime ReaderType: type) type {
8787 pub const reverse : u3 = 0b100 ; // bit reverse readed bits
8888 };
8989
90- // Alias for readF(U, 0).
90+ /// Alias for readF(U, 0).
9191 pub fn read (self : * Self , comptime U : type ) ! U {
9292 return self .readF (U , 0 );
9393 }
9494
95- // Alias for readF with flag.peak set.
95+ /// Alias for readF with flag.peak set.
9696 pub inline fn peekF (self : * Self , comptime U : type , comptime how : u3 ) ! U {
9797 return self .readF (U , how | flag .peek );
9898 }
9999
100- // Read with flags provided.
100+ /// Read with flags provided.
101101 pub fn readF (self : * Self , comptime U : type , comptime how : u3 ) ! U {
102102 const n : u6 = @bitSizeOf (U );
103103 switch (how ) {
@@ -140,8 +140,8 @@ pub fn BitReader(comptime ReaderType: type) type {
140140 }
141141 }
142142
143- // Read n number of bits.
144- // Only buffered flag can be used in how.
143+ /// Read n number of bits.
144+ /// Only buffered flag can be used in how.
145145 pub fn readN (self : * Self , n : u4 , comptime how : u3 ) ! u16 {
146146 switch (how ) {
147147 0 = > {
@@ -156,14 +156,14 @@ pub fn BitReader(comptime ReaderType: type) type {
156156 return u ;
157157 }
158158
159- // Advance buffer for n bits.
159+ /// Advance buffer for n bits.
160160 pub fn shift (self : * Self , n : u6 ) ! void {
161161 if (n > self .nbits ) return error .EndOfStream ;
162162 self .bits >>= n ;
163163 self .nbits -= n ;
164164 }
165165
166- // Skip n bytes.
166+ /// Skip n bytes.
167167 pub fn skipBytes (self : * Self , n : u16 ) ! void {
168168 for (0.. n ) | _ | {
169169 try self .fill (8 );
@@ -176,32 +176,32 @@ pub fn BitReader(comptime ReaderType: type) type {
176176 return @intCast (self .nbits & 0x7 );
177177 }
178178
179- // Align stream to the byte boundary.
179+ /// Align stream to the byte boundary.
180180 pub fn alignToByte (self : * Self ) void {
181181 const ab = self .alignBits ();
182182 if (ab > 0 ) self .shift (ab ) catch unreachable ;
183183 }
184184
185- // Skip zero terminated string.
185+ /// Skip zero terminated string.
186186 pub fn skipStringZ (self : * Self ) ! void {
187187 while (true ) {
188188 if (try self .readF (u8 , 0 ) == 0 ) break ;
189189 }
190190 }
191191
192- // Read deflate fixed fixed code.
193- // Reads first 7 bits, and then mybe 1 or 2 more to get full 7,8 or 9 bit code.
194- // ref: https://datatracker.ietf.org/doc/html/rfc1951#page-12
195- // Lit Value Bits Codes
196- // --------- ---- -----
197- // 0 - 143 8 00110000 through
198- // 10111111
199- // 144 - 255 9 110010000 through
200- // 111111111
201- // 256 - 279 7 0000000 through
202- // 0010111
203- // 280 - 287 8 11000000 through
204- // 11000111
192+ /// Read deflate fixed fixed code.
193+ /// Reads first 7 bits, and then mybe 1 or 2 more to get full 7,8 or 9 bit code.
194+ /// ref: https://datatracker.ietf.org/doc/html/rfc1951#page-12
195+ /// Lit Value Bits Codes
196+ /// --------- ---- -----
197+ /// 0 - 143 8 00110000 through
198+ /// 10111111
199+ /// 144 - 255 9 110010000 through
200+ /// 111111111
201+ /// 256 - 279 7 0000000 through
202+ /// 0010111
203+ /// 280 - 287 8 11000000 through
204+ /// 11000111
205205 pub fn readFixedCode (self : * Self ) ! u16 {
206206 try self .fill (7 + 2 );
207207 const code7 = try self .readF (u7 , flag .buffered | flag .reverse );
0 commit comments