Schemas provide a way to validate the structure of Reduct association lists and transform them into native C structures.
|
| REDUCT_API void | reduct_schema_global_init (reduct_schema_global_t *global) |
| | Initialize a global schema state.
|
| |
| REDUCT_API void | reduct_schema_global_deinit (reduct_schema_global_t *global) |
| | Deinitialize a global schema state.
|
| |
| REDUCT_API reduct_schema_id_t | reduct_schema_new (struct reduct *reduct, size_t count,...) |
| | Create a new schema.
|
| |
| REDUCT_API reduct_schema_id_t | reduct_schema_new_fields (struct reduct *reduct, size_t count, const reduct_schema_t *fields) |
| | Create a new schema from an array of fields.
|
| |
| REDUCT_API void | reduct_schema_apply (struct reduct *reduct, reduct_schema_id_t id, reduct_handle_t listH, void *out) |
| | Apply a schema to an association list and populate a C structure.
|
| |
| REDUCT_API size_t | reduct_schema_get_count (struct reduct *reduct, reduct_schema_id_t id) |
| | Get the number of fields in a schema.
|
| |
| REDUCT_API reduct_handle_t | reduct_schema_serialize (struct reduct *reduct, reduct_schema_id_t id, const void *in) |
| | Transform a C structure into an association list using a schema.
|
| |
◆ REDUCT_SCHEMA_INDEX_NONE
Invalid schema index.
Definition at line 65 of file schema.h.
◆ REDUCT_SCHEMA_FIELD
| #define REDUCT_SCHEMA_FIELD |
( |
|
_key, |
|
|
|
_struct, |
|
|
|
_member, |
|
|
|
_type |
|
) |
| |
Value: (
reduct_schema_t){(_key), offsetof(_struct, _member),
sizeof(((_struct*)0)->_member), REDUCT_SCHEMA_TYPE_##_type, \
0, 0}
Helper macro to define a schema field.
- Parameters
-
| _key | The key string in the association list. |
| _struct | The C structure type. |
| _member | The member name in the C structure. |
| _type | The reduct_schema_type_t of the field, only the suffix is required, REDUCT_SCHEMA_TYPE_ is added automatically. |
Definition at line 154 of file schema.h.
◆ REDUCT_SCHEMA_FIELD_ARRAY
| #define REDUCT_SCHEMA_FIELD_ARRAY |
( |
|
_key, |
|
|
|
_struct, |
|
|
|
_member, |
|
|
|
_subtype |
|
) |
| |
Value:
{ \
REDUCT_SCHEMA_TYPE_##_subtype, sizeof(((_struct*)0)->_member[0]) \
}
@ REDUCT_SCHEMA_TYPE_ARRAY
A fixed-size array of primitives.
Helper macro to define an array schema field.
- Parameters
-
| _key | The key string. |
| _struct | The C structure type. |
| _member | The array member name. |
| _type | The reduct_schema_type_t of the field, only the suffix is required, REDUCT_SCHEMA_TYPE_ is added automatically. |
Definition at line 167 of file schema.h.
◆ reduct_schema_id_t
Schema ID type.
Definition at line 61 of file schema.h.
◆ reduct_schema_index_t
Schema index type.
Definition at line 63 of file schema.h.
◆ reduct_schema_type_t
Schema type flags.
| Enumerator |
|---|
| REDUCT_SCHEMA_TYPE_UINT | Unsigned integer.
|
| REDUCT_SCHEMA_TYPE_INT | Signed integer.
|
| REDUCT_SCHEMA_TYPE_FLOAT | Float or double.
|
| REDUCT_SCHEMA_TYPE_BOOL | A bool.
|
| REDUCT_SCHEMA_TYPE_STRING | An array of characters.
|
| REDUCT_SCHEMA_TYPE_HANDLE | A reduct_handle_t.
|
| REDUCT_SCHEMA_TYPE_ARRAY | A fixed-size array of primitives.
|
Definition at line 26 of file schema.h.
◆ reduct_schema_global_init()
Initialize a global schema state.
- Parameters
-
| global | Pointer to the global schema state to initialize. |
◆ reduct_schema_global_deinit()
Deinitialize a global schema state.
- Parameters
-
| global | Pointer to the global schema state to deinitialize. |
◆ reduct_schema_new()
Create a new schema.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| count | Number of fields. |
| ... | Variadic arguments for specifying the fields. |
- Returns
- The ID of the newly created schema.
◆ reduct_schema_new_fields()
Create a new schema from an array of fields.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| count | Number of fields. |
| fields | Array of field definitions. |
- Returns
- The ID of the newly created schema.
◆ reduct_schema_apply()
Apply a schema to an association list and populate a C structure.
Any fields not explicitly set by the given list are guaranteed to be left untouched.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| id | The ID of the schema to apply. |
| listH | The handle to the association list. |
| out | Pointer to the destination C structure. |
◆ reduct_schema_get_count()
Get the number of fields in a schema.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| id | The schema ID. |
- Returns
- The number of fields, or 0 if the ID is invalid.
◆ reduct_schema_serialize()
Transform a C structure into an association list using a schema.
- Parameters
-
| reduct | Pointer to the Reduct structure. |
| id | The ID of the schema to use. |
| in | Pointer to the source C structure. |
- Returns
- A handle to the newly created association list.