Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_msgpack.c File Reference
#include "vl_msgpack.h"
#include <string.h>
+ Include dependency graph for vl_msgpack.c:

Macros

#define VL_MSGPACK_MAX_STACK_KEY_SIZE   512
 Maximum hierarchical key size to allocate on stack.
 

Functions

vl_hash vl_HashMsgPackKey (const void *data, vl_memsize_t size)
 
void vl_MsgPackFreeChildren (vl_msgpack *pack, vl_msgpack_iter iter)
 
vl_msgpack_iter vlMsgPackInsert (vl_msgpack *pack, vl_msgpack_type type, vl_msgpack_iter parent, const void *keyPtr, vl_memsize_t keyLen, const void *dataPtr, vl_memsize_t dataLen)
 
vl_msgpack_element * vl_MsgPackInitNode (vl_msgpack *pack, vl_msgpack_iter nodeIter, vl_msgpack_type type, vl_int8_t extType, vl_msgpack_iter parent, const void *dataPtr, vl_memsize_t dataLen)
 
void vlMsgPackInit (vl_msgpack *pack)
 Initializes the specified MessagePack DOM.
 
void vlMsgPackFree (vl_msgpack *pack)
 Frees the specified MessagePack DOM.
 
vl_msgpackvlMsgPackNew (void)
 Allocates and initializes a MessagePack DOM.
 
void vlMsgPackDelete (vl_msgpack *pack)
 Deletes the specified MessagePack DOM.
 
void vlMsgPackClear (vl_msgpack *pack)
 Clears the MessagePack DOM, resetting it for reuse.
 
vl_msgpackvlMsgPackClone (vl_msgpack *src, vl_msgpack *dest)
 Clones the specified MessagePack DOM to another.
 
vl_msgpack_iter vlMsgPackParent (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the parent node of a given node in the MessagePack DOM.
 
vl_dsidx_t vlMsgPackTotalChildren (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the total number of children of a given node.
 
vl_msgpack_iter vlMsgPackFirstChild (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the first child of a given node.
 
vl_msgpack_iter vlMsgPackNextSibling (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the next sibling of a given node.
 
vl_msgpack_iter vlMsgPackPrevSibling (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the previous sibling of a given node.
 
vl_msgpack_type vlMsgPackType (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the type of a given node in the MessagePack DOM.
 
vl_int8_t vlMsgPackExtType (vl_msgpack *pack, vl_msgpack_iter iter)
 Retrieves the extension type of a MessagePack EXT node.
 
vl_msgpack_iter vlMsgPackInsertExt (vl_msgpack *pack, vl_msgpack_type type, vl_int8_t extType, vl_msgpack_iter parent, const void *keyPtr, vl_memsize_t keyLen, const void *dataPtr, vl_memsize_t dataLen)
 Inserts a new element into the MessagePack DOM with an extended type.
 
void vlMsgPackRemove (vl_msgpack *pack, vl_msgpack_iter iter)
 Removes an element from the MessagePack DOM.
 
vl_msgpack_iter vlMsgPackFindChild (vl_msgpack *pack, vl_msgpack_iter parent, const void *keyPtr, vl_memsize_t keyLen)
 Finds a child element by key.
 
vl_msgpack_iter vlMsgPackFindChildIndexed (vl_msgpack *pack, vl_msgpack_iter parent, vl_dsidx_t index)
 Finds a child element by index.
 
const vl_transientvlMsgPackSampleKey (vl_msgpack *pack, vl_msgpack_iter iter, vl_memsize_t *size)
 Retrieves the key associated with an element.
 
vl_transientvlMsgPackSampleValue (vl_msgpack *pack, vl_msgpack_iter iter, vl_memsize_t *size)
 Retrieves the value associated with an element.
 

Macro Definition Documentation

◆ VL_MSGPACK_MAX_STACK_KEY_SIZE

#define VL_MSGPACK_MAX_STACK_KEY_SIZE   512

Maximum hierarchical key size to allocate on stack.

For msgpack, a typical key is: [parent_hash (8) + user_key (var)] Most JSON-like keys are < 256 bytes, so 512 provides safe margin. If keys are larger, consider increasing (stack space permits). If stack-constrained (embedded), decrease to 256.

Performance: Stack paths (~5-10 ns) vs Arena paths (~50-100 ns)

Function Documentation

◆ vl_HashMsgPackKey()

vl_hash vl_HashMsgPackKey ( const void *  data,
vl_memsize_t  size 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vl_MsgPackFreeChildren()

void vl_MsgPackFreeChildren ( vl_msgpack pack,
vl_msgpack_iter  iter 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vl_MsgPackInitNode()

vl_msgpack_element * vl_MsgPackInitNode ( vl_msgpack pack,
vl_msgpack_iter  nodeIter,
vl_msgpack_type  type,
vl_int8_t  extType,
vl_msgpack_iter  parent,
const void *  dataPtr,
vl_memsize_t  dataLen 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackClear()

void vlMsgPackClear ( vl_msgpack pack)

Clears the MessagePack DOM, resetting it for reuse.

This function resets the MessagePack DOM instance without deallocating memory. Previously allocated memory remains available for reuse, improving performance when repeatedly decoding into the same structure.

Parameters
packThe MessagePack DOM instance to clear.
+ Here is the call graph for this function:

◆ vlMsgPackClone()

vl_msgpack * vlMsgPackClone ( vl_msgpack src,
vl_msgpack dest 
)

Clones the specified MessagePack DOM to another.

Clones the entirety of the src MessagePack to the dest MessagePack.

The 'src' DOM must be non-null and initialized. The 'dest' DOM may be null, but if it is not null it must be initialized.

If the 'dest' table pointer is null, a new DOM is created via vlMsgPackNew.

See also
vlMsgPackNew
Parameters
srcsource DOM pointer
destdestination DOM pointer
Returns
pointer to the MessagePack that was copied to or created.
+ Here is the call graph for this function:

◆ vlMsgPackDelete()

void vlMsgPackDelete ( vl_msgpack pack)

Deletes the specified MessagePack DOM.

The specified MessagePack must have been initialized via vlMsgPackNew before calling this function.

Contract

  • Ownership: Releases ownership and all associated resources.
  • Lifetime: The pack pointer becomes invalid.
  • Thread Safety: Not thread-safe.
  • Nullability: Safe to call with NULL (due to internal free safety).
  • Error Conditions: None.
  • Undefined Behavior: Double deletion.
  • Memory Allocation Expectations: Frees all heap memory associated with the DOM.
  • Return-value Semantics: None (void).
See also
vlMsgPackNew
Parameters
packpointer to DOM
+ Here is the call graph for this function:

◆ vlMsgPackExtType()

vl_int8_t vlMsgPackExtType ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the extension type of a MessagePack EXT node.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
The extension type value, or an undefined result if the node is not an EXT type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackFindChild()

vl_msgpack_iter vlMsgPackFindChild ( vl_msgpack pack,
vl_msgpack_iter  parent,
const void *  key,
vl_memsize_t  keyLen 
)

Finds a child element by key.

This function searches for a child under the given parent node with a matching key.

Parameters
packThe MessagePack DOM instance.
parentThe parent node to search in.
keyPointer to the key data.
keyLenLength of the key.
Returns
An iterator to the matching child or an invalid iterator if not found.
+ Here is the call graph for this function:

◆ vlMsgPackFindChildIndexed()

vl_msgpack_iter vlMsgPackFindChildIndexed ( vl_msgpack pack,
vl_msgpack_iter  iter,
vl_dsidx_t  idx 
)

Finds a child element by index.

This function retrieves the indexed child from a parent container. The parent must be an array.

Parameters
packThe MessagePack DOM instance.
iterThe parent node.
idxThe zero-based index of the child.
Returns
An iterator to the indexed child or an invalid iterator if out of bounds.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackFirstChild()

vl_msgpack_iter vlMsgPackFirstChild ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the first child of a given node.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
An iterator to the first child node, or an invalid iterator if there are no children.
+ Here is the call graph for this function:

◆ vlMsgPackFree()

void vlMsgPackFree ( vl_msgpack pack)

Frees the specified MessagePack DOM.

The specified MessagePack must have been initialized via vlMsgPackInit before calling this function.

Contract

  • Ownership: Releases ownership of internal resources (hashtable, arena).
  • Lifetime: The pack structure remains but its internal data is invalid.
  • Thread Safety: Not thread-safe.
  • Nullability: pack must not be NULL.
  • Error Conditions: None.
  • Undefined Behavior: Passing NULL. Calling on a pack that was not initialized.
  • Memory Allocation Expectations: Deallocates internal hashtable and arena.
  • Return-value Semantics: None (void).
Parameters
packpointer to DOM
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackInit()

void vlMsgPackInit ( vl_msgpack pack)

Initializes the specified MessagePack DOM.

Contract

  • Ownership: The caller provides the pack memory.
  • Lifetime: The pack remains valid until vlMsgPackFree.
  • Thread Safety: Not thread-safe for the same pack instance.
  • Nullability: pack must not be NULL.
  • Error Conditions: None.
  • Undefined Behavior: Passing NULL. Initializing an already initialized pack without freeing it.
  • Memory Allocation Expectations: Allocates internal hashtable and arena structures.
  • Return-value Semantics: None (void).
See also
vlMsgPackInit
Parameters
packpointer to DOM
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackInsert()

vl_msgpack_iter vlMsgPackInsert ( vl_msgpack pack,
vl_msgpack_type  type,
vl_msgpack_iter  parent,
const void *  keyPtr,
vl_memsize_t  keyLen,
const void *  dataPtr,
vl_memsize_t  dataLen 
)
+ Here is the caller graph for this function:

◆ vlMsgPackInsertExt()

vl_msgpack_iter vlMsgPackInsertExt ( vl_msgpack pack,
vl_msgpack_type  type,
vl_int8_t  subType,
vl_msgpack_iter  parent,
const void *  keyPtr,
vl_memsize_t  keyLen,
const void *  dataPtr,
vl_memsize_t  dataLen 
)

Inserts a new element into the MessagePack DOM with an extended type.

This function inserts an element of the specified MessagePack type and optional extended type under a given parent node. The key and value are copied into the internal storage, allowing external memory to be safely freed after insertion.

Parameters
packThe MessagePack DOM instance.
typeThe type of the inserted element.
subTypeThe extended type (used for MessagePack ext types).
parentThe parent node where the element is inserted.
keyPtrPointer to the key data.
keyLenLength of the key.
dataPtrPointer to the value data.
dataLenLength of the value.
Returns
An iterator to the newly inserted element.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackNew()

vl_msgpack * vlMsgPackNew ( void  )

Allocates and initializes a MessagePack DOM.

The returned pointer is to be deleted via vlMsgPackDelete.

Contract

  • Ownership: The caller owns the returned vl_msgpack pointer and is responsible for calling vlMsgPackDelete.
  • Lifetime: The DOM remains valid until vlMsgPackDelete.
  • Thread Safety: This function is thread-safe (uses heap allocation).
  • Nullability: Returns NULL if allocation fails.
  • Error Conditions: Returns NULL on heap allocation failure.
  • Undefined Behavior: None.
  • Memory Allocation Expectations: Allocates the vl_msgpack structure and its internal data on the heap.
  • Return-value Semantics: Returns a pointer to the new DOM, or NULL on failure.
See also
vlMsgPackDelete
Returns
pointer to DOM
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackNextSibling()

vl_msgpack_iter vlMsgPackNextSibling ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the next sibling of a given node.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
An iterator to the next sibling node, or an invalid iterator if there is no next sibling.
+ Here is the call graph for this function:

◆ vlMsgPackParent()

vl_msgpack_iter vlMsgPackParent ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the parent node of a given node in the MessagePack DOM.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
An iterator to the parent node, or an invalid iterator if the node has no parent.
+ Here is the call graph for this function:

◆ vlMsgPackPrevSibling()

vl_msgpack_iter vlMsgPackPrevSibling ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the previous sibling of a given node.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
An iterator to the previous sibling node, or an invalid iterator if there is no previous sibling.
+ Here is the call graph for this function:

◆ vlMsgPackRemove()

void vlMsgPackRemove ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Removes an element from the MessagePack DOM.

This function removes the specified element and all its children from the DOM. Memory may be reused depending on the allocator's behavior.

Parameters
packThe MessagePack DOM instance.
iterIterator pointing to the element to be removed.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackSampleKey()

const vl_transient * vlMsgPackSampleKey ( vl_msgpack pack,
vl_msgpack_iter  iter,
vl_memsize_t *  size 
)

Retrieves the key associated with an element.

This function returns a pointer to the key data of the given element. The key may move if modifications occur in the DOM, so users should not store this pointer for long-term access.

Parameters
packThe MessagePack DOM instance.
iterThe element iterator.
sizePointer to receive the key size (optional, can be NULL).
Returns
A transient pointer to the key data.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackSampleValue()

vl_transient * vlMsgPackSampleValue ( vl_msgpack pack,
vl_msgpack_iter  iter,
vl_memsize_t *  size 
)

Retrieves the value associated with an element.

This function returns a pointer to the value data of the given element. The value may move if modifications occur in the DOM, so users should not store this pointer for long-term access.

Parameters
packThe MessagePack DOM instance.
iterThe element iterator.
sizePointer to receive the value size (optional, can be NULL).
Returns
A transient pointer to the value data.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlMsgPackTotalChildren()

vl_dsidx_t vlMsgPackTotalChildren ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the total number of children of a given node.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
The number of child nodes.
+ Here is the call graph for this function:

◆ vlMsgPackType()

vl_msgpack_type vlMsgPackType ( vl_msgpack pack,
vl_msgpack_iter  iter 
)

Retrieves the type of a given node in the MessagePack DOM.

Parameters
packThe MessagePack DOM instance.
iterThe iterator pointing to the current node.
Returns
The MessagePack type of the node.
+ Here is the call graph for this function:
+ Here is the caller graph for this function: