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  wired_span
 Read-only view of a byte range. More...
struct  wired_mspan
 Mutable view of a byte range. More...
struct  wired_obuf
 Growing output buffer view for variable-length results. More...

Functions

static wired_span wired_span_of (const u8 *p, usz n)
 Make a read-only span over p[0..n).
static wired_mspan wired_mspan_of (u8 *p, usz n)
 Make a mutable span over p[0..n).
static wired_obuf 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) -> wired_span (by value: 16 bytes, two (u8 *p, usz n) -> wired_mspan registers under SysV, the same as the loose pair) (u8 *out, usz cap, usz *out_len)-> wired_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 wired_span_of / wired_mspan_of / obuf_of constructors below.

Function Documentation

◆ obuf_of()

wired_obuf 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: wired_obuf ob = obuf_of(buf, sizeof buf); ... use ob.len.

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

◆ wired_mspan_of()

wired_mspan wired_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: wired_mspan out = wired_mspan_of(key, sizeof key);

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

◆ wired_span_of()

wired_span wired_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: wired_span msg = wired_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