Expand description
Binary command buffer parser and mutation applicator.
Reads a command buffer produced by the JS CommandBuffer class, converts
commands into arena mutations, and returns the rebuilt arena.
§Wire format
All multi-byte integers are little-endian.
Commands (first byte): 0x01 REMOVE [nodeId: u32] 0x05 INSERT_BEFORE [nodeId: u32][payloadType: u8][payload…] 0x06 INSERT_AFTER [nodeId: u32][payloadType: u8][payload…] 0x07 PREPEND_CHILD [nodeId: u32][payloadType: u8][payload…] 0x08 APPEND_CHILD [nodeId: u32][payloadType: u8][payload…] 0x09 WRAP [nodeId: u32][payloadType: u8][payload…] 0x0B REPLACE [nodeId: u32][payloadType: u8][payload…] 0x0C SET_PROPERTY [nodeId: u32][valueType: u8][nameLen: u32][name…][valueLen: u32][value…] 0x0D SET_CHILDREN [nodeId: u32][payloadType: u8][payload…] (payload is a Root-wrapped child list)
Value types for SET_PROPERTY: 0 STRING : UTF-8 value 1 BOOL_TRUE : no value bytes 2 BOOL_FALSE : no value bytes 3 SPACE_SEP : space-separated list (UTF-8) 4 INT : value is decimal string, parsed to i64 5 NULL : no value bytes
Payload types: 0x10 RAW_MARKDOWN [len: u32][utf8…] 0x11 RAW_HTML [len: u32][utf8…] 0x12 SERDE_JSON [len: u32][utf8…]
The MDAST and HAST command paths are deliberately separate functions
(apply_mdast_commands, apply_hast_commands). Numeric node_type
values overlap between the two arenas (e.g. mdast Paragraph=1 collides
with HastNodeType::Element=1), so a single dispatcher trying to handle
both kinds would silently misroute nodes. The phantom-typed Arena<K>
signature on each entry point makes a cross-kind call a compile error.
Functions§
- apply_
hast_ commands - Apply a command buffer to a HAST arena. Set-property mutations are
applied in-place; structural mutations are collected as
Patch<Hast>objects and applied viarebuild(). Errors if a patch is stranded inside a removed/replaced subtree;apply_hast_commands_lenientdrops it instead. - apply_
hast_ commands_ lenient - Like
apply_hast_commands, but rather than erroring when a patch targets a node inside a removed/replaced subtree, drops it and returns the dropped anchors — mirroringapply_mdast_commands_lenient. Such a patch is moot: the plugin discarded that subtree. A passed-through child keeps its identity (via_ref) and so is never stranded this way. - apply_
mdast_ commands - Apply a command buffer to an MDAST arena. Set-property mutations are
applied in-place; structural mutations are collected as
Patch<Mdast>objects and applied viarebuild(). - apply_
mdast_ commands_ lenient - Like
apply_mdast_commands, but rather than erroring when a patch targets a node inside a removed/replaced subtree, drops it and returns the dropped anchors. Such a patch is moot — the plugin discarded that subtree. A passed-through child is not dropped: it rides a_refplaceholder that splices it back with its id intact, so a transform queued on a nested node (e.g. a:::tipinside a:::note) still applies, in the same pass.