ubjsc  0.4-dev
Enterprise-grade C library for manipulating UBJSON
Macros | Typedefs | Enumerations | Functions
ubjs_common.h File Reference

Definitions of common types, ubjson markers and some utilities. More...

#include <stdint.h>
#include <inttypes.h>
#include "ubjs_exports.h"
Include dependency graph for ubjs_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MARKER_OPTIMIZE_COUNT   35
 Marker "#" that precedes length of a optimized container. More...
 
#define MARKER_OPTIMIZE_TYPE   36
 Marker "$" that precedes type of a optimized container. More...
 
#define MARKER_CHAR   67
 Marker "C" that precedes a character. More...
 
#define MARKER_FLOAT64   68
 Marker "D" that precedes a float64 number. More...
 
#define MARKER_FALSE   70
 Marker "F" that signals a false value. More...
 
#define MARKER_HPN   72
 Marker "H" that precedes an high-precision number. More...
 
#define MARKER_INT16   73
 Marker "I" that precedes an int16 number. More...
 
#define MARKER_INT64   76
 Marker "L" that precedes an int64 number. More...
 
#define MARKER_NOOP   78
 Marker "N" that signals a no-operation. More...
 
#define MARKER_STR   83
 Marker "S" that precedes a string. More...
 
#define MARKER_TRUE   84
 Marker "T" that signals a true value. More...
 
#define MARKER_UINT8   85
 Marker "L" that precedes an uint8 number. More...
 
#define MARKER_NULL   90
 Marker "Z" that signals a null value. More...
 
#define MARKER_ARRAY_BEGIN   91
 Marker "[" that signals beginning of an array. More...
 
#define MARKER_ARRAY_END   93
 Marker "]" that signals end of an unoptimized array. More...
 
#define MARKER_FLOAT32   100
 Marker "d" that precedes a float32 number. More...
 
#define MARKER_INT8   105
 Marker "i" that precedes an int8 number. More...
 
#define MARKER_INT32   108
 Marker "l" that precedes an int32 number. More...
 
#define MARKER_OBJECT_BEGIN   123
 Marker "[" that signals beginning of an object. More...
 
#define MARKER_OBJECT_END   125
 Marker "]" that signals end of an unoptimized object. More...
 

Typedefs

typedef float float32_t
 Typedef to have consistency in naming all int/float types. More...
 
typedef double float64_t
 Typedef to have consistency in naming all int/float types. More...
 
typedef enum ubjs_bool ubjs_bool
 Wrapper around regular C-like booleans. More...
 
typedef enum ubjs_result ubjs_result
 Enum that defines the result of a method. More...
 
typedef void *(* ubjs_library_alloc_f) (unsigned int len)
 Allocation functor. More...
 
typedef void(* ubjs_library_free_f) (void *ptr)
 Deallocation functor. More...
 
typedef struct ubjs_library ubjs_library
 Library handle. More...
 

Enumerations

enum  ubjs_bool { UFALSE, UTRUE }
 Wrapper around regular C-like booleans. More...
 
enum  ubjs_result { UR_OK, UR_ERROR }
 Enum that defines the result of a method. More...
 

Functions

UBJS_EXPORT ubjs_result ubjs_library_new (ubjs_library_alloc_f alloc, ubjs_library_free_f free, ubjs_library **pthis)
 Initializes the library handle. More...
 
UBJS_EXPORT ubjs_result ubjs_library_new_stdlib (ubjs_library **pthis)
 Initializes the library handle using stdlib's malloc() and free(). More...
 
UBJS_EXPORT ubjs_result ubjs_library_free (ubjs_library **pthis)
 Deinitializes the library handle. More...
 

Detailed Description

Definitions of common types, ubjson markers and some utilities.

Since
0.2

Macro Definition Documentation

§ MARKER_ARRAY_BEGIN

#define MARKER_ARRAY_BEGIN   91

Marker "[" that signals beginning of an array.

Since
0.2

Referenced by ubjs_parser_error_get_message_text().

§ MARKER_ARRAY_END

#define MARKER_ARRAY_END   93

Marker "]" that signals end of an unoptimized array.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_parser_parse().

§ MARKER_CHAR

#define MARKER_CHAR   67

Marker "C" that precedes a character.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_FALSE

#define MARKER_FALSE   70

Marker "F" that signals a false value.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_FLOAT32

#define MARKER_FLOAT32   100

Marker "d" that precedes a float32 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_FLOAT64

#define MARKER_FLOAT64   68

Marker "D" that precedes a float64 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_HPN

#define MARKER_HPN   72

Marker "H" that precedes an high-precision number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_INT16

#define MARKER_INT16   73

Marker "I" that precedes an int16 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_INT32

#define MARKER_INT32   108

Marker "l" that precedes an int32 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_INT64

#define MARKER_INT64   76

Marker "L" that precedes an int64 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_INT8

#define MARKER_INT8   105

Marker "i" that precedes an int8 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_NOOP

#define MARKER_NOOP   78

Marker "N" that signals a no-operation.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_NULL

#define MARKER_NULL   90

Marker "Z" that signals a null value.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_OBJECT_BEGIN

#define MARKER_OBJECT_BEGIN   123

Marker "[" that signals beginning of an object.

Since
0.2

Referenced by ubjs_parser_error_get_message_text().

§ MARKER_OBJECT_END

#define MARKER_OBJECT_END   125

Marker "]" that signals end of an unoptimized object.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_parser_parse().

§ MARKER_OPTIMIZE_COUNT

#define MARKER_OPTIMIZE_COUNT   35

Marker "#" that precedes length of a optimized container.

Since
0.2

Referenced by ubjs_parser_error_get_message_text().

§ MARKER_OPTIMIZE_TYPE

#define MARKER_OPTIMIZE_TYPE   36

Marker "$" that precedes type of a optimized container.

Since
0.2

Referenced by ubjs_parser_error_get_message_text().

§ MARKER_STR

#define MARKER_STR   83

Marker "S" that precedes a string.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_TRUE

#define MARKER_TRUE   84

Marker "T" that signals a true value.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

§ MARKER_UINT8

#define MARKER_UINT8   85

Marker "L" that precedes an uint8 number.

Since
0.2

Referenced by ubjs_parser_error_get_message_text(), and ubjs_writer_print().

Typedef Documentation

§ float32_t

typedef float float32_t

Typedef to have consistency in naming all int/float types.

Since
0.2

§ float64_t

typedef double float64_t

Typedef to have consistency in naming all int/float types.

Since
0.2

§ ubjs_bool

typedef enum ubjs_bool ubjs_bool

Wrapper around regular C-like booleans.

Created for consistency and readibility.

Since
0.2

§ ubjs_library

typedef struct ubjs_library ubjs_library

Library handle.

Since
0.4

§ ubjs_library_alloc_f

typedef void*(* ubjs_library_alloc_f) (unsigned int len)

Allocation functor.

This roughly follows the prototype for malloc().

Parameters
lenLength.
Returns
Allocated pointer.
Since
0.4

§ ubjs_library_free_f

typedef void(* ubjs_library_free_f) (void *ptr)

Deallocation functor.

This roughly follows the prototype for free().

Parameters
ptrAllocated pointer.
Since
0.4

§ ubjs_result

typedef enum ubjs_result ubjs_result

Enum that defines the result of a method.

About 99% methods in ubjs API return ubjs_result, with every output being passed by parameters via pointers. This way every method easily tells whether its operation succeded.

Since
0.2

Enumeration Type Documentation

§ ubjs_bool

enum ubjs_bool

Wrapper around regular C-like booleans.

Created for consistency and readibility.

Since
0.2
Enumerator
UFALSE 

False.

UTRUE 

True.

§ ubjs_result

Enum that defines the result of a method.

About 99% methods in ubjs API return ubjs_result, with every output being passed by parameters via pointers. This way every method easily tells whether its operation succeded.

Since
0.2
Enumerator
UR_OK 

Operation succeded competely.

UR_ERROR 

Invalid input or otherwise errorness result.

Function Documentation

§ ubjs_library_free()

UBJS_EXPORT ubjs_result ubjs_library_free ( ubjs_library **  pthis)

Deinitializes the library handle.

After this returns UR_OK, it is guaranteed that pthis points to 0.

Parameters
pthisPointer to library handle.
Returns
UR_ERROR if any of pthis is not 0, otherwise UR_OK.
Since
0.4

References UR_ERROR, and UR_OK.

§ ubjs_library_new()

UBJS_EXPORT ubjs_result ubjs_library_new ( ubjs_library_alloc_f  alloc,
ubjs_library_free_f  free,
ubjs_library **  pthis 
)

Initializes the library handle.

After this returns UR_OK, it is guaranteed that pthis points to already allocated library handle.

Required for most operations.

Parameters
allocAllocation function.
freeDeallocation function.
pthisPointer to where put new library handle.
Returns
UR_ERROR if any of alloc/free is 0, otherwise UR_OK.
Since
0.4

References UR_ERROR, and UR_OK.

Referenced by ubjs_library_new_stdlib().

Here is the caller graph for this function:

§ ubjs_library_new_stdlib()

UBJS_EXPORT ubjs_result ubjs_library_new_stdlib ( ubjs_library **  pthis)

Initializes the library handle using stdlib's malloc() and free().

After this returns UR_OK, it is guaranteed that pthis points to already allocated library handle.

Required for most operations.

Parameters
pthisPointer to where put new library handle.
Returns
UR_ERROR if universe exploded, otherwise UR_OK.
Since
0.4

References ubjs_library_new().

Here is the call graph for this function: