@@ -17,6 +17,11 @@ extern "C" {
1717/**
1818 * @brief Binary serialisation object.
1919 *
20+ * Naming convention:
21+ * - Functions ending in `_b` (or `_b_size`) are NOT MessagePack, i.e. write
22+ * data in plain big endian binary format.
23+ * - All other functions encode their input in MessagePack format.
24+ *
2025 * Some notes on parameter order:
2126 *
2227 * - We pass the `obj` pointer as `this`-like pointer first to the callbacks.
@@ -66,7 +71,9 @@ uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj, const Logger
6671/** @brief Pack an object into a buffer of a given size.
6772 *
6873 * This function creates and initialises a `Bin_Pack` packer object, calls the callback with the
69- * packer object and the to-be-packed object, and then cleans up the packer object.
74+ * packer object and the to-be-packed object, and then cleans up the packer object. Note that
75+ * there is nothing MessagePack-specific about this function, so it can be used for both custom
76+ * binary and MessagePack formats.
7077 *
7178 * You can use `bin_pack_obj_size` to determine the minimum required size of `buf`. If packing
7279 * overflows `uint32_t`, this function returns `false`.
@@ -102,13 +109,8 @@ uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr,
102109
103110/** @brief Pack an object array into a buffer of a given size.
104111 *
105- * Calls the callback `arr_size` times with increasing `index` argument from 0 to
106- * `arr_size`. This function is here just so we don't need to write the same
107- * trivial loop many times and so we don't need an extra struct just to contain
108- * an array with size so it can be passed to `bin_pack_obj`.
109- *
110- * Similar to `bin_pack_obj` but for arrays. Does not write the array length, so
111- * if you need that, write it manually using `bin_pack_array`.
112+ * Similar to `bin_pack_obj_array` but does not write the array length, so
113+ * if you need that, encoding it is on you.
112114 *
113115 * Passing NULL for `arr` has no effect, but requires that `arr_size` is 0.
114116 *
@@ -125,6 +127,32 @@ uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr,
125127non_null (1 , 5 ) nullable (2 , 4 )
126128bool bin_pack_obj_array_b (bin_pack_array_cb * callback , const void * arr , uint32_t arr_size , const Logger * logger , uint8_t * buf , uint32_t buf_size );
127129
130+ /** @brief Encode an object array as MessagePack array into a bin packer.
131+ *
132+ * Calls the callback `arr_size` times with increasing `index` argument from 0 to
133+ * `arr_size`. This function is here just so we don't need to write the same
134+ * trivial loop many times and so we don't need an extra struct just to contain
135+ * an array with size so it can be passed to `bin_pack_obj`.
136+ *
137+ * Similar to `bin_pack_obj` but for arrays. Note that a `Bin_Pack` object is
138+ * required here, so it must be called from within a callback to one of the
139+ * functions above.
140+ *
141+ * Passing NULL for `arr` requires that `arr_size` is 0. This will write a 0-size
142+ * MessagePack array to the packer.
143+ *
144+ * @param bp Bin packer object.
145+ * @param callback The function called on the created packer and packed object
146+ * array.
147+ * @param arr The object array to be packed, passed as `arr` to the callback.
148+ * @param arr_size The number of elements in the object array.
149+ * @param logger Optional logger object to pass to the callback.
150+ *
151+ * @retval false if an error occurred (e.g. buffer overflow).
152+ */
153+ non_null (1 , 2 ) nullable (3 , 5 )
154+ bool bin_pack_obj_array (Bin_Pack * bp , bin_pack_array_cb * callback , const void * arr , uint32_t arr_size , const Logger * logger );
155+
128156/** @brief Start packing a MessagePack array.
129157 *
130158 * A call to this function must be followed by exactly `size` calls to other functions below.
0 commit comments