Loading...
Searching...
No Matches
bit_buffer.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <stddef.h>
10#include <stdint.h>
11#include <stdbool.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17typedef struct BitBuffer BitBuffer;
18
25BitBuffer* bit_buffer_alloc(size_t capacity_bytes);
26
31void bit_buffer_free(BitBuffer* buf);
32
38
39// Copy and write
40
50void bit_buffer_copy(BitBuffer* buf, const BitBuffer* other);
51
62void bit_buffer_copy_right(BitBuffer* buf, const BitBuffer* other, size_t start_index);
63
74void bit_buffer_copy_left(BitBuffer* buf, const BitBuffer* other, size_t end_index);
75
86void bit_buffer_copy_bytes(BitBuffer* buf, const uint8_t* data, size_t size_bytes);
87
98void bit_buffer_copy_bits(BitBuffer* buf, const uint8_t* data, size_t size_bits);
99
113void bit_buffer_copy_bytes_with_parity(BitBuffer* buf, const uint8_t* data, size_t size_bits);
114
124void bit_buffer_write_bytes(const BitBuffer* buf, void* dest, size_t size_bytes);
125
143 const BitBuffer* buf,
144 void* dest,
145 size_t size_bytes,
146 size_t* bits_written);
147
161 const BitBuffer* buf,
162 void* dest,
163 size_t start_index,
164 size_t size_bytes);
165
166// Checks
167
176
184bool bit_buffer_starts_with_byte(const BitBuffer* buf, uint8_t byte);
185
186// Getters
187
196
206size_t bit_buffer_get_size(const BitBuffer* buf);
207
218size_t bit_buffer_get_size_bytes(const BitBuffer* buf);
219
230uint8_t bit_buffer_get_byte(const BitBuffer* buf, size_t index);
231
245uint8_t bit_buffer_get_byte_from_bit(const BitBuffer* buf, size_t index_bits);
246
253const uint8_t* bit_buffer_get_data(const BitBuffer* buf);
254
261const uint8_t* bit_buffer_get_parity(const BitBuffer* buf);
262
263// Setters
264
274void bit_buffer_set_byte(BitBuffer* buf, size_t index, uint8_t byte);
275
286void bit_buffer_set_byte_with_parity(BitBuffer* buff, size_t index, uint8_t byte, bool parity);
287
295void bit_buffer_set_size(BitBuffer* buf, size_t new_size);
296
304void bit_buffer_set_size_bytes(BitBuffer* buf, size_t new_size_bytes);
305
306// Modification
307
316void bit_buffer_append(BitBuffer* buf, const BitBuffer* other);
317
328void bit_buffer_append_right(BitBuffer* buf, const BitBuffer* other, size_t start_index);
329
338void bit_buffer_append_byte(BitBuffer* buf, uint8_t byte);
339
349void bit_buffer_append_bytes(BitBuffer* buf, const uint8_t* data, size_t size_bytes);
350
359void bit_buffer_append_bit(BitBuffer* buf, bool bit);
360
361#ifdef __cplusplus
362}
363#endif
bool bit_buffer_has_partial_byte(const BitBuffer *buf)
Check whether a BitBuffer instance contains a partial byte (i.e. the bit count is not divisible by 8)...
Definition bit_buffer.c:187
void bit_buffer_set_byte_with_parity(BitBuffer *buff, size_t index, uint8_t byte, bool parity)
Set byte and parity bit value at a specified index in a BitBuffer instance.
Definition bit_buffer.c:258
size_t bit_buffer_get_size_bytes(const BitBuffer *buf)
Get a BitBuffer instance's data size (i.e. the amount of stored data), in bytes.
Definition bit_buffer.c:211
void bit_buffer_set_size_bytes(BitBuffer *buf, size_t new_size_bytes)
Resize a BitBuffer instance to a new size, in bytes.
Definition bit_buffer.c:277
void bit_buffer_copy(BitBuffer *buf, const BitBuffer *other)
Copy another BitBuffer instance's contents to this one, replacing all of the original data.
Definition bit_buffer.c:45
void bit_buffer_write_bytes_with_parity(const BitBuffer *buf, void *dest, size_t size_bytes, size_t *bits_written)
Write a BitBuffer instance's entire contents to an arbitrary memory location.
Definition bit_buffer.c:136
uint8_t bit_buffer_get_byte_from_bit(const BitBuffer *buf, size_t index_bits)
Get a byte value starting from the specified bit index in a BitBuffer instance.
Definition bit_buffer.c:224
void bit_buffer_copy_left(BitBuffer *buf, const BitBuffer *other, size_t end_index)
Copy all BitBuffer instance's contents to this one, ending with end_index, replacing all of the origi...
Definition bit_buffer.c:67
void bit_buffer_free(BitBuffer *buf)
Delete a BitBuffer instance.
Definition bit_buffer.c:28
void bit_buffer_copy_bytes_with_parity(BitBuffer *buf, const uint8_t *data, size_t size_bits)
Copy a byte with parity array to a BitBuffer instance, replacing all of the original data.
Definition bit_buffer.c:96
void bit_buffer_set_byte(BitBuffer *buf, size_t index, uint8_t byte)
Set byte value at a specified index in a BitBuffer instance.
Definition bit_buffer.c:249
void bit_buffer_append_right(BitBuffer *buf, const BitBuffer *other, size_t start_index)
Append a BitBuffer's instance contents to this one, starting from start_index.
Definition bit_buffer.c:288
void bit_buffer_copy_bytes(BitBuffer *buf, const uint8_t *data, size_t size_bytes)
Copy a byte array to a BitBuffer instance, replacing all of the original data.
Definition bit_buffer.c:77
void bit_buffer_append(BitBuffer *buf, const BitBuffer *other)
Append all BitBuffer's instance contents to this one.
Definition bit_buffer.c:284
void bit_buffer_copy_bits(BitBuffer *buf, const uint8_t *data, size_t size_bits)
Copy a byte array to a BitBuffer instance, replacing all of the original data.
Definition bit_buffer.c:86
size_t bit_buffer_get_size(const BitBuffer *buf)
Get a BitBuffer instance's data size (i.e. the amount of stored data), in bits.
Definition bit_buffer.c:205
void bit_buffer_set_size(BitBuffer *buf, size_t new_size)
Resize a BitBuffer instance to a new size, in bits.
Definition bit_buffer.c:270
void bit_buffer_append_bit(BitBuffer *buf, bool bit)
Append a bit to a BitBuffer instance.
Definition bit_buffer.c:323
const uint8_t * bit_buffer_get_parity(const BitBuffer *buf)
Get the pointer to the parity data of a BitBuffer instance.
Definition bit_buffer.c:243
void bit_buffer_append_byte(BitBuffer *buf, uint8_t byte)
Append a byte to a BitBuffer instance.
Definition bit_buffer.c:301
void bit_buffer_copy_right(BitBuffer *buf, const BitBuffer *other, size_t start_index)
Copy all BitBuffer instance's contents to this one, starting from start_index, replacing all of the o...
Definition bit_buffer.c:57
size_t bit_buffer_get_capacity_bytes(const BitBuffer *buf)
Get a BitBuffer instance's capacity (i.e. the maximum possible amount of data), in bytes.
Definition bit_buffer.c:199
uint8_t bit_buffer_get_byte(const BitBuffer *buf, size_t index)
Get a byte value at a specified index in a BitBuffer instance.
Definition bit_buffer.c:217
bool bit_buffer_starts_with_byte(const BitBuffer *buf, uint8_t byte)
Check whether a BitBuffer instance's contents start with the designated byte.
Definition bit_buffer.c:193
void bit_buffer_write_bytes_mid(const BitBuffer *buf, void *dest, size_t start_index, size_t size_bytes)
Write a slice of BitBuffer instance's contents to an arbitrary memory location.
Definition bit_buffer.c:175
void bit_buffer_reset(BitBuffer *buf)
Clear all data from a BitBuffer instance.
Definition bit_buffer.c:36
void bit_buffer_append_bytes(BitBuffer *buf, const uint8_t *data, size_t size_bytes)
Append a byte array to a BitBuffer instance.
Definition bit_buffer.c:312
const uint8_t * bit_buffer_get_data(const BitBuffer *buf)
Get the pointer to a BitBuffer instance's underlying data.
Definition bit_buffer.c:237
void bit_buffer_write_bytes(const BitBuffer *buf, void *dest, size_t size_bytes)
Write a BitBuffer instance's entire contents to an arbitrary memory location.
Definition bit_buffer.c:128
BitBuffer * bit_buffer_alloc(size_t capacity_bytes)
Allocate a BitBuffer instance.
Definition bit_buffer.c:14
Definition bit_buffer.c:7