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

Cursor byte-copy helpers shared by the frame codecs. More...

Go to the source code of this file.

Functions

static int bytes_put (wired_mspan buf, usz *off, wired_span src)
 Append src into buf at *off.
static int bytes_take (wired_span buf, usz *off, wired_mspan dst)
 Copy dst.n bytes into dst from *off (buf total).
static void * bytes_memcpy (void *dst, const void *src, usz n)
 Freestanding byte copy.
static void * bytes_move_down (void *dst, const void *src, usz n)
 Byte copy toward lower addresses: dst may overlap src as long as dst <= src (a forward copy then never reads a byte it already overwrote), e.g.
static void * bytes_memset (void *dst, int c, usz n)
 Freestanding byte fill.
static usz wired_cstr_len (const char *s)
 Freestanding NUL-terminated string length.
static u8 ascii_lower (u8 c)
 ASCII lowercase of one octet (A-Z -> a-z, everything else unchanged).
static int ascii_dns_eq (wired_span a, wired_span b)
 RFC 6125 6.4.1: ASCII case-insensitive equality of two DNS-name-shaped byte spans (host names, SNI values).

Detailed Description

Cursor byte-copy helpers shared by the frame codecs.

Inline so multiple codec translation units can use them without redefining a static helper.

Function Documentation

◆ ascii_dns_eq()

int ascii_dns_eq ( wired_span a,
wired_span b )
inlinestatic

RFC 6125 6.4.1: ASCII case-insensitive equality of two DNS-name-shaped byte spans (host names, SNI values).

Non-ASCII bytes compare bytewise (no folding applied outside A-Z).

Parameters
afirst span
bsecond span
Returns
1 if equal length and equal after ASCII case-folding, 0 otherwise.

◆ ascii_lower()

u8 ascii_lower ( u8 c)
inlinestatic

ASCII lowercase of one octet (A-Z -> a-z, everything else unchanged).

Parameters
cinput octet
Returns
lowercased octet

◆ bytes_memcpy()

void * bytes_memcpy ( void * dst,
const void * src,
usz n )
inlinestatic

Freestanding byte copy.

Even under -ffreestanding -fno-builtin the compiler still emits memcpy/memset calls for struct and array copies/zeroing (e.g. modexp.c, ed25519_sign.c, respond.c), and with -nostdlib no libc supplies them. The SDK owns these primitives; each freestanding binary's mandatory libc-named memcpy/memset shim (the symbol names the compiler hard-codes) just forwards to these.

Parameters
dstdestination buffer (must not overlap src)
srcsource buffer
nnumber of bytes to copy
Returns
dst

◆ bytes_memset()

void * bytes_memset ( void * dst,
int c,
usz n )
inlinestatic

Freestanding byte fill.

See bytes_memcpy() for why the SDK owns this.

Parameters
dstbuffer to fill
cfill byte (truncated to u8)
nnumber of bytes to fill
Returns
dst

◆ bytes_move_down()

void * bytes_move_down ( void * dst,
const void * src,
usz n )
inlinestatic

Byte copy toward lower addresses: dst may overlap src as long as dst <= src (a forward copy then never reads a byte it already overwrote), e.g.

sliding a buffer's tail down to its front.

The loop is the same as bytes_memcpy's today, but only this contract promises forward order: bytes_memcpy stays free to copy in any order.

Parameters
dstdestination, at or below src
srcsource buffer
nnumber of bytes to copy
Returns
dst

◆ bytes_put()

int bytes_put ( wired_mspan buf,
usz * off,
wired_span src )
inlinestatic

Append src into buf at *off.

Both buf and src are borrowed views: no ownership transfers and nothing is copied into new storage, so buf and src must stay alive (and unmoved) only for the duration of this call.

Parameters
bufdestination buffer (its .n is the total capacity)
offwrite cursor into buf; advanced by src.n on success
srcbytes to append
Returns
1 ok, 0 if no room.

◆ bytes_take()

int bytes_take ( wired_span buf,
usz * off,
wired_mspan dst )
inlinestatic

Copy dst.n bytes into dst from *off (buf total).

Both buf and dst are borrowed views: no ownership transfers, and each must stay alive (and unmoved) only for the duration of this call.

Parameters
bufsource buffer to read from
offread cursor into buf; advanced by dst.n on success
dstdestination; exactly dst.n bytes are copied
Returns
1 ok, 0 if truncated.

◆ wired_cstr_len()

usz wired_cstr_len ( const char * s)
inlinestatic

Freestanding NUL-terminated string length.

src/ has no libc strlen.

Parameters
sNUL-terminated string
Returns
number of bytes before the terminating NUL