Flipper Zero Firmware
Loading...
Searching...
No Matches
bit_buffer.h
1#pragma once
2
3#include <stddef.h>
4#include <stdint.h>
5#include <stdbool.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct BitBuffer BitBuffer;
12
13// Construction, deletion, reset
14
21BitBuffer* bit_buffer_alloc(size_t capacity_bytes);
22
28void bit_buffer_free(BitBuffer* buf);
29
35void bit_buffer_reset(BitBuffer* buf);
36
37// Copy and write
38
48void bit_buffer_copy(BitBuffer* buf, const BitBuffer* other);
49
60void bit_buffer_copy_right(BitBuffer* buf, const BitBuffer* other, size_t start_index);
61
72void bit_buffer_copy_left(BitBuffer* buf, const BitBuffer* other, size_t end_index);
73
82void bit_buffer_copy_bytes(BitBuffer* buf, const uint8_t* data, size_t size_bytes);
83
92void bit_buffer_copy_bits(BitBuffer* buf, const uint8_t* data, size_t size_bits);
93
102void bit_buffer_copy_bytes_with_parity(BitBuffer* buf, const uint8_t* data, size_t size_bits);
103
113void bit_buffer_write_bytes(const BitBuffer* buf, void* dest, size_t size_bytes);
114
126void bit_buffer_write_bytes_with_parity(
127 const BitBuffer* buf,
128 void* dest,
129 size_t size_bytes,
130 size_t* bits_written);
131
142void bit_buffer_write_bytes_mid(
143 const BitBuffer* buf,
144 void* dest,
145 size_t start_index,
146 size_t size_bytes);
147
148// Checks
149
157bool bit_buffer_has_partial_byte(const BitBuffer* buf);
158
166bool bit_buffer_starts_with_byte(const BitBuffer* buf, uint8_t byte);
167
168// Getters
169
176size_t bit_buffer_get_capacity_bytes(const BitBuffer* buf);
177
185size_t bit_buffer_get_size(const BitBuffer* buf);
186
194size_t bit_buffer_get_size_bytes(const BitBuffer* buf);
195
203uint8_t bit_buffer_get_byte(const BitBuffer* buf, size_t index);
204
214uint8_t bit_buffer_get_byte_from_bit(const BitBuffer* buf, size_t index_bits);
215
222const uint8_t* bit_buffer_get_data(const BitBuffer* buf);
223
230const uint8_t* bit_buffer_get_parity(const BitBuffer* buf);
231
232// Setters
233
242void bit_buffer_set_byte(BitBuffer* buf, size_t index, uint8_t byte);
243
253void bit_buffer_set_byte_with_parity(BitBuffer* buff, size_t index, uint8_t byte, bool parity);
254
262void bit_buffer_set_size(BitBuffer* buf, size_t new_size);
263
271void bit_buffer_set_size_bytes(BitBuffer* buf, size_t new_size_bytes);
272
273// Modification
274
282void bit_buffer_append(BitBuffer* buf, const BitBuffer* other);
283
293void bit_buffer_append_right(BitBuffer* buf, const BitBuffer* other, size_t start_index);
294
302void bit_buffer_append_byte(BitBuffer* buf, uint8_t byte);
303
312void bit_buffer_append_bytes(BitBuffer* buf, const uint8_t* data, size_t size_bytes);
313
321void bit_buffer_append_bit(BitBuffer* buf, bool bit);
322
323#ifdef __cplusplus
324}
325#endif
Definition bit_buffer.c:7