Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_msgpack.h File Reference
#include "vl_hashtable.h"
#include "vl_arena.h"
#include "vl_buffer.h"
#include <string.h>
+ Include dependency graph for vl_msgpack.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vl_msgpack
 MessagePack Document Object Model. More...
 

Macros

#define VL_MSGPACK_ITER_INVALID   VL_HASHTABLE_ITER_INVALID
 
#define VL_MSGPACK_EXT_NONE   -127
 
#define VL_MSGPACK_FOREACH_CHILD(packPtr, parentIter, childIterSymbol)
 
#define vlMsgPackRoot(packPtr)   ((packPtr)->root)
 Macro to retrieve the root of the MessagePack DOM.
 

Typedefs

typedef vl_hash_iter vl_msgpack_iter
 

Enumerations

enum  vl_msgpack_type {
  VL_MSGPACK_NIL , VL_MSGPACK_BOOL , VL_MSGPACK_INT , VL_MSGPACK_UINT ,
  VL_MSGPACK_FLOAT32 , VL_MSGPACK_FLOAT64 , VL_MSGPACK_STRING , VL_MSGPACK_BINARY ,
  VL_MSGPACK_ARRAY , VL_MSGPACK_MAP , VL_MSGPACK_EXT
}
 All MessagePack Types. More...
 

Functions

void vlMsgPackInit (vl_msgpack *pack)
 Initializes the specified MessagePack DOM.
 
void vlMsgPackFree (vl_msgpack *pack)
 Frees the specified MessagePack DOM.
 
vl_msgpackvlMsgPackNew ()
 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 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.
 
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 *key, vl_memsize_t keyLen)
 Finds a child element by key.
 
vl_msgpack_iter vlMsgPackFindChildIndexed (vl_msgpack *pack, vl_msgpack_iter iter, vl_dsidx_t idx)
 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.
 

Data Structure Documentation

◆ vl_msgpack

struct vl_msgpack

MessagePack Document Object Model.

An in-memory, hierarchical representation of a complete MessagePack.

This structure represents an N-Tree with parent-child relationships that accurately represents a MessagePack structure. It is implemented using a hierarchical hash table for nodes and parent-child relationships, using separate arena allocator for node values. Nodes in this structure are dynamically typed.

The design of this structure is NOT completely compliant with the MessagePack spec. It requires the two following rules to be enforced:

  1. Elements in a Map must ALWAYS have String keys (e.g, named elements).
  2. Elements in an Array must ALWAYS have Integer keys (e.g, indexed elements), although their keys are implicit. This design choice simplifies the implementation by disallowing complex structures such as Maps and Arrays to act as Map keys, keeping it in line with formats comparable to JSON.

All strings in and out of this structure, keys or values, are assumed to be UTF-8 encoded.

See also
https://github.com/msgpack/msgpack/blob/master/spec.md
+ Collaboration diagram for vl_msgpack:
Data Fields
vl_hashtable nodes
vl_msgpack_iter root
vl_arena values

Macro Definition Documentation

◆ VL_MSGPACK_EXT_NONE

#define VL_MSGPACK_EXT_NONE   -127

◆ VL_MSGPACK_FOREACH_CHILD

#define VL_MSGPACK_FOREACH_CHILD ( packPtr,
parentIter,
childIterSymbol )
Value:
for(vl_msgpack_iter childIterSymbol = vlMsgPackFirstChild((packPtr), (parentIter)); \
childIterSymbol != VL_MSGPACK_ITER_INVALID; \
childIterSymbol = vlMsgPackNextSibling((packPtr), (childIterSymbol)))
vl_hash_iter vl_msgpack_iter
Definition vl_msgpack.h:17
vl_msgpack_iter vlMsgPackFirstChild(vl_msgpack *pack, vl_msgpack_iter iter)
Retrieves the first child of a given node.
Definition vl_msgpack.c:214
vl_msgpack_iter vlMsgPackNextSibling(vl_msgpack *pack, vl_msgpack_iter iter)
Retrieves the next sibling of a given node.
Definition vl_msgpack.c:226
#define VL_MSGPACK_ITER_INVALID
Definition vl_msgpack.h:9

◆ VL_MSGPACK_ITER_INVALID

#define VL_MSGPACK_ITER_INVALID   VL_HASHTABLE_ITER_INVALID

◆ vlMsgPackRoot

#define vlMsgPackRoot ( packPtr)    ((packPtr)->root)

Macro to retrieve the root of the MessagePack DOM.

This macro provides access to the root node of the DOM. The root node is always a map.

Parameters
packPtrA pointer to the MessagePack DOM instance.
Returns
The root iterator of the MessagePack DOM.

Typedef Documentation

◆ vl_msgpack_iter

Enumeration Type Documentation

◆ vl_msgpack_type

All MessagePack Types.

Enumerator
VL_MSGPACK_NIL 

MessagePack type equivalent to NIL. Has no data associated with it.

VL_MSGPACK_BOOL 

MessagePack Boolean. Either True (1) or False (0).

VL_MSGPACK_INT 

MessagePack Signed Integer. Implemented as vl_ilarge_t.

VL_MSGPACK_UINT 

MessagePack Unsigned Integer. Implemented as vl_ularge_t.

VL_MSGPACK_FLOAT32 

MessagePack 32-bit Float. Implemented as vl_float32_t.

VL_MSGPACK_FLOAT64 

MessagePack 64-bit Float. Implemented as vl_float64_t.

VL_MSGPACK_STRING 

MessagePack String. Must have UTF-8 encoding.

VL_MSGPACK_BINARY 

MessagePack Binary. An arbitrary sequence of bytes with a well-defined length.

VL_MSGPACK_ARRAY 

MessagePack Array. A sequence of dynamically-typed nodes of a well-determined length.

VL_MSGPACK_MAP 

MessagePack Map. A collection of node key-value pairs of an arbitrary size.

VL_MSGPACK_EXT 

MessagePack Extension Type. Has a type identifier in range of 0...127 and arbitrary data.

Function Documentation

◆ 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.

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.

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.

See also
vlMsgPackInit
Parameters
packpointer to DOM
+ Here is the call graph for this function:
+ 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 ( )

Allocates and initializes a MessagePack DOM.

The returned pointer is to be deleted via vlMsgPackDelete.

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: