Rename rde_common to bej_common
bej_common.h is a more consistant name than rde_common.h.
Also this repo only contains code related to BEJ encoding and decoding.
Therefore this change removes the rde related structs defind in the
bej_common.h. Those structs should be defined somewhere else (libpldm).
Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: Ic296ece11efc0967366e197a8609c3c88c325610
diff --git a/src/bej_common.c b/src/bej_common.c
new file mode 100644
index 0000000..1d3be07
--- /dev/null
+++ b/src/bej_common.c
@@ -0,0 +1,25 @@
+#include "bej_common.h"
+
+uint64_t bejGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes)
+{
+ uint64_t num = 0;
+ for (uint8_t i = 0; i < numOfBytes; ++i)
+ {
+ num |= (uint64_t)(*(bytes + i)) << (i * 8);
+ }
+ return num;
+}
+
+uint64_t bejGetNnint(const uint8_t* nnint)
+{
+ // In nnint, first byte indicate how many bytes are there. Remaining bytes
+ // represent the value in little-endian format.
+ const uint8_t size = *nnint;
+ return bejGetUnsignedInteger(nnint + sizeof(uint8_t), size);
+}
+
+uint8_t bejGetNnintSize(const uint8_t* nnint)
+{
+ // In nnint, first byte indicate how many bytes are there.
+ return *nnint + sizeof(uint8_t);
+}