libosmocore
0.9.6-13.20170220git32ee5af8.fc33
Osmocom core library
|
Osmocom bit vector abstraction. More...
#include <stdint.h>
#include <osmocom/core/talloc.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | bitvec |
structure describing a bit vector More... | |
Enumerations | |
enum | bit_value { ZERO = 0, ONE = 1, L = 2, H = 3 } |
A single GSM bit. More... | |
Functions | |
enum bit_value | bitvec_get_bit_pos (const struct bitvec *bv, unsigned int bitnr) |
check if the bit is 0 or 1 for a given position inside a bitvec More... | |
enum bit_value | bitvec_get_bit_pos_high (const struct bitvec *bv, unsigned int bitnr) |
check if the bit is L or H for a given position inside a bitvec More... | |
unsigned int | bitvec_get_nth_set_bit (const struct bitvec *bv, unsigned int n) |
get the Nth set bit inside the bit vector More... | |
int | bitvec_set_bit_pos (struct bitvec *bv, unsigned int bitnr, enum bit_value bit) |
set a bit at given position in a bit vector More... | |
int | bitvec_set_bit (struct bitvec *bv, enum bit_value bit) |
set the next bit inside a bitvec More... | |
int | bitvec_get_bit_high (struct bitvec *bv) |
get the next bit (low/high) inside a bitvec More... | |
int | bitvec_set_bits (struct bitvec *bv, const enum bit_value *bits, unsigned int count) |
set multiple bits (based on array of bitvals) at current pos More... | |
int | bitvec_set_uint (struct bitvec *bv, unsigned int ui, unsigned int num_bits) |
set multiple bits (based on numeric value) at current pos More... | |
int | bitvec_get_uint (struct bitvec *bv, unsigned int num_bits) |
get multiple bits (based on numeric value) from current pos More... | |
int | bitvec_find_bit_pos (const struct bitvec *bv, unsigned int n, enum bit_value val) |
find first bit set in bit vector More... | |
int | bitvec_spare_padding (struct bitvec *bv, unsigned int up_to_bit) |
pad all remaining bits up to num_bits More... | |
int | bitvec_get_bytes (struct bitvec *bv, uint8_t *bytes, unsigned int count) |
get multiple bytes from current pos Assumes MSB first encoding. More... | |
int | bitvec_set_bytes (struct bitvec *bv, const uint8_t *bytes, unsigned int count) |
set multiple bytes at current pos Assumes MSB first encoding. More... | |
struct bitvec * | bitvec_alloc (unsigned int size, TALLOC_CTX *ctx) |
Allocate a bit vector. More... | |
void | bitvec_free (struct bitvec *bv) |
Free a bit vector (release its memory) More... | |
int | bitvec_unhex (struct bitvec *bv, const char *src) |
read hexadecimap string into a bit vector More... | |
unsigned int | bitvec_pack (const struct bitvec *bv, uint8_t *buffer) |
Export a bit vector to a buffer. More... | |
unsigned int | bitvec_unpack (struct bitvec *bv, const uint8_t *buffer) |
Copy buffer of unpacked bits into bit vector. More... | |
uint64_t | bitvec_read_field (struct bitvec *bv, unsigned int *read_index, unsigned int len) |
read part of the vector More... | |
int | bitvec_write_field (struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len) |
write into the vector More... | |
int | bitvec_fill (struct bitvec *bv, unsigned int num_bits, enum bit_value fill) |
fill num_bits with \fill starting from the current position More... | |
char | bit_value_to_char (enum bit_value v) |
convert enum to corresponding character More... | |
void | bitvec_to_string_r (const struct bitvec *bv, char *str) |
prints bit vector to provided string It's caller's responsibility to ensure that we won't shoot him in the foot: the provided buffer should be at lest cur_bit + 1 bytes long | |
void | bitvec_zero (struct bitvec *bv) |
force bit vector to all 0 and current bit to the beginnig of the vector | |
unsigned | bitvec_rl (const struct bitvec *bv, bool b) |
Return number (bits) of uninterrupted bit run in vector starting from the MSB. More... | |
unsigned | bitvec_rl_curbit (struct bitvec *bv, bool b, int max_bits) |
Return number (bits) of uninterrupted bit run in vector starting from the current bit. More... | |
void | bitvec_shiftl (struct bitvec *bv, unsigned int n) |
int16_t | bitvec_get_int16_msb (const struct bitvec *bv, unsigned int num_bits) |
get multiple bits (num_bits) from beginning of vector (MSB side) More... | |
unsigned int | bitvec_add_array (struct bitvec *bv, const uint32_t *array, unsigned int array_len, bool dry_run, unsigned int num_bits) |
Add given array to bitvec. More... | |
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).