ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
quic_varint.h File Reference

QUIC variable-length integer coding (RFC 9000 sec 16). More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  QuicVarintNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define QUIC_VARINT_MAX   0x3FFFFFFFFFFFFFFFull
 Largest value a QUIC varint can hold (2^62 - 1).
 

Functions

 PROTOCORE_NS_LAYOUT (QuicVarintNs, len, encode, decode)
 
size_t protocore_quic_varint_len (uint8_t *work, uint64_t value)
 Bytes value encodes to (1 / 2 / 4 / 8), or 0 if it exceeds .
 
size_t protocore_quic_varint_encode (uint8_t *work, uint8_t *out, size_t cap, uint64_t value)
 Encode value in its shortest form. bytes written, or 0 on overflow .
 
proto_bool protocore_quic_varint_decode (uint8_t *work, const uint8_t *in, size_t len, uint64_t *value, size_t *consumed)
 Decode a varint at in. Sets value and consumed (1/2/4/8). false if .
 

Variables

PROTOCORE_NS QuicVarintNs QuicVarint PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

QUIC variable-length integer coding (RFC 9000 sec 16).

QUIC, HTTP/3 (RFC 9114), and QPACK (RFC 9204) encode most lengths and identifiers as a variable-length integer: the two most-significant bits of the first byte give the total length (00 -> 1 byte / 6-bit value, 01 -> 2 / 14-bit, 10 -> 4 / 30-bit, 11 -> 8 / 62-bit), and the remaining bits hold the value big-endian. The representable range is 0 .. 2^62-1.

This is the foundational primitive of the HTTP/3 stack. Pure and host-tested.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file quic_varint.h.

Macro Definition Documentation

◆ QUIC_VARINT_MAX

#define QUIC_VARINT_MAX   0x3FFFFFFFFFFFFFFFull

Largest value a QUIC varint can hold (2^62 - 1).

Definition at line 35 of file quic_varint.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( QuicVarintNs  ,
len  ,
encode  ,
decode   
)

◆ protocore_quic_varint_len()

size_t protocore_quic_varint_len ( uint8_t *  work,
uint64_t  value 
)

Bytes value encodes to (1 / 2 / 4 / 8), or 0 if it exceeds .

Parameters
workPROTOCORE_QUIC_VARINT_BORROW bytes the caller took. Not held past the call.
valueValue
Returns
The size_t.

◆ protocore_quic_varint_encode()

size_t protocore_quic_varint_encode ( uint8_t *  work,
uint8_t *  out,
size_t  cap,
uint64_t  value 
)

Encode value in its shortest form. bytes written, or 0 on overflow .

Parameters
workPROTOCORE_QUIC_VARINT_BORROW bytes the caller took. Not held past the call.
outOut
capCap
valueValue
Returns
The size_t.

◆ protocore_quic_varint_decode()

proto_bool protocore_quic_varint_decode ( uint8_t *  work,
const uint8_t *  in,
size_t  len,
uint64_t *  value,
size_t *  consumed 
)

Decode a varint at in. Sets value and consumed (1/2/4/8). false if .

Parameters
workPROTOCORE_QUIC_VARINT_BORROW bytes the caller took. Not held past the call.
inIn
lenLen
valueValue
consumedConsumed
Returns
PROTO_TRUE on success.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS QuicVarintNs QuicVarint PROTOCORE_UNUSED
Initial value:
= {
size_t protocore_quic_varint_len(uint8_t *work, uint64_t value)
Bytes value encodes to (1 / 2 / 4 / 8), or 0 if it exceeds .
proto_bool protocore_quic_varint_decode(uint8_t *work, const uint8_t *in, size_t len, uint64_t *value, size_t *consumed)
Decode a varint at in. Sets value and consumed (1/2/4/8). false if .
size_t protocore_quic_varint_encode(uint8_t *work, uint8_t *out, size_t cap, uint64_t value)
Encode value in its shortest form. bytes written, or 0 on overflow .

Module namespace.

Definition at line 75 of file quic_varint.h.