aboutsummaryrefslogtreecommitdiff
path: root/testing/yup-comm/utils/byte_buffer.h
diff options
context:
space:
mode:
authorJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
committerJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
commitdc8703206e3f0f69605c56d0e1127f7e17f3476a (patch)
tree166823a741dc420c10d54250cb53d1e3a6b74faf /testing/yup-comm/utils/byte_buffer.h
Initial commit
Diffstat (limited to 'testing/yup-comm/utils/byte_buffer.h')
-rw-r--r--testing/yup-comm/utils/byte_buffer.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/testing/yup-comm/utils/byte_buffer.h b/testing/yup-comm/utils/byte_buffer.h
new file mode 100644
index 0000000..30746f2
--- /dev/null
+++ b/testing/yup-comm/utils/byte_buffer.h
@@ -0,0 +1,31 @@
+/* Author: Jan Sucan */
+
+#ifndef BYTE_BUFFER_H_
+#define BYTE_BUFFER_H_
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#define GET_UINT8_T_FROM_BYTES(b, i) ((uint8_t) b[i])
+
+#define GET_UINT16_T_FROM_BYTES(b, i) ((uint16_t) ((b[i + 1] << 8) | b[i]))
+
+#define GET_UINT32_T_FROM_BYTES(b, i) ((uint32_t) ((b[i + 3] << 24) | (b[i + 2] << 16) | (b[i + 1] << 8) | b[i]))
+
+#define SET_BYTES_FROM_UINT8_T(b, i, v) {\
+ b[i + 0] = v;\
+}
+
+#define SET_BYTES_FROM_UINT16_T(b, i, v) { \
+ b[i + 1] = (v & 0xFF00) >> 8;\
+ b[i + 0] = (v & 0x00FF);\
+}
+
+#define SET_BYTES_FROM_UINT32_T(b, i, v) {\
+ b[i + 3] = (v & 0xFF000000) >> 24;\
+ b[i + 2] = (v & 0x00FF0000) >> 16;\
+ b[i + 1] = (v & 0x0000FF00) >> 8;\
+ b[i + 0] = (v & 0x000000FF);\
+}
+
+#endif /* BYTE_BUFFER_H_ */