Welcome to little lamb

Code » limb » commit 123742a

u16/u32/u64: Update interface

author Olivier Brunel
2023-02-20 09:40:23 UTC
committer Olivier Brunel
2023-02-20 14:14:20 UTC
parent 4dfc5355fe3c0e681f0aef19f0a42711fb6b8a77

u16/u32/u64: Update interface

Moving to better consistency (within limb) where (when applicable) we
put destination first and context last.

doc/u16_pack.3.md +5 -5
doc/u32_pack.3.md +5 -5
doc/u64_pack.3.md +8 -8
include/limb/u16.h +4 -4
include/limb/u32.h +4 -4
include/limb/u64.h +6 -6
src/saencdata.c +3 -3

diff --git a/doc/u16_pack.3.md b/doc/u16_pack.3.md
index 94e5900..0a3ffae 100644
--- a/doc/u16_pack.3.md
+++ b/doc/u16_pack.3.md
@@ -11,10 +11,10 @@ integer (u16) into\/from a byte array
     #include <limb/u16.h>
 
 ```pre hl
-void u16_pack(u16 <em>val</em>, void *<em>dst</em>)
-void u16_unpack(const void *<em>sce</em>, u16 *<em>val</em>)
-void u16_pack_big(u16 <em>val</em>, void *<em>dst</em>)
-void 164_unpack_big(const void *<em>sce</em>, u16 *<em>val</em>)
+void u16_pack(void *<em>dst</em>, u16 <em>val</em>)
+void u16_unpack(u16 *<em>val</em>, const void *<em>sce</em>)
+void u16_pack_big(void *<em>dst</em>, u16 <em>val</em>)
+void 164_unpack_big(u16 *<em>val</em>, const void *<em>sce</em>)
 ```
 
 # DESCRIPTION
@@ -23,7 +23,7 @@ All of these aim to either pack the given integer (u16) `val` into the specified
 byte array `dst`, or unpack from the specified byte array `sce` the integer
 value into the pointed `val`.
 
-The `u16_pack`() function packs `val` into 8 bytes encoded as little endian, the
+The `u16_pack`() function packs `val` into 2 bytes encoded as little endian, the
 `u16_pack_big`() function does the same encoded as big endian.
 
 The `u16_unpack` family does the same, only unpacking from the byte array `sce`
diff --git a/doc/u32_pack.3.md b/doc/u32_pack.3.md
index c1b7780..8c6645f 100644
--- a/doc/u32_pack.3.md
+++ b/doc/u32_pack.3.md
@@ -11,10 +11,10 @@ integer (u32) into\/from a byte array
     #include <limb/u32.h>
 
 ```pre hl
-void u32_pack(u32 <em>val</em>, void *<em>dst</em>)
-void u32_unpack(const void *<em>sce</em>, u32 *<em>val</em>)
-void u32_pack_big(u32 <em>val</em>, void *<em>dst</em>)
-void 324_unpack_big(const void *<em>sce</em>, u32 *<em>val</em>)
+void u32_pack(void *<em>dst</em>, u32 <em>val</em>)
+void u32_unpack(u32 *<em>val</em>, const void *<em>sce</em>)
+void u32_pack_big(void *<em>dst</em>, u32 <em>val</em>)
+void u32_unpack_big(u32 *<em>val</em>, const void *<em>sce</em>)
 ```
 
 # DESCRIPTION
@@ -23,7 +23,7 @@ All of these aim to either pack the given integer (u32) `val` into the specified
 byte array `dst`, or unpack from the specified byte array `sce` the integer
 value into the pointed `val`.
 
-The `u32_pack`() function packs `val` into 8 bytes encoded as little endian, the
+The `u32_pack`() function packs `val` into 4 bytes encoded as little endian, the
 `u32_pack_big`() function does the same encoded as big endian.
 
 The `u32_unpack` family does the same, only unpacking from the byte array `sce`
diff --git a/doc/u64_pack.3.md b/doc/u64_pack.3.md
index 7572874..539f84b 100644
--- a/doc/u64_pack.3.md
+++ b/doc/u64_pack.3.md
@@ -13,12 +13,12 @@ u64\_unpack\_trim - pack\/unpack an integer (u64) into\/from a byte array
     #include <limb/u64.h>
 
 ```pre hl
-void u64_pack(u64 <em>val</em>, void *<em>dst</em>)
-void u64_unpack(const void *<em>sce</em>, u64 *<em>val</em>)
-void u64_pack_big(u64 <em>val</em>, void *<em>dst</em>)
-void u64_unpack_big(const void *<em>sce</em>, u64 *<em>val</em>)
-int u64_pack_trim(u64 <em>val</em>, void *<em>dst</em>)
-int u64_unpack_trim(const void *<em>sce</em>, u64 *<em>val</em>)
+void u64_pack(void *<em>dst</em>, u64 <em>val</em>)
+void u64_unpack(u64 *<em>val</em>, const void *<em>sce</em>)
+void u64_pack_big(void *<em>dst</em>, u64 <em>val</em>)
+void u64_unpack_big(u64 *<em>val</em>, const void *<em>sce</em>)
+int u64_pack_trim(void *<em>dst</em>, u64 <em>val</em>)
+int u64_unpack_trim(u64 *<em>val</em>, const void *<em>sce</em>)
 ```
 
 # DESCRIPTION
@@ -27,8 +27,8 @@ All of these aim to either pack the given integer (u64) `val` into the specified
 byte array `dst`, or unpack from the specified byte array `sce` the integer
 value into the pointed `val`.
 
-The `u64_pack`() function packs `val` into 8 bytes encoded as little endian, the
-`u64_pack_big`() function does the same encoded as big endian, and the
+The `u64_pack`() function packs `val` into 8 bytes encoded as little endian,
+the `u64_pack_big`() function does the same encoded as big endian, and the
 `u64_pack_trim`() function pack in a little endian mode but /trimming/ the
 "unneeded" bits, i.e. all most significant bits set to zero need not be
 included. It will therefore pack into from 1 to 9 bytes, depending on the value.
diff --git a/include/limb/u16.h b/include/limb/u16.h
index 28cc4e9..9c824c6 100644
--- a/include/limb/u16.h
+++ b/include/limb/u16.h
@@ -4,9 +4,9 @@
 #include <skalibs/uint16.h>
 #include "limb/int.h"
 
-#define u16_pack(val,dst)           uint16_pack((char *) (dst), val)
-#define u16_unpack(sce,val)         uint16_unpack((const char *) (sce), val)
-#define u16_pack_big(val,dst)       uint16_pack_big((char *) (dst), val)
-#define u16_unpack_big(sce,val)     uint16_unpack_big((const char *) (sce), val)
+#define u16_pack(dst,val)           uint16_pack((char *) (dst), val)
+#define u16_unpack(val,sce)         uint16_unpack((const char *) (sce), val)
+#define u16_pack_big(dst,val)       uint16_pack_big((char *) (dst), val)
+#define u16_unpack_big(val,sce)     uint16_unpack_big((const char *) (sce), val)
 
 #endif /* LIMB_U16_H */
diff --git a/include/limb/u32.h b/include/limb/u32.h
index 6a3baca..d7c32de 100644
--- a/include/limb/u32.h
+++ b/include/limb/u32.h
@@ -4,9 +4,9 @@
 #include <skalibs/uint32.h>
 #include "limb/int.h"
 
-#define u32_pack(val,dst)           uint32_pack((char *) (dst), val)
-#define u32_unpack(sce,val)         uint32_unpack((const char *) (sce), val)
-#define u32_pack_big(val,dst)       uint32_pack_big((char *) (dst), val)
-#define u32_unpack_big(sce,val)     uint32_unpack_big((const char *) (sce), val)
+#define u32_pack(dst,val)           uint32_pack((char *) (dst), val)
+#define u32_unpack(val,sce)         uint32_unpack((const char *) (sce), val)
+#define u32_pack_big(dst,val)       uint32_pack_big((char *) (dst), val)
+#define u32_unpack_big(val,sce)     uint32_unpack_big((const char *) (sce), val)
 
 #endif /* LIMB_U32_H */
diff --git a/include/limb/u64.h b/include/limb/u64.h
index 439bca7..fe79dc4 100644
--- a/include/limb/u64.h
+++ b/include/limb/u64.h
@@ -5,11 +5,11 @@
 #include "limb/int.h"
 #include "limb/uint64.h"
 
-#define u64_pack(val,dst)           uint64_pack((char *) (dst), val)
-#define u64_unpack(sce,val)         uint64_unpack((const char *) (sce), val)
-#define u64_pack_big(val,dst)       uint64_pack_big((char *) (dst), val)
-#define u64_unpack_big(sce,val)     uint64_unpack_big((const char *) (sce), val)
-#define u64_pack_trim(val,dst)      uint64_pack_trim((char *) (dst), val)
-#define u64_unpack_trim(sce,val)    uint64_unpack_trim((const char *) (sce), val)
+#define u64_pack(dst,val)           uint64_pack((char *) (dst), val)
+#define u64_unpack(val,sce)         uint64_unpack((const char *) (sce), val)
+#define u64_pack_big(dst,val)       uint64_pack_big((char *) (dst), val)
+#define u64_unpack_big(val,sce)     uint64_unpack_big((const char *) (sce), val)
+#define u64_pack_trim(dst,val)      uint64_pack_trim((char *) (dst), val)
+#define u64_unpack_trim(val,sce)    uint64_unpack_trim((const char *) (sce), val)
 
 #endif /* LIMB_U64_H */
diff --git a/src/saencdata.c b/src/saencdata.c
index 4fa6a54..0c774b3 100644
--- a/src/saencdata.c
+++ b/src/saencdata.c
@@ -11,15 +11,15 @@ saencdata(stralloc *sa, const u16 id, const void *val, const size_t size)
     /* 2 bytes for id, then we might need up to 9 bytes to store our integer */
     if (!stralloc_readyplus(sa, 2 + 9))
         return 0;
-    u16_pack(id, sa->s + sa->len);
+    u16_pack(sa->s + sa->len, id);
     sa->len += 2;
 
     if (is_blob) {
-        sa->len += u64_pack_trim((u64) size, (u8 *) sa->s + sa->len);
+        sa->len += u64_pack_trim(sa->s + sa->len, (u64) size);
         if (!stralloc_catb(sa, * (char **) val, size))
             goto err;
     } else {
-        sa->len += u64_pack_trim(* (u64 *) val, (u8 *) sa->s + sa->len);
+        sa->len += u64_pack_trim(sa->s + sa->len, * (u64 *) val);
     }
 
     return 1;