Functions in this module convert schema syntax into schema objects.
Example Workflow
Create a schema object from schema syntax:
const char syntax[] =
"InsertOrder/1 ->\n"
" string Symbol,\n"
" string OrderId,\n"
" u32 Price,\n"
" u32 Quantity\n";
To operate on the "InsertOrder" group we need to get a reference to it:
It's also possible to get a reference to "InsertOrder" by its group ID:
While not very useful in this example, it is possible to read attributes from a group like so:
To access the fields of a group you will need a field iterator. An iterator is composed of an array of schema references, one entry for this group plus any inherited supergroups. Where the memory is stored depends on your requirements for the lifetime of the iterator - below we use a VLA.
Below is an example of accessing field definitions sequentally using the iterator:
|
enum | blink_type_tag {
BLINK_TYPE_STRING = 0,
BLINK_TYPE_BINARY,
BLINK_TYPE_FIXED,
BLINK_TYPE_BOOL,
BLINK_TYPE_U8,
BLINK_TYPE_U16,
BLINK_TYPE_U32,
BLINK_TYPE_U64,
BLINK_TYPE_I8,
BLINK_TYPE_I16,
BLINK_TYPE_I32,
BLINK_TYPE_I64,
BLINK_TYPE_F64,
BLINK_TYPE_DATE,
BLINK_TYPE_TIME_OF_DAY_MILLI,
BLINK_TYPE_TIME_OF_DAY_NANO,
BLINK_TYPE_NANO_TIME,
BLINK_TYPE_MILLI_TIME,
BLINK_TYPE_DECIMAL,
BLINK_TYPE_OBJECT,
BLINK_TYPE_ENUM,
BLINK_TYPE_STATIC_GROUP,
BLINK_TYPE_DYNAMIC_GROUP
} |
| A field shall represent one of the following types. More...
|
|
struct blink_field_iterator |
A field iterator stores state required to iterate through all fields of a group (including any inherited fields)
Data Fields |
blink_schema_t * |
field |
stack of pointers to fields within groups |
size_t |
index |
current index in field |
struct blink_group_iterator |
A field shall represent one of the following types.
Enumerator |
---|
BLINK_TYPE_STRING |
UTF8 encoded string.
|
BLINK_TYPE_BINARY |
octet string
|
BLINK_TYPE_FIXED |
fixed size string
|
BLINK_TYPE_BOOL |
boolean
|
BLINK_TYPE_U8 |
8 bit unsigned integer
|
BLINK_TYPE_U16 |
16 bit unsigned integer
|
BLINK_TYPE_U32 |
32 bit unsigned integer
|
BLINK_TYPE_U64 |
64 bit unsigned integer
|
BLINK_TYPE_I8 |
8 bit signed integer
|
BLINK_TYPE_I16 |
16 bit signed integer
|
BLINK_TYPE_I32 |
32 bit signed integer
|
BLINK_TYPE_I64 |
64 bit signed integer
|
BLINK_TYPE_F64 |
IEEE 754 double.
|
BLINK_TYPE_DATE |
days since 2000-01-01
|
BLINK_TYPE_TIME_OF_DAY_MILLI |
milliseconds since midnight
|
BLINK_TYPE_TIME_OF_DAY_NANO |
nanoseconds since midnight
|
BLINK_TYPE_NANO_TIME |
nanoseconds since (or before) 1970-01-01 00:00:00.000000000
|
BLINK_TYPE_MILLI_TIME |
milliseconds since (or before) 1970-01-01 00:00:00.000000000
|
BLINK_TYPE_DECIMAL |
8 bit signed integer exponent, 64 bit signed integer mantissa
|
BLINK_TYPE_OBJECT |
any group encoded as dynamic group
|
BLINK_TYPE_ENUM |
32 bit signed integer
|
BLINK_TYPE_STATIC_GROUP |
static group
|
BLINK_TYPE_DYNAMIC_GROUP |
dynamic group
|
Find enum symbol by name.
- Parameters
-
[in] | self | enum object |
[in] | name | null terminated name string |
- Returns
- symbol
- Return values
-
Find enum symbol by value.
- Parameters
-
[in] | self | enum object |
[in] | value | |
- Returns
- symbol
- Return values
-
Get enum (nested within field)
- Note
- relevant if field type is BLINK_TYPE_ENUM
- Parameters
-
- Returns
- enum
- Return values
-
Get field name.
- Parameters
-
- Returns
- null terminated string
Get field type.
- Parameters
-
- Returns
- field type
Discover if field is optional.
- Parameters
-
- Returns
- Is field optional?
- Return values
-
Discover if field is a sequence.
- Parameters
-
- Returns
- Is field a sequence?
- Return values
-
Create field iterator object.
Use the returned object to iterate through group fields.
- Parameters
-
[in] | stack | an array of references which must be maintained for same lifetime as iterator object |
[in] | depth | dimension of stack |
To iterate through all inherited fields depth
must be equal to (BLINK_Group_getAncestorCount(self) + 1U).
To iterate only through the subgroup depth
must be 1U.
- Returns
- field iterator
Get next field from a field iterator.
- Parameters
-
- Returns
- field
- Return values
-
NULL | no next field in group |
Get next field from a field iterator but do not change the iterator state.
- Parameters
-
- Returns
- field
- Return values
-
NULL | no next field in group |
Get group ID.
- Note
- only valid if BLINK_GroupHasID returns true
- Parameters
-
- Returns
- ID
Get group name (within namespace)
- Parameters
-
- Returns
- null terminated name
Get group namespace.
- Parameters
-
- Returns
- namespace
Discover if group has a valid ID.
- Note
- groups which do not have an ID cannot be serialised as a dynamic group
- Parameters
-
- Returns
- Does group have an ID?
- Return values
-
Test if self is group or a subclass of group.
- Parameters
-
[in] | self | group object |
[in] | group | |
- Returns
- is self a kind of group?
- Return values
-
- Examples:
- tc_blink_group_iskindof.c.
Return the number of supergroups this group inherits from.
- Parameters
-
- Returns
- number of supergroups
Get symbol name.
- Parameters
-
- Returns
- NULL null terminated string
Get symbol value.
- Parameters
-
- Returns
- signed 32 bit integer