ubjsc
0.5
Enterprise-grade C library for manipulating UBJSON
|
Wrappers over ubjson primitive types. More...
Go to the source code of this file.
Typedefs | |
typedef struct ubjs_prmtv | ubjs_prmtv |
typedef struct ubjs_array_iterator | ubjs_array_iterator |
typedef struct ubjs_object_iterator | ubjs_object_iterator |
typedef enum ubjs_prmtv_type | ubjs_prmtv_type |
Enumerations | |
enum | ubjs_prmtv_type { UOT_NULL, UOT_NOOP, UOT_TRUE, UOT_FALSE, UOT_INT8, UOT_UINT8, UOT_INT16, UOT_INT32, UOT_INT64, UOT_FLOAT32, UOT_FLOAT64, UOT_HPN, UOT_CHAR, UOT_STR, UOT_ARRAY, UOT_OBJECT, UOT_MAX } |
Functions | |
UBJS_EXPORT ubjs_prmtv * | ubjs_prmtv_null (void) |
Returns null primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_null (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a null primitive. More... | |
UBJS_EXPORT ubjs_prmtv * | ubjs_prmtv_noop (void) |
Returns no-op primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_noop (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a no-op primitive. More... | |
UBJS_EXPORT ubjs_prmtv * | ubjs_prmtv_true (void) |
Returns true primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_true (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a true primitive. More... | |
UBJS_EXPORT ubjs_prmtv * | ubjs_prmtv_false (void) |
Returns false primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_false (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a false primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int (ubjs_library *lib, int64_t value, ubjs_prmtv **pthis) |
Returns the best int primitive wrapping given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_uint (ubjs_library *lib, int64_t value, ubjs_prmtv **pthis) |
Returns the best unsigned int primitive wrapping given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_int (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is any integer primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int_get (ubjs_prmtv *this, int64_t *pvalue) |
Gets the value of the integer primitive, regardless of its type. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int8 (ubjs_library *lib, int8_t value, ubjs_prmtv **pthis) |
Returns int8 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_int8 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an int8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int8_get (ubjs_prmtv *this, int8_t *pvalue) |
Gets the value of the int8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int8_set (ubjs_prmtv *this, int8_t value) |
Sets the value of the int8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_uint8 (ubjs_library *lib, uint8_t value, ubjs_prmtv **pthis) |
Returns uint8 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_uint8 (ubjs_prmtv *this, ubjs_bool *presult) |
Checks whether the primitive is an uint8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_uint8_get (ubjs_prmtv *this, uint8_t *pvalue) |
Gets the value of the uint8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_uint8_set (ubjs_prmtv *this, uint8_t value) |
Sets the value of the uint8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int16 (ubjs_library *lib, int16_t value, ubjs_prmtv **pthis) |
Returns int16 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_int16 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an int16 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int16_get (ubjs_prmtv *this, int16_t *pvalue) |
Gets the value of the int16 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int16_set (ubjs_prmtv *this, int16_t value) |
Sets the value of the int16 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int32 (ubjs_library *lib, int32_t value, ubjs_prmtv **pthis) |
Returns int32 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_int32 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an int32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int32_get (ubjs_prmtv *this, int32_t *pvalue) |
Gets the value of the int32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int32_set (ubjs_prmtv *this, int32_t value) |
Sets the value of the int32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int64 (ubjs_library *lib, int64_t value, ubjs_prmtv **pthis) |
Returns int64 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_int64 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an int64 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int64_get (ubjs_prmtv *this, int64_t *pvalue) |
Gets the value of the int8 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_int64_set (ubjs_prmtv *this, int64_t value) |
Sets the value of the int64 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float32 (ubjs_library *lib, float32_t value, ubjs_prmtv **pthis) |
Returns float32 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_float32 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a float32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float32_get (ubjs_prmtv *this, float32_t *pvalue) |
Gets the value of the int32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float32_set (ubjs_prmtv *this, float32_t value) |
Sets the value of the float32 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float64 (ubjs_library *lib, float64_t value, ubjs_prmtv **pthis) |
Returns float64 primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_float64 (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a float64 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float64_get (ubjs_prmtv *this, float64_t *pvalue) |
Gets the value of the int64 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_float64_set (ubjs_prmtv *this, float64_t value) |
Sets the value of the float64 primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_hpn (ubjs_library *lib, unsigned int length, char *text, ubjs_prmtv **pthis) |
Returns high-precision number primitive for given string. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_hpn (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a high-precision number primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_hpn_get_length (ubjs_prmtv *this, unsigned int *result) |
Gets the high-precision number primitive's string length. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_hpn_copy_text (ubjs_prmtv *this, char *result) |
Copies the high-precision number primitive's string content to provided array. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_hpn_set (ubjs_prmtv *this, unsigned int length, char *text) |
Sets the string value of the high-precision number primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_char (ubjs_library *lib, char value, ubjs_prmtv **pthis) |
Returns char primitive for given value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_char (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a char primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_char_get (ubjs_prmtv *this, char *pvalue) |
Gets the value of the char primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_char_set (ubjs_prmtv *this, char value) |
Sets the value of the char primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_str (ubjs_library *lib, unsigned int length, char *text, ubjs_prmtv **pthis) |
Returns str primitive for given string. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_str (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is a str primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_str_get_length (ubjs_prmtv *this, unsigned int *result) |
Gets the string primitive's length. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_str_copy_text (ubjs_prmtv *this, char *result) |
Copies the string primitive's content to provided array. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_str_set (ubjs_prmtv *this, unsigned int length, char *text) |
Sets the value of the string primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array (ubjs_library *lib, ubjs_prmtv **pthis) |
Returns array primitive for an empty array. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_with_length (ubjs_library *lib, unsigned int length, ubjs_prmtv **pthis) |
Returns array primitive for an empty array, with initial size known. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_with_length_and_type (ubjs_library *lib, ubjs_prmtv_type type, unsigned int length, ubjs_prmtv **pthis) |
Returns array primitive for an empty array, with initial size known and item type. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_array (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_get_length (ubjs_prmtv *this, unsigned int *length) |
Gets the array primitive's length. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_get_first (ubjs_prmtv *this, ubjs_prmtv **pitem) |
Gets reference to first item of the array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_get_last (ubjs_prmtv *this, ubjs_prmtv **pitem) |
Gets reference to last item of the array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_get_at (ubjs_prmtv *this, unsigned int pos, ubjs_prmtv **pitem) |
Gets reference to n-th item of the array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_add_first (ubjs_prmtv *this, ubjs_prmtv *item) |
Inserts an item into array primitive as a first one. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_add_last (ubjs_prmtv *this, ubjs_prmtv *item) |
Inserts an item into array primitive as a last one. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_add_at (ubjs_prmtv *this, unsigned int pos, ubjs_prmtv *item) |
Inserts an item into array primitive before an existing n-th one. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_delete_first (ubjs_prmtv *this) |
Deletes the first item from array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_delete_last (ubjs_prmtv *this) |
Deletes the last item from array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_delete_at (ubjs_prmtv *this, unsigned int pos) |
Deletes the n-th item from array primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_array_iterate (ubjs_prmtv *this, ubjs_array_iterator **iterator) |
Returns iterator over this array. More... | |
UBJS_EXPORT ubjs_result | ubjs_array_iterator_next (ubjs_array_iterator *this) |
Tries to advance the array iterator. More... | |
UBJS_EXPORT ubjs_result | ubjs_array_iterator_get (ubjs_array_iterator *this, ubjs_prmtv **item) |
Gets the item from the array iterator. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object (ubjs_library *lib, ubjs_prmtv **pthis) |
Returns object primitive for an empty object. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_with_length (ubjs_library *lib, unsigned int length, ubjs_prmtv **pthis) |
Returns object primitive for an empty object, with initial size known. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_with_length_and_type (ubjs_library *lib, ubjs_prmtv_type type, unsigned int length, ubjs_prmtv **pthis) |
Returns object primitive for an empty objecty, with initial size known and item type. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_is_object (ubjs_prmtv *this, ubjs_bool *result) |
Checks whether the primitive is an object primitive. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_get_length (ubjs_prmtv *this, unsigned int *pvalue) |
Gets the object primitive's length. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_get (ubjs_prmtv *this, unsigned int key_length, char *key, ubjs_prmtv **pvalue) |
Gets the value for specified key. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_set (ubjs_prmtv *this, unsigned int key_length, char *key, ubjs_prmtv *value) |
Sets the value for specified key. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_delete (ubjs_prmtv *this, unsigned int key_length, char *key) |
Deletes the value for specified key. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_object_iterate (ubjs_prmtv *this, ubjs_object_iterator **iterator) |
Returns iterator over this object. The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_object_iterator_free, behavior is undefined. More... | |
UBJS_EXPORT ubjs_result | ubjs_object_iterator_next (ubjs_object_iterator *this) |
Tries to advance the object iterator. More... | |
UBJS_EXPORT ubjs_result | ubjs_object_iterator_get_key_length (ubjs_object_iterator *this, unsigned int *plen) |
Gets the key's length from the object iterator. More... | |
UBJS_EXPORT ubjs_result | ubjs_object_iterator_copy_key (ubjs_object_iterator *this, char *text) |
Copies the key from the object iterator to provided array. More... | |
UBJS_EXPORT ubjs_result | ubjs_object_iterator_get_value (ubjs_object_iterator *this, ubjs_prmtv **pvalue) |
Gets the value from the object iterator. More... | |
UBJS_EXPORT ubjs_result | ubjs_array_iterator_free (ubjs_array_iterator **pthis) |
Frees the iterator. After this returns UR_OK, *pthis is equal to 0. More... | |
UBJS_EXPORT ubjs_result | ubjs_object_iterator_free (ubjs_object_iterator **pthis) |
Frees the iterator. After this returns UR_OK, *pthis is equal to 0. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_get_type (ubjs_prmtv *this, ubjs_prmtv_type *ptype) |
Gets the primitive's type. After this returns UR_OK, *ptype has a value. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_debug_string_get_length (ubjs_prmtv *this, unsigned int *plen) |
Calculates the length of would-be-serialized debug string for the primitive. After this returns UR_OK, *this gets a malloc()-d null-terminated string. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_debug_string_copy (ubjs_prmtv *this, char *str) |
Serializes the primitive and copies the debug string to provided array. More... | |
UBJS_EXPORT ubjs_result | ubjs_prmtv_free (ubjs_prmtv **pthis) |
Frees the primitive. After this returns UR_OK, *pthis is equal to 0. More... | |
Wrappers over ubjson primitive types.
Ubjson defines a number of types and they all are wrapped over an umbrella ubjs_prmtv structure.
Common operations:
construction.
For non-value types (null, no-op, true, false), ubjs_prmtv_<type> return singletons.
For "valued" types, especially containers, ubjs_prmtv_<type> construct new structs.
For integer values, there is also a helper ubjs_prmtv_int that decides the type of final wrapper in runtime, depending on the value. This ensures that the least memory is taken for the wrapper.
deconstruction.
Call ubjs_prmtv_free(&value). This works on all types, both valueless and "valued".
checking type
ubjs_prmtv_get_type returns the wrapper's type. Also each type has its own ubjs_prmtv_is_<type> method.
This applies also to ubjs_prmtv_is_int that returns UTRUE when the wrapper is of any int type.
getters/setters
Most valued types has its own ubjs_prmtv_<type>_get and ubjs_prmtv_<type>_set methods.
String, array and object wrappers also have ubjs_prmtv_<type>_get_length methods for getting the number of items (or, in case of str, characters) in the value.
manipulating container's content
Strings are mutable. Arrays have methods for inserting, getting and removing items, and same for objects.
iterating over container
Array and object have their own iterators. Arrays are iterated from front (from 0 to ubjs_array_get_length() - 1), objects are iterated in-order (from the lowest key to the highest).
Types supported:
no-op - ubjs_prmtv_noop returns a singleton.
ubjson.org says that "when parsed by the receiver, the no-op values are simply skipped and carry know meaningful value with them.". I've decided to leave this to the user and because of that, no-ops are parsed always and passed to the user.
For ubjsc these two arrays are NOT equal on the parse/write level:
string - ubjs_prmtv_str. Internally stored as (char *).
Supported length markers: uint8, int8 (only parsing), int16, int32. Theoretically int64 will work too, but due to lack of example (who would like a 13TB string?) this is not not tested. When writing, the best length marker is choosen during runtime.
high precision numbers - ubjs_prmtv_hpn. Internally stored as (char *).
Currently no all-precision manipulation library is employed.
array - ubjs_prmtv_array.
This is stored internally as an... array of pointers to items. Its real size is maintained using something similar to exponential backoff algorithm. The real size is expanded and shrunk on demand. The items are NOT stored in single memory block, and for now this is true even though we have implemented count and typed optimizations of containers.
object - ubjs_prmtv_object.
This is stored internally as a patricia trie, by in-house library. I know, another reinvented wheel in this world... But so far it works great. The items are NOT stored in single memory block, and for now this is true even though we have implemented count and typed optimizations of containers.
typedef struct ubjs_array_iterator ubjs_array_iterator |
Struct for array's iterator.
typedef struct ubjs_object_iterator ubjs_object_iterator |
Struct for objects's iterator.
typedef struct ubjs_prmtv ubjs_prmtv |
Abstract struct for all ubjson primitives.
typedef enum ubjs_prmtv_type ubjs_prmtv_type |
Legal primitive types.
enum ubjs_prmtv_type |
Legal primitive types.
UBJS_EXPORT ubjs_result ubjs_array_iterator_free | ( | ubjs_array_iterator ** | pthis | ) |
Frees the iterator. After this returns UR_OK, *pthis is equal to 0.
pthis | Pointer to existing iterator. |
References ubjs_prmtv_free(), UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_array_iterator_get | ( | ubjs_array_iterator * | this, |
ubjs_prmtv ** | item | ||
) |
Gets the item from the array iterator.
The array must exist thru the life of the iterator. If you ubjs_prmtv_free the array before you ubjs_array_iterator_free, behavior is undefined.
If ubjs_array_iterator_next returned UR_ERROR, this will also return UR_ERROR. Else after this method returns UR_OK, and *item gets a value.
this | Iterator. |
item | Pointer to where put the item. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_array_iterator_next | ( | ubjs_array_iterator * | this | ) |
Tries to advance the array iterator.
The array must exist thru the life of the iterator. If you ubjs_prmtv_free the array before you ubjs_array_iterator_free, behavior is undefined.
If this returns UR_OK, you can safely call ubjs_array_iterator_get to get the item at this position.
this | Iterator. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_object_iterator_copy_key | ( | ubjs_object_iterator * | this, |
char * | text | ||
) |
Copies the key from the object iterator to provided array.
Target array must be preallocated. Before the call, you may want to ubjs_prmtv_str_get_length and allocate the target array.
The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_array_iterator_free, behavior is undefined.
If ubjs_array_iterator_next returned UR_ERROR, this will also return UR_ERROR. Else after this method returns UR_OK, and *text gets a value.
this | Iterator. |
text | Target array. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_object_iterator_free | ( | ubjs_object_iterator ** | pthis | ) |
UBJS_EXPORT ubjs_result ubjs_object_iterator_get_key_length | ( | ubjs_object_iterator * | this, |
unsigned int * | plen | ||
) |
Gets the key's length from the object iterator.
The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_array_iterator_free, behavior is undefined.
If ubjs_array_iterator_next returned UR_ERROR, this will also return UR_ERROR. Else after this method returns UR_OK, and *plen gets a value.
this | Iterator. |
plen | Pointer to where put key's length. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_object_iterator_get_value | ( | ubjs_object_iterator * | this, |
ubjs_prmtv ** | pvalue | ||
) |
Gets the value from the object iterator.
The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_array_iterator_free, behavior is undefined.
If ubjs_array_iterator_next returned UR_ERROR, this will also return UR_ERROR. Else after this method returns UR_OK, and *pvalue gets a value.
this | Iterator. |
pvalue | Pointer to where put value. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_object_iterator_next | ( | ubjs_object_iterator * | this | ) |
Tries to advance the object iterator.
The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_array_iterator_free, behavior is undefined.
If this returns UR_OK, you can safely call ubjs_object_iterator_get to get the item at this position.
this | Iterator. |
References UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_array | ( | ubjs_library * | lib, |
ubjs_prmtv ** | pthis | ||
) |
Returns array primitive for an empty array.
After this returns UR_OK, *pthis points to a valid array primitive.
lib | Library handle. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, ubjs_glue_array_builder::build_f, ubjs_glue_array_builder::free_f, ubjs_library::glue_array_builder, ubjs_glue_array_builder::set_value_free_f, UOT_ARRAY, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_array_add_at | ( | ubjs_prmtv * | this, |
unsigned int | pos, | ||
ubjs_prmtv * | item | ||
) |
Inserts an item into array primitive before an existing n-th one.
This means that existing n-th item will become (n + 1)-th. pos == 0 is the same as ubjs_prmtv_array_add_first. pos == ubjs_prmtv_array_get_length is the same as ubjs_prmtv_array_add_last. What happens when iterating over the array during adding items - this is undefined behavior.
this | Primitive. |
pos | Position of the item. Must be within 0..(ubjs_prmtv_array_get_length). |
item | New item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_add_first | ( | ubjs_prmtv * | this, |
ubjs_prmtv * | item | ||
) |
Inserts an item into array primitive as a first one.
This means that the existing first item becomes the second. What happens when iterating over the array during adding items - this is undefined behavior.
this | Primitive. |
item | New item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_add_last | ( | ubjs_prmtv * | this, |
ubjs_prmtv * | item | ||
) |
Inserts an item into array primitive as a last one.
This means that the existing last item becomes the second-last. What happens when iterating over the array during adding items - this is undefined behavior.
this | Primitive. |
item | New item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_delete_at | ( | ubjs_prmtv * | this, |
unsigned int | pos | ||
) |
Deletes the n-th item from array primitive.
This means that the (n + 1)-th item becomes the n-th. What happens when iterating over the array during deleting items - this is undefined behavior.
The item does get ubjs_prmtv_free-d.
this | Primitive. |
pos | Position of the item. Must be within 0..(ubjs_prmtv_array_get_length - 1). |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_delete_first | ( | ubjs_prmtv * | this | ) |
Deletes the first item from array primitive.
This means that the existing second item becomes the first. What happens when iterating over the array during deleting items - this is undefined behavior.
The item does get ubjs_prmtv_free-d.
this | Primitive. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_delete_last | ( | ubjs_prmtv * | this | ) |
Deletes the last item from array primitive.
This means that the existing second-last item becomes the last. What happens when iterating over the array during deleting items - this is undefined behavior.
The item does get ubjs_prmtv_free-d.
this | Primitive. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_get_at | ( | ubjs_prmtv * | this, |
unsigned int | pos, | ||
ubjs_prmtv ** | pitem | ||
) |
Gets reference to n-th item of the array primitive.
This is the internal reference to an item and must not be ubjs_prmtv_free-d.
this | Primitive. |
pos | Position of the item. Must be within 0..(ubjs_prmtv_array_get_length - 1). |
pitem | Pointer to where set the item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_get_first | ( | ubjs_prmtv * | this, |
ubjs_prmtv ** | pitem | ||
) |
Gets reference to first item of the array primitive.
This is the internal reference to an item and must not be ubjs_prmtv_free-d.
this | Primitive. |
pitem | Pointer to where set the item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_get_last | ( | ubjs_prmtv * | this, |
ubjs_prmtv ** | pitem | ||
) |
Gets reference to last item of the array primitive.
This is the internal reference to an item and must not be ubjs_prmtv_free-d.
this | Primitive. |
pitem | Pointer to where set the item. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_get_length | ( | ubjs_prmtv * | this, |
unsigned int * | length | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_iterate | ( | ubjs_prmtv * | this, |
ubjs_array_iterator ** | iterator | ||
) |
Returns iterator over this array.
The array must exist thru the life of the iterator. If you ubjs_prmtv_free the array before you ubjs_array_iterator_free, behavior is undefined.
After this returns UR_OK, *pthis points to new iterator. First call to ubjs_array_iterator_next will point to 0-th item.
this | Existing array primitive. |
iterator | Pointer to where put newly created iterator. |
UBJS_EXPORT ubjs_result ubjs_prmtv_array_with_length | ( | ubjs_library * | lib, |
unsigned int | length, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns array primitive for an empty array, with initial size known.
Call this if you know you will add n-items.
After this returns UR_OK, *pthis points to a valid array primitive.
lib | Library handle. |
length | Initial length. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, ubjs_glue_array_builder::build_f, ubjs_glue_array_builder::free_f, ubjs_library::glue_array_builder, ubjs_glue_array_builder::set_length_f, ubjs_glue_array_builder::set_value_free_f, UOT_ARRAY, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_array_with_length_and_type | ( | ubjs_library * | lib, |
ubjs_prmtv_type | type, | ||
unsigned int | length, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns array primitive for an empty array, with initial size known and item type.
Call this if you know you will add n-items of exactly one type.
After this returns UR_OK, *pthis points to a valid array primitive.
lib | Library handle. |
type | Item type. |
length | Initial length. |
pthis | Pointer to where put newly created primitive. |
UBJS_EXPORT ubjs_result ubjs_prmtv_char | ( | ubjs_library * | lib, |
char | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns char primitive for given value.
After this returns UR_OK, *pthis points to a valid char primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_CHAR, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_char_get | ( | ubjs_prmtv * | this, |
char * | pvalue | ||
) |
Gets the value of the char primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_CHAR, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_char_set | ( | ubjs_prmtv * | this, |
char | value | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_debug_string_copy | ( | ubjs_prmtv * | this, |
char * | str | ||
) |
Serializes the primitive and copies the debug string to provided array.
Target array must be preallocated. Before the call, you may want to ubjs_prmtv_debug_string_get_length and allocate the target array.
this | Existing primitive. |
str | Pointer to where put debug string. |
References UR_ERROR.
Referenced by ubjs_parser_parse().
UBJS_EXPORT ubjs_result ubjs_prmtv_debug_string_get_length | ( | ubjs_prmtv * | this, |
unsigned int * | plen | ||
) |
Calculates the length of would-be-serialized debug string for the primitive. After this returns UR_OK, *this gets a malloc()-d null-terminated string.
this | Existing primitive. |
plen | Pointer to where put debug string's length. |
References UR_ERROR.
Referenced by ubjs_parser_parse().
UBJS_EXPORT ubjs_prmtv* ubjs_prmtv_false | ( | void | ) |
Returns false primitive.
This is a singleton and ubj_prmtv_free do nothing.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_float32 | ( | ubjs_library * | lib, |
float32_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns float32 primitive for given value.
After this returns UR_OK, *pthis points to a valid float32 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_FLOAT32, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_float32_get | ( | ubjs_prmtv * | this, |
float32_t * | pvalue | ||
) |
Gets the value of the int32 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_FLOAT32, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_float32_set | ( | ubjs_prmtv * | this, |
float32_t | value | ||
) |
Sets the value of the float32 primitive.
this | Primitive. |
value | New value. |
References UOT_FLOAT32, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_float64 | ( | ubjs_library * | lib, |
float64_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns float64 primitive for given value.
After this returns UR_OK, *pthis points to a valid float64 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_FLOAT64, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_float64_get | ( | ubjs_prmtv * | this, |
float64_t * | pvalue | ||
) |
Gets the value of the int64 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_FLOAT64, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_float64_set | ( | ubjs_prmtv * | this, |
float64_t | value | ||
) |
Sets the value of the float64 primitive.
this | Primitive. |
value | New value. |
References UOT_FLOAT64, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_free | ( | ubjs_prmtv ** | pthis | ) |
Frees the primitive. After this returns UR_OK, *pthis is equal to 0.
pthis | Pointer to existing primitive. |
References UR_ERROR.
Referenced by ubjs_array_iterator_free(), ubjs_parser_parse(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_get_type | ( | ubjs_prmtv * | this, |
ubjs_prmtv_type * | ptype | ||
) |
Gets the primitive's type. After this returns UR_OK, *ptype has a value.
this | Existing primitive. |
ptype | Pointer to where put primitive's type. |
References UR_ERROR, and UR_OK.
Referenced by ubjs_parser_parse().
UBJS_EXPORT ubjs_result ubjs_prmtv_hpn | ( | ubjs_library * | lib, |
unsigned int | length, | ||
char * | text, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns high-precision number primitive for given string.
The string does not need to be null terminated. In fact, you must provide its length at first. Only bytes (0..length-1) will make into final primitive.
The string is parsed the same as json "number" type. See http://www.json.org/number.gif. If the string does not conform to the format, this method returns UR_ERROR.
After this returns UR_OK, *pthis points to a valid str primitive.
lib | Library handle. |
length | The length of the original string. |
text | Original string. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UFALSE, UOT_HPN, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_hpn_copy_text | ( | ubjs_prmtv * | this, |
char * | result | ||
) |
Copies the high-precision number primitive's string content to provided array.
Target array must be preallocated. Before the call, you may want to ubjs_prmtv_str_get_length and allocate the target array.
this | Primitive. |
result | Target array. |
References UOT_HPN, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_hpn_get_length | ( | ubjs_prmtv * | this, |
unsigned int * | result | ||
) |
Gets the high-precision number primitive's string length.
this | Primitive. |
result | Pointer to where set the value. |
References UOT_HPN, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_hpn_set | ( | ubjs_prmtv * | this, |
unsigned int | length, | ||
char * | text | ||
) |
Sets the string value of the high-precision number primitive.
The string is parsed the same as json "number" type. See http://www.json.org/number.gif. If the string does not conform to the format, this method returns UR_ERROR.
this | Primitive. |
length | New length of the string. |
text | New string. |
UBJS_EXPORT ubjs_result ubjs_prmtv_int | ( | ubjs_library * | lib, |
int64_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns the best int primitive wrapping given value.
After this returns UR_OK, *pthis points to a valid (u)int8/int16/int32/int64 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_prmtv_int16(), ubjs_prmtv_int32(), ubjs_prmtv_int64(), ubjs_prmtv_int8(), ubjs_prmtv_uint8(), and UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_int16 | ( | ubjs_library * | lib, |
int16_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns int16 primitive for given value.
After this returns UR_OK, *pthis points to a valid int16 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_INT16, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int(), and ubjs_prmtv_uint().
UBJS_EXPORT ubjs_result ubjs_prmtv_int16_get | ( | ubjs_prmtv * | this, |
int16_t * | pvalue | ||
) |
Gets the value of the int16 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_INT16, UR_ERROR, and UR_OK.
Referenced by ubjs_parser_parse(), ubjs_prmtv_int_get(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_int16_set | ( | ubjs_prmtv * | this, |
int16_t | value | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_int32 | ( | ubjs_library * | lib, |
int32_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns int32 primitive for given value.
After this returns UR_OK, *pthis points to a valid int32 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_INT32, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int(), and ubjs_prmtv_uint().
UBJS_EXPORT ubjs_result ubjs_prmtv_int32_get | ( | ubjs_prmtv * | this, |
int32_t * | pvalue | ||
) |
Gets the value of the int32 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_INT32, UR_ERROR, and UR_OK.
Referenced by ubjs_parser_parse(), ubjs_prmtv_int_get(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_int32_set | ( | ubjs_prmtv * | this, |
int32_t | value | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_int64 | ( | ubjs_library * | lib, |
int64_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns int64 primitive for given value.
After this returns UR_OK, *pthis points to a valid int64 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_INT64, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int(), and ubjs_prmtv_uint().
UBJS_EXPORT ubjs_result ubjs_prmtv_int64_get | ( | ubjs_prmtv * | this, |
int64_t * | pvalue | ||
) |
Gets the value of the int8 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_INT64, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int_get(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_int64_set | ( | ubjs_prmtv * | this, |
int64_t | value | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_int8 | ( | ubjs_library * | lib, |
int8_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns int8 primitive for given value.
After this returns UR_OK, *pthis points to a valid int8 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_INT8, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int().
UBJS_EXPORT ubjs_result ubjs_prmtv_int8_get | ( | ubjs_prmtv * | this, |
int8_t * | pvalue | ||
) |
Gets the value of the int8 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_INT8, UR_ERROR, and UR_OK.
Referenced by ubjs_parser_parse(), ubjs_prmtv_int_get(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_int8_set | ( | ubjs_prmtv * | this, |
int8_t | value | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_int_get | ( | ubjs_prmtv * | this, |
int64_t * | pvalue | ||
) |
Gets the value of the integer primitive, regardless of its type.
Recognized primitive types are (u)int8/int16/int32/int64. The output value is upcasted to int64_t.
this | Primitive. |
pvalue | Pointer to where set the value. |
References ubjs_prmtv_int16_get(), ubjs_prmtv_int32_get(), ubjs_prmtv_int64_get(), ubjs_prmtv_int8_get(), ubjs_prmtv_uint8_get(), UOT_INT16, UOT_INT32, UOT_INT64, UOT_INT8, UOT_UINT8, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_is_array | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_is_char | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is a char primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_CHAR, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_false | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_is_float32 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is a float32 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_FLOAT32, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_float64 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is a float64 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_FLOAT64, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_hpn | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is a high-precision number primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_HPN, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_int | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is any integer primitive.
Any integer primitive means (u)int8/int16/int32/int64.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_INT16, UOT_INT32, UOT_INT64, UOT_INT8, UOT_UINT8, UR_ERROR, UR_OK, and UTRUE.
UBJS_EXPORT ubjs_result ubjs_prmtv_is_int16 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is an int16 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_INT16, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_int32 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is an int32 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_INT32, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_int64 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is an int64 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_INT64, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_int8 | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is an int8 primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_INT8, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_noop | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_is_null | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_is_object | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is an object primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_OBJECT, UR_ERROR, UR_OK, and UTRUE.
UBJS_EXPORT ubjs_result ubjs_prmtv_is_str | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
Checks whether the primitive is a str primitive.
this | Primitive. |
result | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_STR, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_is_true | ( | ubjs_prmtv * | this, |
ubjs_bool * | result | ||
) |
UBJS_EXPORT ubjs_result ubjs_prmtv_is_uint8 | ( | ubjs_prmtv * | this, |
ubjs_bool * | presult | ||
) |
Checks whether the primitive is an uint8 primitive.
this | Primitive. |
presult | Pointer to where set the result - UTRUE/UFALSE. |
References UFALSE, UOT_UINT8, UR_ERROR, UR_OK, and UTRUE.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_prmtv* ubjs_prmtv_noop | ( | void | ) |
Returns no-op primitive.
This is a singleton and ubj_prmtv_free do nothing.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_prmtv* ubjs_prmtv_null | ( | void | ) |
Returns null primitive.
This is a singleton and ubj_prmtv_free do nothing.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_object | ( | ubjs_library * | lib, |
ubjs_prmtv ** | pthis | ||
) |
Returns object primitive for an empty object.
After this returns UR_OK, *pthis points to a valid object primitive.
lib | Library handle. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, ubjs_glue_dict_builder::build_f, ubjs_glue_dict_builder::free_f, ubjs_library::glue_dict_builder, ubjs_glue_dict_builder::set_value_free_f, UOT_OBJECT, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_delete | ( | ubjs_prmtv * | this, |
unsigned int | key_length, | ||
char * | key | ||
) |
Deletes the value for specified key.
The value gets ubjs_prmtv_free-d.
this | Primitive. |
key_length | Length of the key. |
key | Key. |
References UOT_OBJECT, and UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_get | ( | ubjs_prmtv * | this, |
unsigned int | key_length, | ||
char * | key, | ||
ubjs_prmtv ** | pvalue | ||
) |
Gets the value for specified key.
this | Primitive. |
key_length | Length of the key. |
key | Key. |
pvalue | Pointer to where put the value. |
References UOT_OBJECT, and UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_get_length | ( | ubjs_prmtv * | this, |
unsigned int * | pvalue | ||
) |
Gets the object primitive's length.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_OBJECT, and UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_iterate | ( | ubjs_prmtv * | this, |
ubjs_object_iterator ** | iterator | ||
) |
Returns iterator over this object. The object must exist thru the life of the iterator. If you ubjs_prmtv_free the object before you ubjs_object_iterator_free, behavior is undefined.
After this returns UR_OK, *pthis points to new iterator. First call to ubjs_object_iterator_next will point to 0-th item.
this | Existing object primitive. |
iterator | Pointer to where put newly created iterator. |
References UOT_OBJECT, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_set | ( | ubjs_prmtv * | this, |
unsigned int | key_length, | ||
char * | key, | ||
ubjs_prmtv * | value | ||
) |
Sets the value for specified key.
If there already exists such key in object, its value gets ubjs_prmtv_free-d.
this | Primitive. |
key_length | Length of the key. |
key | Key. |
value | New value. |
References UOT_OBJECT, and UR_ERROR.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_with_length | ( | ubjs_library * | lib, |
unsigned int | length, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns object primitive for an empty object, with initial size known.
Call this if you know you will add n-items.
After this returns UR_OK, *pthis points to a valid object primitive.
lib | Library handle. |
length | Initial length. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, ubjs_glue_dict_builder::build_f, ubjs_glue_dict_builder::free_f, ubjs_library::glue_dict_builder, ubjs_glue_dict_builder::set_length_f, ubjs_glue_dict_builder::set_value_free_f, UOT_OBJECT, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_object_with_length_and_type | ( | ubjs_library * | lib, |
ubjs_prmtv_type | type, | ||
unsigned int | length, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns object primitive for an empty objecty, with initial size known and item type.
Call this if you know you will add n-items of exactly one type.
After this returns UR_OK, *pthis points to a valid object primitive.
lib | Library handle. |
type | Item type. |
length | Length. |
pthis | Pointer to where put newly created primitive. |
UBJS_EXPORT ubjs_result ubjs_prmtv_str | ( | ubjs_library * | lib, |
unsigned int | length, | ||
char * | text, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns str primitive for given string.
The string does not need to be null terminated. In fact, you must provide its length at first. Only bytes (0..length-1) will make into final primitive.
After this returns UR_OK, *pthis points to a valid str primitive.
lib | Library handle. |
length | The length of the original string. |
text | Original string. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_STR, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_prmtv_str_copy_text | ( | ubjs_prmtv * | this, |
char * | result | ||
) |
Copies the string primitive's content to provided array.
Target array must be preallocated. Before the call, you may want to ubjs_prmtv_str_get_length and allocate the target array.
this | Primitive. |
result | Target array. |
References UOT_STR, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_str_get_length | ( | ubjs_prmtv * | this, |
unsigned int * | result | ||
) |
Gets the string primitive's length.
this | Primitive. |
result | Pointer to where set the value. |
References UOT_STR, UR_ERROR, and UR_OK.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_str_set | ( | ubjs_prmtv * | this, |
unsigned int | length, | ||
char * | text | ||
) |
UBJS_EXPORT ubjs_prmtv* ubjs_prmtv_true | ( | void | ) |
Returns true primitive.
This is a singleton and ubj_prmtv_free do nothing.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_uint | ( | ubjs_library * | lib, |
int64_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns the best unsigned int primitive wrapping given value.
After this returns UR_OK, *pthis points to a valid uint8/int16/int32/int64 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_prmtv_int16(), ubjs_prmtv_int32(), ubjs_prmtv_int64(), ubjs_prmtv_uint8(), and UR_ERROR.
Referenced by ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_uint8 | ( | ubjs_library * | lib, |
uint8_t | value, | ||
ubjs_prmtv ** | pthis | ||
) |
Returns uint8 primitive for given value.
After this returns UR_OK, *pthis points to a valid uint8 primitive.
lib | Library handle. |
value | The value. |
pthis | Pointer to where put newly created primitive. |
References ubjs_library::alloc_f, UOT_UINT8, UR_ERROR, and UR_OK.
Referenced by ubjs_prmtv_int(), and ubjs_prmtv_uint().
UBJS_EXPORT ubjs_result ubjs_prmtv_uint8_get | ( | ubjs_prmtv * | this, |
uint8_t * | pvalue | ||
) |
Gets the value of the uint8 primitive.
this | Primitive. |
pvalue | Pointer to where set the value. |
References UOT_UINT8, UR_ERROR, and UR_OK.
Referenced by ubjs_parser_parse(), ubjs_prmtv_int_get(), and ubjs_writer_print().
UBJS_EXPORT ubjs_result ubjs_prmtv_uint8_set | ( | ubjs_prmtv * | this, |
uint8_t | value | ||
) |