bitstruct 8.22.2__cp315-cp315-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bitstruct/bitstream.h ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2019 Erik Moqvist
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+
27
+ #ifndef BITSTREAM_H
28
+ #define BITSTREAM_H
29
+
30
+ #include <stdint.h>
31
+
32
+ #define BITSTREAM_VERSION "0.8.0"
33
+
34
+ struct bitstream_writer_t {
35
+ uint8_t *buf_p;
36
+ int byte_offset;
37
+ int bit_offset;
38
+ };
39
+
40
+ struct bitstream_writer_bounds_t {
41
+ struct bitstream_writer_t *writer_p;
42
+ int first_byte_offset;
43
+ uint8_t first_byte;
44
+ int last_byte_offset;
45
+ uint8_t last_byte;
46
+ };
47
+
48
+ struct bitstream_reader_t {
49
+ const uint8_t *buf_p;
50
+ int byte_offset;
51
+ int bit_offset;
52
+ };
53
+
54
+ /*
55
+ * The writer.
56
+ */
57
+
58
+ void bitstream_writer_init(struct bitstream_writer_t *self_p,
59
+ uint8_t *buf_p);
60
+
61
+ int bitstream_writer_size_in_bits(struct bitstream_writer_t *self_p);
62
+
63
+ int bitstream_writer_size_in_bytes(struct bitstream_writer_t *self_p);
64
+
65
+ /* Write bits to the stream. Clears each byte before bits are
66
+ written. */
67
+ void bitstream_writer_write_bit(struct bitstream_writer_t *self_p,
68
+ int value);
69
+
70
+ void bitstream_writer_write_bytes(struct bitstream_writer_t *self_p,
71
+ const uint8_t *buf_p,
72
+ int length);
73
+
74
+ void bitstream_writer_write_u8(struct bitstream_writer_t *self_p,
75
+ uint8_t value);
76
+
77
+ void bitstream_writer_write_u16(struct bitstream_writer_t *self_p,
78
+ uint16_t value);
79
+
80
+ void bitstream_writer_write_u32(struct bitstream_writer_t *self_p,
81
+ uint32_t value);
82
+
83
+ void bitstream_writer_write_u64(struct bitstream_writer_t *self_p,
84
+ uint64_t value);
85
+
86
+ /* Upper unused bits must be zero. */
87
+ void bitstream_writer_write_u64_bits(struct bitstream_writer_t *self_p,
88
+ uint64_t value,
89
+ int number_of_bits);
90
+
91
+ void bitstream_writer_write_repeated_bit(struct bitstream_writer_t *self_p,
92
+ int value,
93
+ int length);
94
+
95
+ void bitstream_writer_write_repeated_u8(struct bitstream_writer_t *self_p,
96
+ uint8_t value,
97
+ int length);
98
+
99
+ /* Insert bits into the stream. Leaves all other bits unmodified. */
100
+ void bitstream_writer_insert_bit(struct bitstream_writer_t *self_p,
101
+ int value);
102
+
103
+ void bitstream_writer_insert_bytes(struct bitstream_writer_t *self_p,
104
+ const uint8_t *buf_p,
105
+ int length);
106
+
107
+ void bitstream_writer_insert_u8(struct bitstream_writer_t *self_p,
108
+ uint8_t value);
109
+
110
+ void bitstream_writer_insert_u16(struct bitstream_writer_t *self_p,
111
+ uint16_t value);
112
+
113
+ void bitstream_writer_insert_u32(struct bitstream_writer_t *self_p,
114
+ uint32_t value);
115
+
116
+ void bitstream_writer_insert_u64(struct bitstream_writer_t *self_p,
117
+ uint64_t value);
118
+
119
+ void bitstream_writer_insert_u64_bits(struct bitstream_writer_t *self_p,
120
+ uint64_t value,
121
+ int number_of_bits);
122
+
123
+ /* Move write position. Seeking backwards makes the written size
124
+ smaller. Use write with care after seek, as seek does not clear
125
+ bytes. */
126
+ void bitstream_writer_seek(struct bitstream_writer_t *self_p,
127
+ int offset);
128
+
129
+ /* Save-restore first and last bytes in given range, so write can be
130
+ used in given range. */
131
+ void bitstream_writer_bounds_save(struct bitstream_writer_bounds_t *self_p,
132
+ struct bitstream_writer_t *writer_p,
133
+ int bit_offset,
134
+ int length);
135
+
136
+ void bitstream_writer_bounds_restore(struct bitstream_writer_bounds_t *self_p);
137
+
138
+ /*
139
+ * The reader.
140
+ */
141
+
142
+ void bitstream_reader_init(struct bitstream_reader_t *self_p,
143
+ const uint8_t *buf_p);
144
+
145
+ /* Read bits from the stream. */
146
+ int bitstream_reader_read_bit(struct bitstream_reader_t *self_p);
147
+
148
+ void bitstream_reader_read_bytes(struct bitstream_reader_t *self_p,
149
+ uint8_t *buf_p,
150
+ int length);
151
+
152
+ uint8_t bitstream_reader_read_u8(struct bitstream_reader_t *self_p);
153
+
154
+ uint16_t bitstream_reader_read_u16(struct bitstream_reader_t *self_p);
155
+
156
+ uint32_t bitstream_reader_read_u32(struct bitstream_reader_t *self_p);
157
+
158
+ uint64_t bitstream_reader_read_u64(struct bitstream_reader_t *self_p);
159
+
160
+ uint64_t bitstream_reader_read_u64_bits(struct bitstream_reader_t *self_p,
161
+ int number_of_bits);
162
+
163
+ /* Move read position. */
164
+ void bitstream_reader_seek(struct bitstream_reader_t *self_p,
165
+ int offset);
166
+
167
+ /* Get read position. */
168
+ int bitstream_reader_tell(struct bitstream_reader_t *self_p);
169
+
170
+ #endif