wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
varint.h
1#ifndef VARINT_H
2#define VARINT_H
3
6
7/* RFC 9000 16. Variable-length integer encoding.
8 * 2-bit prefix in MSB of first byte selects length 1/2/4/8. */
9
10#define VARINT_MAX 0x3FFFFFFFFFFFFFFFULL
11
12/* Bytes needed to encode v. Returns 0 if v exceeds the 62-bit range. */
13usz varint_len(u64 v);
14
15/* Encode v into buf (must hold varint_len(v) bytes).
16 * Returns bytes written, or 0 if v out of range. */
17usz varint_encode(u8* buf, u64 v);
18
19/* Decode from buf of n readable bytes into *out.
20 * Returns bytes consumed, or 0 if n too small for the encoded length. */
21usz varint_decode(const u8* buf, usz n, u64* out);
22
23/* Cursor helpers shared by TLV codecs (frames, transport params). Each
24 * decodes/encodes one varint at buf+*off and advances *off on success. */
25
26/* Returns 1 ok, 0 if truncated. */
27int varint_take(wired_span buf, usz* off, u64* out);
28
29/* Returns 1 ok, 0 if out of range or no room within cap. */
30int varint_put(wired_mspan buf, usz* off, u64 v);
31
32#endif
Value-type views that fold the SDK's recurring argument shapes into single parameters,...
Mutable view of a byte range.
Definition span.h:42
Read-only view of a byte range.
Definition span.h:30
Linux direct syscalls.
u64 usz
unsigned size (size_t equivalent)
Definition types.h:20
unsigned char u8
unsigned 8-bit integer / byte
Definition types.h:18
unsigned long u64
unsigned 64-bit integer
Definition types.h:13