13 functions · signatures checked against lib/xtp2.h · fuzzed with libFuzzer
xtp2 Extension Reference
A binary application-layer protocol frame library over ordered byte streams: built in by build.bat xtp, a 32-byte header, four message types (REQUEST / RESPONSE / PUSH / EVENT), streaming incremental parsing, and a complete limits system. Two inline helpers (xtp2_text / xtp2_wants_reply) stay in the header for the script side to inline.
The wire format at a glance
xtp2 frame layout (big-endian)
┌──────────────────────────────────────────────┐
│ magic "xtp\2" 4B fixed tag + version │
│ total u32 whole-frame length │
│ id u64 message ID (request-response correlation) │
│ flags / type / command / params u16 each │
│ body u32 body length │
├──────────────────────────────────────────────┤
│ [key:u16 value:u16] × params length table │
│ command data · parameter data · body │
└──────────────────────────────────────────────┘
type: REQUEST / RESPONSE / PUSH / EVENT · a request with id==0 needs no reply
Default limits: whole frame ≤1MiB, ≤256 parameters, command/key/value lengths each capped — all tighten-able in xtp2_config (see below). Parse errors are sticky: after an error, no further messages are produced until xtp2_reset.
Create & configure (3)
xtp2_config_init config
Initialize the configuration to defaults (all default limits + the default allocator).
void xtp2_config_init(xtp2_config *config);
Constraint: max_packet ∈ [32, UINT32_MAX]; the other limits must fit the wire
An invalid configuration (e.g. max_packet too small) returns E_ARGUMENT at create time — tightened limits never fail silently.
xtp2_create / xtp2_destroy lifecycle
Create / destroy a processor. Pass a NULL config for defaults.
Returns: XTP2_MORE (need data) / XTP2_MESSAGE (produced) / negative (sticky error)Message: value-semantics out-param; use it in the callback/loop, then discard
Official usage (verbatim from lib/xtp2.h)source signatures
xtp2_processor *rx;
if ( xtp2_create(NULL, &rx) != XTP2_OK ) { ... }
while ( size ) {
size_t iUsed;
xtp2_message msg;
xtp2_result r = xtp2_feed(rx, bytes, size, &iUsed, &msg);
bytes += iUsed; size -= iUsed;
if ( r < 0 ) break; /* sticky error */if ( r == XTP2_MESSAGE ) { ... } /* use/copy msg, then continue */if ( r == XTP2_MORE ) break; /* wait for the next round of data */
}
xtp2_finish parse
End-of-stream check: at EOF with a partial frame pending, it returns an error (never a silent drop).