MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
bitorum_introitus_exitus — bit writer

Data Structures

struct  mmgr_bitor
 Bit writer state: the buffer, how much went out, and the partial byte. More...
struct  BitorumCfg
 Arguments for the bitor calls, where each call reads only the members it needs. More...
struct  BitorumIntroitusExitusNs
 Type of the bitio dispatch table. More...

Functions

EMBED_HOST_DEVICE mmgr_bitor mmgr_bitor_init (const BitorumCfg *args)
 Builds a bit writer over args->out with capacity args->cap.
EMBED_HOST_DEVICE void mmgr_bitor_put (const BitorumCfg *args)
 Appends the low args->bit_count bits of args->val to args->writer.
EMBED_HOST_DEVICE void mmgr_bitor_align (const BitorumCfg *args)
 Writes the partial byte the writer still holds, padded with zeros above its bits.

Variables

static const BitorumIntroitusExitusNs bitio
 Dispatch table instance named bitio, with each member set to its mmgr_bitor_ function.

Detailed Description

Function Documentation

◆ mmgr_bitor_init()

EMBED_HOST_DEVICE mmgr_bitor mmgr_bitor_init ( const BitorumCfg * args)

Builds a bit writer over args->out with capacity args->cap.

Parameters
[in]argsBuffer and capacity [BORROWS].
Returns
A writer with no bytes written and no residue.
Note
The returned writer retains args->out, which must outlive it [BORROWS].
Warning
args->out must not be null and args->cap must not be zero. Neither has a check outside a MMGR_DEBUG_CHECKS build, and a null out passes here. mmgr_bitor_put writes through it on the first whole byte.

References mmgr_bitor_init().

Referenced by mmgr_bitor_init().

◆ mmgr_bitor_put()

EMBED_HOST_DEVICE void mmgr_bitor_put ( const BitorumCfg * args)

Appends the low args->bit_count bits of args->val to args->writer.

Parameters
[in,out]argsWriter, value and bit count [BORROWS].
Note
Writes whole bytes only. Leftover bits stay in the writer's residue.
Does nothing when the writer's overflow is already set. A caller may write a whole stream and test overflow once at the end and not after every call.
Sets the writer's overflow and clears its residue when the bytes would pass its cap.
Warning
args->bit_count must not exceed 64, and nothing holds it there outside a MMGR_DEBUG_CHECKS build. A larger count writes zeros past the sixty-fourth bit and advances the writer as though they were data.

References mmgr_bitor_put().

Referenced by mmgr_bitor_put().

◆ mmgr_bitor_align()

EMBED_HOST_DEVICE void mmgr_bitor_align ( const BitorumCfg * args)

Writes the partial byte the writer still holds, padded with zeros above its bits.

Parameters
[in,out]argsWriter to finish [BORROWS].
Note
mmgr_bitor_put writes whole bytes only. Without this call the residue is never written.
Does nothing when the residue is empty. A second call writes nothing.
Does nothing when the writer's overflow is already set.
It reads only args->writer.
Warning
Sets the writer's overflow when the byte would pass its cap.

References mmgr_bitor_align().

Referenced by mmgr_bitor_align().

Variable Documentation

◆ bitio

const BitorumIntroitusExitusNs bitio
static

Dispatch table instance named bitio, with each member set to its mmgr_bitor_ function.

Definition at line 120 of file bitorum_introitus_exitus.h.