summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-12-21 16:04:03 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-01-15 14:51:32 +0100
commit5f349be820b32a5bb312566a4a35ef679fe7e478 (patch)
tree4e5c9a197c485d3481aa8b9ed559582708c7ffb6 /include
parent8114294bf29ac6e44822c0ae43d4b0819f11b022 (diff)
bitvec: Add get/set byte sequences
The new functions bitvec_get_bytes and bitvec_set_bytes copy byte sequences from bitvecs to uint8_t arrays and vice versa. While the bytes in the bitvecs do not need to be aligned, the uint8_t arrays always are. In case the bytes in the bitvec are aligned, the implementation uses memcpy. Note that the implementation like the other existing functions assume MSB first encoding. [hfreyther: Squash the comment fix into this commit as well] Sponsored-by: On-Waves ehf
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/core/bitvec.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h
index 62e2e7b6..89eb7848 100644
--- a/include/osmocom/core/bitvec.h
+++ b/include/osmocom/core/bitvec.h
@@ -28,6 +28,14 @@
/*! \file bitvec.h
* \brief Osmocom bit vector abstraction
+ *
+ * These functions assume a MSB (most significant bit) first layout of the
+ * bits, so that for instance the 5 bit number abcde (a is MSB) can be
+ * embedded into a byte sequence like in xxxxxxab cdexxxxx. The bit count
+ * starts with the MSB, so the bits in a byte are numbered (MSB) 01234567 (LSB).
+ * Note that there are other incompatible encodings, like it is used
+ * for the EGPRS RLC data block headers (there the bits are numbered from LSB
+ * to MSB).
*/
#include <stdint.h>
@@ -63,5 +71,7 @@ int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count);
int bitvec_get_uint(struct bitvec *bv, int num_bits);
int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
+int bitvec_get_bytes(struct bitvec *bv, uint8_t *bytes, int count);
+int bitvec_set_bytes(struct bitvec *bv, const uint8_t *bytes, int count);
/*! @} */