aboutsummaryrefslogtreecommitdiff
path: root/shared/bin.h
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-12 13:57:33 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-12 13:57:33 +0100
commit61dd8a5ee66734dfd53ee9be725c9e71fd8d5414 (patch)
treeda896421d93baa3a80a7c6ebb3a16fc25138516f /shared/bin.h
parent8c21a929d06ed108b0e64f3892d036cd4cd67e51 (diff)
implement DYN_MEMBER_SIZEOF macro correctly and implement cd_cmd_response_sizeof
Diffstat (limited to 'shared/bin.h')
-rw-r--r--shared/bin.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/shared/bin.h b/shared/bin.h
index 35d2bc4..0e16ec0 100644
--- a/shared/bin.h
+++ b/shared/bin.h
@@ -10,6 +10,7 @@
*/
#include <stdint.h>
+#include <malloc.h>
#ifdef __cplusplus
extern "C" {
@@ -50,6 +51,21 @@ uint32_t cd_bin_ntoh32(uint32_t n32);
/** @brief convert 16-bit value from network (big-endian) to host endian */
uint16_t cd_bin_ntoh16(uint16_t n16);
+/**
+ * @brief convert (8*s)-bit value from network (big-endian) to host endian
+ * (dynamic size)
+ *
+ * @param n pointer to number
+ * @param s size of number in bytes
+ *
+ * @return 32-bit integer regardless of `s`
+ *
+ * this function is exclusively used by the CD_DYN_MEMBER_SIZEOF macro in
+ * shared/protocol.c
+ */
+uint32_t cd_bin_ntohd(uint8_t* n, size_t s);
+uint32_t cd_bin_htond(uint8_t* h, size_t s);
+
/** @brief replace 32-bit value from host endian to network (big-endian) */
void cd_bin_repl_hton32(uint32_t *h32);
/** @brief replace 16-bit value from host endian to network (big-endian) */