Tny
A simple data serializer in C
|
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
union | tnyHostOrder |
struct | _Tny |
Tny is the main type. Every Tny-document consists of chained Tny-elements. More... | |
Defines | |
#define | HOST_ORDER (tnyHostOrder.value) |
Typedefs | |
typedef struct _Tny | Tny |
Tny is the main type. Every Tny-document consists of chained Tny-elements. | |
Enumerations | |
enum | TnyEndianness { ORDER_LITTLE_ENDIAN = 0x03020100ul, ORDER_BIG_ENDIAN = 0x00010203ul } |
enum | TnyType { TNY_NULL, TNY_ARRAY, TNY_DICT, TNY_OBJ, TNY_BIN, TNY_CHAR, TNY_INT32, TNY_INT64, TNY_DOUBLE } |
TnyType contains every supported type. More... | |
Functions | |
Tny * | Tny_add (Tny *prev, TnyType type, char *key, void *value, uint64_t size) |
Adds a new element after the prev element. | |
Tny * | Tny_copy (size_t *docSizePtr, const Tny *src) |
Performs a deep copy of the src object. | |
void | Tny_remove (Tny *tny) |
Removes an element or a complete document. | |
Tny * | Tny_at (const Tny *tny, size_t index) |
Returns the element at position index . | |
Tny * | Tny_get (const Tny *tny, const char *key) |
Returns the element with the specified key. | |
size_t | Tny_dumps (const Tny *tny, void **data) |
Serializes a document. | |
Tny * | Tny_loads (void *data, size_t length) |
Deserializes a serialized document. | |
int | Tny_hasNext (const Tny *tny) |
Checks if there are more elements to fetch. | |
Tny * | Tny_next (const Tny *tny) |
Returns the next element. | |
void | Tny_free (Tny *tny) |
Frees the document. | |
Variables | |
union tnyHostOrder | tnyHostOrder |
The Tny binary format looks like this (ABNF):
{.txt} Document = (ArrayHeader *ArrayElement) / (DictionaryHeader *DictionaryElement) ArrayHeader = ArrayType NumberOfElements DictionaryHeader = DictionaryType NumberOfElements NumberOfElements = int32 ; Dictionary element DictionaryElement = NullType Key DictionaryElement =/ ObjectType Key ObjectValue DictionaryElement =/ BinaryType Key BinaryValue DictionaryElement =/ CharType Key CharValue DictionaryElement =/ Int32Type Key Int32Value DictionaryElement =/ Int64Type Key Int64Value DictionaryElement =/ DoubleType Key DoubleValue Key = int32 1*(%x01-FF) %x00 ; Array element ArrayElement = NullType ArrayElement =/ ObjectType ObjectValue ArrayElement =/ BinaryType BinaryValue ArrayElement =/ CharType CharValue ArrayElement =/ Int32Type Int32Value ArrayElement =/ Int64Type Int64Value ArrayElement =/ DoubleType DoubleValue ; Types NullType = %x00 ArrayType = %x01 DictionaryType = %x02 ObjectType = %x03 BinaryType = %x04 CharType = %x05 Int32Type = %x06 Int64Type = %x07 DoubleType = %x08 ; Values ObjectValue = Document BinaryValue = int32 *CharValue CharValue = %x00-FF Int32Value = int32 Int64Value = int64 DoubleValue = int64 int32 = 4(%x00-FF) int64 = 8(%x00-FF)
enum TnyType |
TnyType contains every supported type.
Adds a new element after the prev
element.
[in] | prev | is the previous element. If prev is NULL, a new document will be created. |
[in] | type | is the type of the new element. If this is the first element you can either use TNY_ARRAY for an array or TNY_DICT for a dictionary. |
[in] | key | If the document is of type TNY_DICT, the key must be set in every element. Otherwise key can be NULL. |
[in] | value | is the value of the new element. If the type is TNY_OBJ a deep copy of value will be performed. |
[in] | size | needs only to be set if the element is of type TNY_BIN. Otherwise it can be 0. |
Returns the element at position index
.
Works in a TNY_ARRAY and a TNY_DICT.
[in] | tny | is the document or an element somewhere in the document. |
[in] | index | is the position of the element in the document tny . |
Performs a deep copy of the src
object.
[in] | docSizePtr | is only needed for internal use of Tny and can be NULL. |
[in] | src | is the source document which will be copied. |
Serializes a document.
Serializes the document and stores the result in data
. The memory needed for the serialization will get allocated.
[in] | tny | is the document which shall be serialized. |
[out] | data | is the position where the serialized document is copied to. |
Frees the document.
[in] | tny | is the document which shall be free'd. |
Returns the element with the specified key.
Works in a TNY_ARRAY and a TNY_DICT.
[in] | tny | is the document or an element somewhere in the document. |
[in] | key | is the key of the element in the document tny . |
int Tny_hasNext | ( | const Tny * | tny | ) |
Checks if there are more elements to fetch.
Simple iterator function which makes it easy to walk through an Tny document.
[in] | tny | is the current element. |
Deserializes a serialized document.
[in] | data | contains the serialized document. |
[in] | length | is the size in bytes of the serialized document. |
Returns the next element.
[in] | tny | is the last element fetched by Tny_next. |
void Tny_remove | ( | Tny * | tny | ) |
Removes an element or a complete document.