wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
span.h File Reference

Value-type views that fold the SDK's recurring argument shapes into single parameters, keeping every function at <=3 args without a calling cost: More...

Go to the source code of this file.

Data Structures

struct  quic_span
 Read-only view of a byte range. More...
struct  quic_mspan
 Mutable view of a byte range. More...
struct  quic_obuf
 Growing output buffer view for variable-length results. More...

Functions

static quic_span quic_span_of (const u8 *p, usz n)
 Make a read-only span over p[0..n).
static quic_mspan quic_mspan_of (u8 *p, usz n)
 Make a mutable span over p[0..n).
static quic_obuf quic_obuf_of (u8 *p, usz cap)
 Make an output buffer over p[0..cap) with len starting at 0.

Detailed Description

Value-type views that fold the SDK's recurring argument shapes into single parameters, keeping every function at <=3 args without a calling cost:

(const u8 *p, usz n) -> quic_span (by value: 16 bytes, two (u8 *p, usz n) -> quic_mspan registers under SysV, the same as the loose pair) (u8 *out, usz cap, usz *out_len)-> quic_obuf * (one register instead of three; callee fills .len)

These are views, not owners: a span never copies and never frees. The caller's buffer must stay alive for as long as the span (or anything the span was handed to) is in use. Build them with the quic_span_of / quic_mspan_of / quic_obuf_of constructors below.

Function Documentation

◆ quic_mspan_of()

quic_mspan quic_mspan_of ( u8 * p,
usz n )
inlinestatic

Make a mutable span over p[0..n).

The span borrows p; the buffer must outlive every use of the returned value. Example: quic_mspan out = quic_mspan_of(key, sizeof key);

Parameters
pfirst byte of the writable range
nnumber of writable bytes
Returns
the view as a value type

◆ quic_obuf_of()

quic_obuf quic_obuf_of ( u8 * p,
usz cap )
inlinestatic

Make an output buffer over p[0..cap) with len starting at 0.

The buffer borrows p; the storage must outlive every use of the returned value. Pass its address to the producing call and read .len afterwards: quic_obuf ob = quic_obuf_of(buf, sizeof buf); ... use ob.len.

Parameters
pcaller-provided storage
capcapacity of p in bytes
Returns
the buffer view with len = 0

◆ quic_span_of()

quic_span quic_span_of ( const u8 * p,
usz n )
inlinestatic

Make a read-only span over p[0..n).

The span borrows p; the buffer must outlive every use of the returned value. Example: quic_span msg = quic_span_of(buf, buf_len);

Parameters
pfirst byte of the range (may be 0 when n is 0)
nnumber of readable bytes
Returns
the view as a value type