@@ -242,41 +242,56 @@ static const bool CHANNEL_BIT_UPDATE_CHANNEL_ERROR = true;
242
242
#include < ostream>
243
243
#include < new>
244
244
245
+ // / A struct to facilitate transferring a `Vec<u8>` across FFI boundaries.
245
246
struct CVec {
246
247
uint8_t *data;
247
248
uintptr_t len;
248
249
uintptr_t capacity;
249
250
};
250
251
252
+ // / A struct to manage a collection of `CVec` objects across FFI boundaries.
251
253
struct CVec2 {
252
254
CVec *data;
253
255
uintptr_t len;
254
256
uintptr_t capacity;
255
257
};
256
258
259
+ // / Represents a 24-bit unsigned integer (`U24`), supporting SV2 serialization and deserialization.
260
+ // / Only first 3 bytes of a u32 is considered to get the SV2 value, and rest are ignored (in little
261
+ // / endian).
257
262
struct U24 {
258
263
uint32_t _0;
259
264
};
260
265
261
266
extern " C" {
262
267
263
- // / Given a C allocated buffer return a rust allocated CVec
268
+ // / Creates a `CVec` from a buffer that was allocated in C.
264
269
// /
265
270
// / # Safety
271
+ // / The caller must ensure that the buffer is valid and that
272
+ // / the data length does not exceed the allocated size.
266
273
CVec cvec_from_buffer (const uint8_t *data, uintptr_t len);
267
274
275
+ // / Initializes an empty `CVec2`.
276
+ // /
268
277
// / # Safety
278
+ // / The caller is responsible for freeing the `CVec2` when it is no longer needed.
269
279
CVec2 init_cvec2 ();
270
280
271
- // / The caller is reponsible for NOT adding duplicate cvecs to the cvec2 structure,
272
- // / as this can lead to double free errors when the message is dropped.
281
+ // / Adds a `CVec` to a `CVec2`.
282
+ // /
273
283
// / # Safety
284
+ // / The caller must ensure no duplicate `CVec`s are added, as duplicates may
285
+ // / lead to double-free errors when the message is dropped.
274
286
void cvec2_push (CVec2 *cvec2, CVec cvec);
275
287
288
+ // / Exported FFI functions for interoperability with C code for u24
276
289
void _c_export_u24 (U24 _a);
277
290
291
+ // / Exported FFI functions for interoperability with C code for CVec
278
292
void _c_export_cvec (CVec _a);
279
293
294
+ // / Exported FFI functions for interoperability with C code for CVec2
280
295
void _c_export_cvec2 (CVec2 _a);
281
296
282
297
} // extern "C"
0 commit comments