Skip to content

Commit 8bf2780

Browse files
plebhashShourya742
authored andcommitted
update sv2.h for binary_sv2 docs
1 parent bdb30b5 commit 8bf2780

File tree

1 file changed

+18
-3
lines changed
  • protocols/v2/sv2-ffi

1 file changed

+18
-3
lines changed

protocols/v2/sv2-ffi/sv2.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -242,41 +242,56 @@ static const bool CHANNEL_BIT_UPDATE_CHANNEL_ERROR = true;
242242
#include <ostream>
243243
#include <new>
244244

245+
/// A struct to facilitate transferring a `Vec<u8>` across FFI boundaries.
245246
struct CVec {
246247
uint8_t *data;
247248
uintptr_t len;
248249
uintptr_t capacity;
249250
};
250251

252+
/// A struct to manage a collection of `CVec` objects across FFI boundaries.
251253
struct CVec2 {
252254
CVec *data;
253255
uintptr_t len;
254256
uintptr_t capacity;
255257
};
256258

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).
257262
struct U24 {
258263
uint32_t _0;
259264
};
260265

261266
extern "C" {
262267

263-
/// Given a C allocated buffer return a rust allocated CVec
268+
/// Creates a `CVec` from a buffer that was allocated in C.
264269
///
265270
/// # Safety
271+
/// The caller must ensure that the buffer is valid and that
272+
/// the data length does not exceed the allocated size.
266273
CVec cvec_from_buffer(const uint8_t *data, uintptr_t len);
267274

275+
/// Initializes an empty `CVec2`.
276+
///
268277
/// # Safety
278+
/// The caller is responsible for freeing the `CVec2` when it is no longer needed.
269279
CVec2 init_cvec2();
270280

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+
///
273283
/// # 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.
274286
void cvec2_push(CVec2 *cvec2, CVec cvec);
275287

288+
/// Exported FFI functions for interoperability with C code for u24
276289
void _c_export_u24(U24 _a);
277290

291+
/// Exported FFI functions for interoperability with C code for CVec
278292
void _c_export_cvec(CVec _a);
279293

294+
/// Exported FFI functions for interoperability with C code for CVec2
280295
void _c_export_cvec2(CVec2 _a);
281296

282297
} // extern "C"

0 commit comments

Comments
 (0)