Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* license:BSD-3-Clause |
2 | * copyright-holders:Aaron Giles | |
3 | *************************************************************************** | |
4 | ||
5 | bitstream.h | |
6 | ||
7 | Helper classes for reading/writing at the bit level. | |
8 | ||
9 | ***************************************************************************/ | |
10 | ||
11 | #pragma once | |
12 | ||
13 | #ifndef __BITSTREAM_H__ | |
14 | #define __BITSTREAM_H__ | |
15 | ||
16 | #include <stdint.h> | |
17 | ||
18 | /*************************************************************************** | |
19 | * TYPE DEFINITIONS | |
20 | *************************************************************************** | |
21 | */ | |
22 | ||
23 | /* helper class for reading from a bit buffer */ | |
24 | struct bitstream | |
25 | { | |
26 | uint32_t buffer; /* current bit accumulator */ | |
27 | int bits; /* number of bits in the accumulator */ | |
28 | const uint8_t * read; /* read pointer */ | |
29 | uint32_t doffset; /* byte offset within the data */ | |
30 | uint32_t dlength; /* length of the data */ | |
31 | }; | |
32 | ||
33 | struct bitstream* create_bitstream(const void *src, uint32_t srclength); | |
34 | int bitstream_overflow(struct bitstream* bitstream); | |
35 | uint32_t bitstream_read_offset(struct bitstream* bitstream); | |
36 | ||
37 | uint32_t bitstream_read(struct bitstream* bitstream, int numbits); | |
38 | uint32_t bitstream_peek(struct bitstream* bitstream, int numbits); | |
39 | void bitstream_remove(struct bitstream* bitstream, int numbits); | |
40 | uint32_t bitstream_flush(struct bitstream* bitstream); | |
41 | ||
42 | #endif |