ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
bitio.h File Reference

LSB-first bit writer over a caller-owned byte buffer - one source of truth. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  pc_bit_writer
 LSB-first bit writer over the caller's output buffer; overflow latches once cap is exceeded. More...
 

Functions

void pc_bitw_put (pc_bit_writer *w, uint32_t bits, int n)
 Append the low n bits of bits, LSB-first, spilling any completed bytes to the output.
 
void pc_bitw_align (pc_bit_writer *w)
 Flush any partial byte, padding the high bits with zero (byte alignment).
 

Detailed Description

LSB-first bit writer over a caller-owned byte buffer - one source of truth.

The DEFLATE encoder (network_drivers/presentation/codec/deflate) and the SSH zlib@.nosp@m.open.nosp@m.ssh.c.nosp@m.om stream compressor (ssh/transport/ssh_zlib) each carried a byte-for-byte copy of the same bit writer: pack bits LSB-first into a uint32_t accumulator, spill whole bytes to the output, and latch overflow when the buffer is full. It lives here once.

NOTE: distinct from bytes.h's pc_bw_* helpers, which are a BYTE-oriented (big-endian) codec cursor. This is a BIT writer (pc_bitw_*), for the DEFLATE bitstream. Header-only, pure (only <stdint.h> / <stddef.h>), zero link cost when unused.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file bitio.h.

Function Documentation

◆ pc_bitw_put()

void pc_bitw_put ( pc_bit_writer w,
uint32_t  bits,
int  n 
)
inline

Append the low n bits of bits, LSB-first, spilling any completed bytes to the output.

Definition at line 39 of file bitio.h.

References pc_bit_writer::acc, pc_bit_writer::cap, pc_bit_writer::cnt, pc_bit_writer::nbits, pc_bit_writer::out, and pc_bit_writer::overflow.

◆ pc_bitw_align()

void pc_bitw_align ( pc_bit_writer w)
inline

Flush any partial byte, padding the high bits with zero (byte alignment).

Definition at line 57 of file bitio.h.

References pc_bit_writer::acc, pc_bit_writer::cap, pc_bit_writer::cnt, pc_bit_writer::nbits, pc_bit_writer::out, and pc_bit_writer::overflow.