This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Minh-Quang Nguyen gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/3990
bitvec: implement write L or H value to vector
Change-Id: I36a76916a5986f098b6be6b5b779639c470725ef
---
M include/osmocom/core/bitvec.h
M src/bitvec.c
2 files changed, 25 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/90/3990/1
diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h
index d4c7d68..944b391 100644
--- a/include/osmocom/core/bitvec.h
+++ b/include/osmocom/core/bitvec.h
@@ -70,6 +70,7 @@
unsigned int bitvec_unpack(struct bitvec *bv, const uint8_t *buffer);
uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned int len);
int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len);
+int bitvec_write_field_lh(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len);
int bitvec_fill(struct bitvec *bv, unsigned int num_bits, enum bit_value fill);
char bit_value_to_char(enum bit_value v);
void bitvec_to_string_r(const struct bitvec *bv, char *str);
diff --git a/src/bitvec.c b/src/bitvec.c
index f07b42c..a294675 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -503,6 +503,30 @@
return 0;
}
+/*! write L/H value into the vector
+ * \param[in] bv The boolean vector to work on
+ * \param[in,out] write_index Where writing supposed to start in the vector
+ * \param[in] L or H value to be written to the vector
+ * \param[in] len How many bits to write
+ * \returns 0 in case of success or negative value on error
+ */
+int bitvec_write_field_lh(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len)
+{
+ unsigned int i;
+ int rc;
+ bv->cur_bit = *write_index;
+ for (i = 0; i < len; i++) {
+ int bit = L;
+ if (val & ((uint64_t)1 << (len - i - 1)))
+ bit = H;
+ rc = bitvec_set_bit(bv, bit);
+ if (rc)
+ return rc;
+ }
+ *write_index += len;
+ return 0;
+}
+
/*! convert enum to corresponding character
* \param v input value (bit)
* \return single character, either 0, 1, L or H */
--
To view, visit https://gerrit.osmocom.org/3990
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I36a76916a5986f098b6be6b5b779639c470725ef
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Minh-Quang Nguyen <minh-quang.nguyen at nutaq.com>