|
YAPB
|
A minimal, zero-allocation binary serialization library in C.
Every YAPB packet has a simple wire format:
| Tag | Type | Value Size |
|---|---|---|
| 0x00 | INT8 | 1 byte |
| 0x01 | INT16 | 2 bytes |
| 0x02 | INT32 | 4 bytes |
| 0x03 | INT64 | 8 bytes |
| 0x04 | FLOAT | 4 bytes |
| 0x05 | DOUBLE | 8 bytes |
| 0x0E | BLOB | 2-byte length + N raw bytes |
| 0x0F | NESTED_PKT | full nested packet (with its own 4-byte header) |
Tags 0x06-0x0D are reserved for future types.
YAPB uses sticky errors (like errno or OpenGL). Once an error occurs, all subsequent push/pop calls return that same error immediately. This means you can chain operations and check once at the end:
Pop functions do NOT modify the output on error. Initialize fields to defaults before popping - if the packet lacks that field, the default is preserved because the pop returns an error (e.g. YAPB_ERR_NO_MORE_ELEMENTS):
| Function | Description |
|---|---|
| YAPB_initialize(*out, *in_buf, in_size) | Init packet for writing |
| YAPB_finalize(*in, *out_len) | Write header, get total length |
| YAPB_load(*out, *in_data, in_size) | Load raw data for reading |
| Function | Description |
|---|---|
| YAPB_push_i8/i16/i32/i64(*in, *in_val) | Push signed integer |
| YAPB_push_u8/u16/u32/u64(*in, *in_val) | Push unsigned integer (inline wrappers) |
| YAPB_push_float/double(*in, *in_val) | Push floating point |
| YAPB_push_blob(*in, *in_data, in_len) | Push raw bytes (max 65535) |
| YAPB_push_nested(*in, *in_nested) | Push a finalized packet inside another |
| Function | Description |
|---|---|
| YAPB_pop_i8/i16/i32/i64(*in, *out) | Pop signed integer |
| YAPB_pop_u8/u16/u32/u64(*in, *out) | Pop unsigned integer (inline wrappers) |
| YAPB_pop_float/double(*in, *out) | Pop floating point |
| YAPB_pop_blob(*in, *out_data, *out_len) | Pop blob (pointer into packet buffer) |
| YAPB_pop_nested(*in, *out) | Pop nested packet |
| YAPB_pop_next(*in, *out) | Pop next element with type tag (for dynamic parsing) |
| Function | Description |
|---|---|
| YAPB_get_error(*in) | Get sticky error state |
| YAPB_get_elem_count(*in, *out_count) | Count elements without advancing position |
| YAPB_get_buffer(*in) | Get const pointer to packet buffer |
| YAPB_check_complete(*in_data, in_len) | Check if buffer contains a complete packet |
| YAPB_Result_str(in_result) | Get string name for result code |