CYAML Internals
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
load.c File Reference

Load YAML data into client's data structure. More...

#include <inttypes.h>
#include <stdbool.h>
#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <float.h>
#include <math.h>
#include <yaml.h>
#include "mem.h"
#include "data.h"
#include "util.h"
Include dependency graph for load.c:

Data Structures

struct  cyaml_state
 
struct  cyaml_anchor
 
struct  cyaml_event_record
 
struct  cyaml_event_replay
 
struct  cyaml_event_ctx
 
struct  cyaml_ctx
 

Macros

#define CYAML_FIELDS_IDX_NONE   0xffff
 

Typedefs

typedef enum cyaml_event cyaml_event_t
 
typedef struct cyaml_state cyaml_state_t
 
typedef struct cyaml_anchor cyaml_anchor_t
 
typedef struct cyaml_event_record cyaml_event_record_t
 
typedef struct cyaml_event_replay cyaml_event_replay_t
 
typedef struct cyaml_event_ctx cyaml_event_ctx_t
 
typedef struct cyaml_ctx cyaml_ctx_t
 

Enumerations

enum  cyaml_event {
  CYAML_EVT_NO_EVENT = YAML_NO_EVENT , CYAML_EVT_STRM_START = YAML_STREAM_START_EVENT , CYAML_EVT_STRM_END = YAML_STREAM_END_EVENT , CYAML_EVT_DOC_START = YAML_DOCUMENT_START_EVENT ,
  CYAML_EVT_DOC_END = YAML_DOCUMENT_END_EVENT , CYAML_EVT_ALIAS = YAML_ALIAS_EVENT , CYAML_EVT_SCALAR = YAML_SCALAR_EVENT , CYAML_EVT_SEQ_START = YAML_SEQUENCE_START_EVENT ,
  CYAML_EVT_SEQ_END = YAML_SEQUENCE_END_EVENT , CYAML_EVT_MAP_START = YAML_MAPPING_START_EVENT , CYAML_EVT_MAP_END = YAML_MAPPING_END_EVENT , CYAML_EVT__COUNT
}
 

Functions

static cyaml_err_t cyaml__store_int (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *location, int64_t value)
 
static cyaml_err_t cyaml__store_uint (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *location, uint64_t value)
 
static cyaml_err_t cyaml__store_bool (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *location, bool value)
 
static cyaml_err_t cyaml__store_float (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *location, double value)
 
static cyaml_err_t cyaml__store_string (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *location, const char *value)
 
static cyaml_event_t cyaml__get_event_type (const yaml_event_t *event)
 
static const char * cyaml__libyaml_event_type_str (const yaml_event_t *event)
 
static const char * cyaml__get_yaml_event_anchor (const yaml_event_t *event)
 
static const char * cyaml__get_yaml_event_alias (const yaml_event_t *event)
 
static cyaml_err_t cyaml__handle_alias (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__new_anchor (cyaml_ctx_t *ctx, uint32_t *anchors_count, cyaml_anchor_t **anchors)
 
static cyaml_err_t cyaml__handle_anchor (cyaml_ctx_t *ctx, const yaml_event_t *event, bool *is_anchor_out)
 
static cyaml_err_t cyaml__record_stack_push (cyaml_ctx_t *ctx, uint32_t event_index)
 
static cyaml_err_t cyaml__record_stack_pop (cyaml_ctx_t *ctx, uint32_t event_index)
 
static cyaml_err_t cyaml__update_anchor_recordings (cyaml_ctx_t *ctx, uint32_t event_index, const yaml_event_t *event)
 
static cyaml_err_t cyaml__handle_record (cyaml_ctx_t *ctx, const yaml_event_t *event, bool replayed_event, uint32_t replay_event_index)
 
static void cyaml__handle_replay (cyaml_ctx_t *ctx, yaml_event_t *event_out, uint32_t *event_index_out)
 
static void cyaml__delete_yaml_event (cyaml_ctx_t *ctx)
 
static void cyaml__free_recording (cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml_get_next_event (cyaml_ctx_t *ctx)
 
static const yaml_event_t * cyaml__current_event (const cyaml_ctx_t *ctx)
 
static uint16_t cyaml__get_mapping_field_idx (const cyaml_config_t *cfg, const cyaml_schema_value_t *schema, const char *key)
 
static const cyaml_schema_field_tcyaml_mapping_schema_field (const cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml__stack_ensure (cyaml_ctx_t *ctx)
 
static uint16_t cyaml__get_mapping_field_count (const cyaml_schema_field_t *mapping_schema)
 
static cyaml_err_t cyaml__mapping_bitfieid_create (cyaml_ctx_t *ctx, cyaml_state_t *state)
 
static void cyaml__mapping_bitfieid_destroy (const cyaml_ctx_t *ctx, cyaml_state_t *state)
 
static void cyaml__mapping_bitfieid_set (const cyaml_ctx_t *ctx)
 
static bool cyaml__mapping_bitfieid_check (const cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml__mapping_bitfieid_validate (const cyaml_ctx_t *ctx)
 
static bool cyaml__is_sequence (const cyaml_schema_value_t *schema)
 
static cyaml_err_t cyaml__stack_push (cyaml_ctx_t *ctx, enum cyaml_state_e state, const yaml_event_t *event, const cyaml_schema_value_t *schema, cyaml_data_t *data)
 
static void cyaml__stack_pop (cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml__validate_event_type_for_schema (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const yaml_event_t *event)
 
static cyaml_err_t cyaml__data_handle_pointer (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const yaml_event_t *event, uint8_t **value_data_io)
 
static void cyaml__backtrace (cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml__read_int (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_uint64_t (const cyaml_ctx_t *ctx, const char *value, uint64_t *out)
 
static cyaml_err_t cyaml__read_uint (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_bool (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_enum (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_float (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_string (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint8_t *data)
 
static cyaml_err_t cyaml__read_scalar_value (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, cyaml_data_t *data, const yaml_event_t *event)
 
static cyaml_err_t cyaml__set_flag (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, uint64_t *flags_out)
 
static cyaml_err_t cyaml__read_flags_value (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, cyaml_data_t *data)
 
static cyaml_err_t cyaml__get_bitval_index (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint32_t *index_out)
 
static cyaml_err_t cyaml__set_bitval (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint64_t *bits_out)
 
static cyaml_err_t cyaml__read_bitfield_value (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, cyaml_data_t *data)
 
static cyaml_err_t cyaml__consume_ignored_value (cyaml_ctx_t *ctx, cyaml_event_t cyaml_event)
 
static bool cyaml__string_is_null_ptr (const cyaml_schema_value_t *schema, const char *value)
 
static cyaml_err_t cyaml__read_value (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint8_t *data, const yaml_event_t *event)
 
static cyaml_err_t cyaml__stream_start (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__doc_start (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__stream_end (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__doc_root_value (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__doc_end (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static void cyaml__log_ignored_key (const cyaml_ctx_t *ctx, const char *key)
 
static cyaml_err_t cyaml__map_key_check_field (const cyaml_ctx_t *ctx)
 
static cyaml_err_t cyaml__map_key (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__map_end (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__map_value (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__seq_entry (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__seq_end (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__validate_load_params (const cyaml_config_t *config, const cyaml_schema_value_t *schema, cyaml_data_t *const *data_tgt, const unsigned *seq_count_tgt)
 
static cyaml_err_t cyaml__load_event (cyaml_ctx_t *ctx, const yaml_event_t *event)
 
static cyaml_err_t cyaml__load (const cyaml_config_t *config, const cyaml_schema_value_t *schema, cyaml_data_t **data_out, unsigned *seq_count_out, yaml_parser_t *parser)
 
cyaml_err_t cyaml_load_file (const char *path, const cyaml_config_t *config, const cyaml_schema_value_t *schema, cyaml_data_t **data_out, unsigned *seq_count_out)
 
cyaml_err_t cyaml_load_data (const uint8_t *input, size_t input_len, const cyaml_config_t *config, const cyaml_schema_value_t *schema, cyaml_data_t **data_out, unsigned *seq_count_out)
 

Detailed Description

Load YAML data into client's data structure.

This uses libyaml to parse YAML documents, it validates the documents against the client provided schema, and uses the schema to place the data in the client's data structure.

Macro Definition Documentation

◆ CYAML_FIELDS_IDX_NONE

#define CYAML_FIELDS_IDX_NONE   0xffff

Identifies that no mapping schema entry was found for key.

Typedef Documentation

◆ cyaml_anchor_t

typedef struct cyaml_anchor cyaml_anchor_t

Anchor data.

This is used to track the progress of recording the anchor's events, and then the data is referenced during replay.

◆ cyaml_ctx_t

typedef struct cyaml_ctx cyaml_ctx_t

Internal YAML loading context.

◆ cyaml_event_ctx_t

CYAML's LibYAML event context.

Only cyaml_get_next_event and friends should poke around inside here. Everything else should use cyaml__current_event to access the current event data, and call cyaml_get_next_event to pump the event stream.

◆ cyaml_event_record_t

Event recording context.

This records anchor details, and any anchored events. A stack of events is maintained to keep track of matching start/end events, in order to end anchor recordings with the correct end event.

◆ cyaml_event_replay_t

Event replay context.

◆ cyaml_event_t

typedef enum cyaml_event cyaml_event_t

CYAML events. These correspond to libyaml events.

◆ cyaml_state_t

typedef struct cyaml_state cyaml_state_t

A CYAML load state machine stack entry.

Enumeration Type Documentation

◆ cyaml_event

CYAML events. These correspond to libyaml events.

Function Documentation

◆ cyaml__backtrace()

static void cyaml__backtrace ( cyaml_ctx_t ctx)
static

Dump a backtrace to the log.

Parameters
[in]ctxThe CYAML loading context.
Todo:
CYAML_STATE_IN_DOC handling for multi document streams.

◆ cyaml__consume_ignored_value()

static cyaml_err_t cyaml__consume_ignored_value ( cyaml_ctx_t ctx,
cyaml_event_t  cyaml_event 
)
static

Entirely consume an ignored value.

This ignores all the descendants of the value, e.g. if the ignored key's value is of type CYAML_IGNORE, all of the following is ignored:

ignored:
- foo: 7
bar: 9
- foo: 1
bar: 2
Parameters
[in]ctxThe CYAML loading context.
[in]cyaml_eventThe event for the value to ignore.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__current_event()

static const yaml_event_t * cyaml__current_event ( const cyaml_ctx_t ctx)
inlinestatic

Get a pointer to the load context's current event.

The outside world should use this to get the address of the event data, which will not change for subsequent events. The event should only be used after cyaml_get_next_event() has returned CYAML_OK.

Parameters
[in]ctxThe CYAML loading context.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__data_handle_pointer()

static cyaml_err_t cyaml__data_handle_pointer ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const yaml_event_t *  event,
uint8_t **  value_data_io 
)
static

Helper to make allocations for loaded YAML values.

If the current state is sequence, this extends any existing allocation for the sequence.

The current CYAML loading context's state is updated with new allocation address, where necessary.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for value to get data pointer for.
[in]eventThe YAML event value to get data pointer for.
[in,out]value_data_ioCurrent address of value's data. Updated to new address if value is allocation requiring an allocation.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__delete_yaml_event()

static void cyaml__delete_yaml_event ( cyaml_ctx_t ctx)
static

Delete any current event from the load context.

This gets the next event from the CYAML load context's libyaml parser object.

Parameters
[in]ctxThe CYAML loading context.

◆ cyaml__doc_end()

static cyaml_err_t cyaml__doc_end ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for finalising the CYAML_STATE_IN_DOC state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__doc_root_value()

static cyaml_err_t cyaml__doc_root_value ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for the root value in the CYAML_STATE_IN_DOC state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__doc_start()

static cyaml_err_t cyaml__doc_start ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for documents in the CYAML_STATE_IN_STREAM state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__free_recording()

static void cyaml__free_recording ( cyaml_ctx_t ctx)
static

Free any recordings from the CYAML loading context.

Parameters
[in]ctxThe CYAML loading context.

◆ cyaml__get_bitval_index()

static cyaml_err_t cyaml__get_bitval_index ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint32_t *  index_out 
)
static

Get bitfield component index for name in a CYAML_BITFIELD value.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[out]index_outReturns bitdefs index on success.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__get_event_type()

static cyaml_event_t cyaml__get_event_type ( const yaml_event_t *  event)
inlinestatic

Get the CYAML event type from a libyaml event.

Parameters
[in]eventThe libyaml event.
Returns
corresponding CYAML event.

◆ cyaml__get_mapping_field_count()

static uint16_t cyaml__get_mapping_field_count ( const cyaml_schema_field_t mapping_schema)
static

Count the entries in a mapping field array schema.

The mapping schema array must be terminated by an entry with a NULL key.

Parameters
[in]mapping_schemaArray of mapping schema fields.
Returns
Number of entries in mapping_schema array.

◆ cyaml__get_mapping_field_idx()

static uint16_t cyaml__get_mapping_field_idx ( const cyaml_config_t cfg,
const cyaml_schema_value_t schema,
const char *  key 
)
inlinestatic

Get the offset to a mapping field by key in a mapping schema array.

Parameters
[in]cfgThe client's CYAML library config.
[in]schemaCYAML schema for the mapping value to be loaded.
[in]keyKey to search for in mapping schema.
Returns
index the mapping schema's mapping fields array for key, or CYAML_FIELDS_IDX_NONE if key is not present in schema.

◆ cyaml__get_yaml_event_alias()

static const char * cyaml__get_yaml_event_alias ( const yaml_event_t *  event)
static

Get the anchor name for an alias event.

Parameters
[in]eventThe libyaml event.
Returns
String representing event's aliased anchor name.

◆ cyaml__get_yaml_event_anchor()

static const char * cyaml__get_yaml_event_anchor ( const yaml_event_t *  event)
static

Get the anchor name for an event, or NULL if the event isn't an anchor.

Parameters
[in]eventThe libyaml event.
Returns
String representing event's anchor, or NULL.

◆ cyaml__handle_alias()

static cyaml_err_t cyaml__handle_alias ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

Handle an alias event.

This searches the know anchors for a match. If a matching anchor is found, it sets the replay context up to play back the recorded events associated with the anchor, setting the replay state to active.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe libyaml event.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__handle_anchor()

static cyaml_err_t cyaml__handle_anchor ( cyaml_ctx_t ctx,
const yaml_event_t *  event,
bool *  is_anchor_out 
)
static

Handle an event that establishes an anchor.

This should not be called while replaying recorded events, or it will try to rebuild anchors we already have.

This is a no-op if the event doesn't establish an anchor. If the event does create an anchor, an anchor entry is added to the recording context.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe libyaml event to handle any anchor for.
[out]is_anchor_outReturns whether the event creates an anchor.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__handle_record()

static cyaml_err_t cyaml__handle_record ( cyaml_ctx_t ctx,
const yaml_event_t *  event,
bool  replayed_event,
uint32_t  replay_event_index 
)
static

Handle the recording of the current event.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe libyaml to record.
[in]replayed_eventWhether this event is a replay.
[in]replay_event_indexIndex in events array of replayed event.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__handle_replay()

static void cyaml__handle_replay ( cyaml_ctx_t ctx,
yaml_event_t *  event_out,
uint32_t *  event_index_out 
)
static

Handle the current event replay.

There must be an active replay before this is called. If this call yields the final event of the anchor, the replay state is disabled.

Parameters
[in]ctxThe CYAML loading context.
[out]event_outThe libyaml event to fill from the recording.
[out]event_index_outThe index in events array of the replayed event.

◆ cyaml__is_sequence()

static bool cyaml__is_sequence ( const cyaml_schema_value_t schema)
inlinestatic

Helper to check if schema is for a CYAML_SEQUENCE type.

Parameters
[in]schemaThe schema entry for a type.
Returns
true iff schema is for a CYAML_SEQUENCE type, false otherwise.

◆ cyaml__libyaml_event_type_str()

static const char * cyaml__libyaml_event_type_str ( const yaml_event_t *  event)
static

Convert a libyaml event to a human readable string.

Parameters
[in]eventThe libyaml event.
Returns
String representing event.

◆ cyaml__load()

static cyaml_err_t cyaml__load ( const cyaml_config_t config,
const cyaml_schema_value_t schema,
cyaml_data_t **  data_out,
unsigned *  seq_count_out,
yaml_parser_t *  parser 
)
static

The main YAML loading function.

The public interfaces are wrappers around this.

Parameters
[in]configClient's CYAML configuration structure.
[in]schemaCYAML schema for the YAML to be loaded.
[out]data_outReturns the caller-owned loaded data on success. Untouched on failure.
[out]seq_count_outOn success, returns the sequence entry count. Untouched on failure. Must be non-NULL if top-level schema type is CYAML_SEQUENCE, otherwise, must be NULL.
[in]parserAn initialised libyaml parser object with its input set.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__load_event()

static cyaml_err_t cyaml__load_event ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
inlinestatic

YAML loading helper dispatch function.

Dispatches events to the appropriate event handler function for the current combination of load state machine state (from the load context) and event type.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__log_ignored_key()

static void cyaml__log_ignored_key ( const cyaml_ctx_t ctx,
const char *  key 
)
inlinestatic

Log an ignored mapping key.

Parameters
[in]ctxThe CYAML loading context.
[in]keyThe key that has been ignored.

◆ cyaml__map_end()

static cyaml_err_t cyaml__map_end ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for finalising the CYAML_STATE_IN_MAP_KEY state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__map_key()

static cyaml_err_t cyaml__map_key ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for new mapping fields in the CYAML_STATE_IN_MAP_KEY state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__map_key_check_field()

static cyaml_err_t cyaml__map_key_check_field ( const cyaml_ctx_t ctx)
static

Check the field against the schema for the current mapping key.

Parameters
[in]ctxThe CYAML loading context.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__map_value()

static cyaml_err_t cyaml__map_value ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for the CYAML_STATE_IN_MAP_VALUE state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__mapping_bitfieid_check()

static bool cyaml__mapping_bitfieid_check ( const cyaml_ctx_t ctx)
static

Check the bit for current mapping's current field.

Current CYAML load state must be CYAML_STATE_IN_MAP_KEY.

Parameters
[in]ctxThe CYAML loading context.

◆ cyaml__mapping_bitfieid_create()

static cyaml_err_t cyaml__mapping_bitfieid_create ( cyaml_ctx_t ctx,
cyaml_state_t state 
)
static

Create CYAML_STATE_IN_MAP_KEY state's bitfield array allocation.

The bitfield is used to record whether the mapping as all the required fields by mapping schema array index.

Parameters
[in]ctxThe CYAML loading context.
[in]stateCYAML load state for a CYAML_STATE_IN_MAP_KEY state.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__mapping_bitfieid_destroy()

static void cyaml__mapping_bitfieid_destroy ( const cyaml_ctx_t ctx,
cyaml_state_t state 
)
static

Destroy a CYAML_STATE_IN_MAP_KEY state's bitfield array allocation.

Parameters
[in]ctxThe CYAML loading context.
[in]stateCYAML load state for a CYAML_STATE_IN_MAP_KEY state.

◆ cyaml__mapping_bitfieid_set()

static void cyaml__mapping_bitfieid_set ( const cyaml_ctx_t ctx)
static

Set the bit for the current mapping's current field, to indicate it exists.

Current CYAML load state must be CYAML_STATE_IN_MAP_KEY.

Parameters
[in]ctxThe CYAML loading context.

◆ cyaml__mapping_bitfieid_validate()

static cyaml_err_t cyaml__mapping_bitfieid_validate ( const cyaml_ctx_t ctx)
static

Check a mapping had all the required fields.

Checks all the bits are set in the bitfield, which correspond to entries in the mapping schema array which are not marked with the CYAML_FLAG_OPTIONAL flag.

Current CYAML load state must be CYAML_STATE_IN_MAP_KEY.

Parameters
[in]ctxThe CYAML loading context.
Returns
CYAML_OK if all required fields are present, or CYAML_ERR_MAPPING_FIELD_MISSING any are missing.

◆ cyaml__new_anchor()

static cyaml_err_t cyaml__new_anchor ( cyaml_ctx_t ctx,
uint32_t *  anchors_count,
cyaml_anchor_t **  anchors 
)
static

Create new anchor entry at the end of an anchors array.

Parameters
[in]ctxThe CYAML loading context.
[in,out]anchors_countCount of anchors in array. Updated on success.
[in,out]anchorsAnchors array, updated on success.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__read_bitfield_value()

static cyaml_err_t cyaml__read_bitfield_value ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
cyaml_data_t data 
)
static

Read a value of type CYAML_BITFIELD.

Since CYAML_FLAGS is a composite value (a mapping), rather than a simple scaler, this consumes events from the YAML input stream.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_bool()

static cyaml_err_t cyaml__read_bool ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Read a value of type CYAML_BOOL.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_enum()

static cyaml_err_t cyaml__read_enum ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Read a value of type CYAML_ENUM.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_flags_value()

static cyaml_err_t cyaml__read_flags_value ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
cyaml_data_t data 
)
static

Read a value of type CYAML_FLAGS.

Since CYAML_FLAGS is a composite value (a sequence of scalars), rather than a simple scaler, this consumes events from the YAML input stream.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_float()

static cyaml_err_t cyaml__read_float ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Helper to read CYAML_FLOAT values.

The data_size of the schema entry must be the size of a known floating point C type.

Note
The long double type was causing problems, so it isn't currently supported.
Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_int()

static cyaml_err_t cyaml__read_int ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Read a value of type CYAML_INT.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_scalar_value()

static cyaml_err_t cyaml__read_scalar_value ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
cyaml_data_t data,
const yaml_event_t *  event 
)
static

Read a scalar value.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]dataThe place to write the value in the output data.
[in]eventThe libyaml event providing the scalar value data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_string()

static cyaml_err_t cyaml__read_string ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Read a value of type CYAML_STRING.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_uint()

static cyaml_err_t cyaml__read_uint ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint8_t *  data 
)
static

Read a value of type CYAML_UINT.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in]dataThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_uint64_t()

static cyaml_err_t cyaml__read_uint64_t ( const cyaml_ctx_t ctx,
const char *  value,
uint64_t *  out 
)
inlinestatic

Helper to read a number into a uint64_t.

Parameters
[in]ctxThe CYAML loading context.
[in]valueString containing scaler value.
[in]outThe place to write the value in the output data.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__read_value()

static cyaml_err_t cyaml__read_value ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  data,
const yaml_event_t *  event 
)
static

Handle a YAML event corresponding to a YAML data value.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaCYAML schema for the expected value.
[in]dataPointer to where value's data should be written.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__record_stack_pop()

static cyaml_err_t cyaml__record_stack_pop ( cyaml_ctx_t ctx,
uint32_t  event_index 
)
static

Pop a recording stack context entry.

Any actively recording anchors are checked, and if this event ends the anchor, the anchor recording is moved from the progress array to the complete array.

Parameters
[in]ctxThe CYAML loading context.
[in]event_indexThe current event's index in the recording.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__record_stack_push()

static cyaml_err_t cyaml__record_stack_push ( cyaml_ctx_t ctx,
uint32_t  event_index 
)
static

Push a recording stack context entry.

Parameters
[in]ctxThe CYAML loading context.
[in]event_indexThe current event's index in the recording.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__seq_end()

static cyaml_err_t cyaml__seq_end ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for finalising the CYAML_STATE_IN_SEQUENCE state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__seq_entry()

static cyaml_err_t cyaml__seq_entry ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for new sequence entries in the CYAML_STATE_IN_SEQUENCE state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__set_bitval()

static cyaml_err_t cyaml__set_bitval ( cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint64_t *  bits_out 
)
static

Set some bits in a CYAML_BITFIELD value.

If the given bit value name is one expected by the schema, then this function consumes an event from the YAML input stream.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in,out]bits_outCurrent bits, updated on success.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__set_flag()

static cyaml_err_t cyaml__set_flag ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const char *  value,
uint64_t *  flags_out 
)
static

Set a flag in a CYAML_FLAGS value.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be read.
[in]valueString containing scaler value.
[in,out]flags_outCurrent flags, updated on success.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__stack_ensure()

static cyaml_err_t cyaml__stack_ensure ( cyaml_ctx_t ctx)
static

Ensure that the CYAML load context has space for a new stack entry.

Parameters
[in]ctxThe CYAML loading context.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__stack_pop()

static void cyaml__stack_pop ( cyaml_ctx_t ctx)
static

Pop the current entry on the CYAML load context's stack.

This frees any resources owned by the stack entry.

Parameters
[in]ctxThe CYAML loading context.

◆ cyaml__stack_push()

static cyaml_err_t cyaml__stack_push ( cyaml_ctx_t ctx,
enum cyaml_state_e  state,
const yaml_event_t *  event,
const cyaml_schema_value_t schema,
cyaml_data_t data 
)
static

Push a new entry onto the CYAML load context's stack.

Parameters
[in]ctxThe CYAML loading context.
[in]stateThe CYAML load state we're pushing a stack entry for.
[in]eventThe YAML event we're pushing a stack entry for.
[in]schemaThe CYAML schema for the value expected in state.
[in]dataPointer to where value's data should be written.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__store_bool()

static cyaml_err_t cyaml__store_bool ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  location,
bool  value 
)
inlinestatic

Store a boolean to client data structure according to schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be stored.
[in]locationThe place to write the value in the output data.
[in]valueThe value to store.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__store_float()

static cyaml_err_t cyaml__store_float ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  location,
double  value 
)
static

Store a floating point value to client data structure according to schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be stored.
[in]locationThe place to write the value in the output data.
[in]valueThe value to store.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__store_int()

static cyaml_err_t cyaml__store_int ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  location,
int64_t  value 
)
inlinestatic

Store a signed integer to client data structure according to schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be stored.
[in]locationThe place to write the value in the output data.
[in]valueThe value to store.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__store_string()

static cyaml_err_t cyaml__store_string ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  location,
const char *  value 
)
static

Store a string value to client data structure according to schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be stored.
[in]locationThe place to write the value in the output data.
[in]valueThe value to store.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__store_uint()

static cyaml_err_t cyaml__store_uint ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
uint8_t *  location,
uint64_t  value 
)
inlinestatic

Store an unsigned integer to client data structure according to schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for the value to be stored.
[in]locationThe place to write the value in the output data.
[in]valueThe value to store.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__stream_end()

static cyaml_err_t cyaml__stream_end ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for finalising the CYAML_STATE_IN_STREAM state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__stream_start()

static cyaml_err_t cyaml__stream_start ( cyaml_ctx_t ctx,
const yaml_event_t *  event 
)
static

YAML loading handler for start of stream in the CYAML_STATE_START state.

Parameters
[in]ctxThe CYAML loading context.
[in]eventThe YAML event to handle.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__string_is_null_ptr()

static bool cyaml__string_is_null_ptr ( const cyaml_schema_value_t schema,
const char *  value 
)
static

Check whether a string represents a NULL value.

Parameters
[in]schemaCYAML schema for the value to test.
[in]valueString value to test.
Returns
true if string represents a NULL, false otherwise.

◆ cyaml__update_anchor_recordings()

static cyaml_err_t cyaml__update_anchor_recordings ( cyaml_ctx_t ctx,
uint32_t  event_index,
const yaml_event_t *  event 
)
static

Update the anchor data in the recording context.

Parameters
[in]ctxThe CYAML loading context.
[in]event_indexThe current event's index in the recording.
[in]eventThe libyaml event to fill from the recording.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml__validate_event_type_for_schema()

static cyaml_err_t cyaml__validate_event_type_for_schema ( const cyaml_ctx_t ctx,
const cyaml_schema_value_t schema,
const yaml_event_t *  event 
)
static

Validate the current event for what's expected by the schema.

Parameters
[in]ctxThe CYAML loading context.
[in]schemaThe schema for value that the event belongs to.
[in]eventThe event to be checked.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml__validate_load_params()

static cyaml_err_t cyaml__validate_load_params ( const cyaml_config_t config,
const cyaml_schema_value_t schema,
cyaml_data_t *const *  data_tgt,
const unsigned *  seq_count_tgt 
)
inlinestatic

Check that common load parameters from client are valid.

Parameters
[in]configThe client's CYAML library config.
[in]schemaThe schema describing the content of data.
[in]data_tgtPoints to client's address to write data to.
[in]seq_count_tgtPoints to client's address to write sequence count.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml_get_next_event()

static cyaml_err_t cyaml_get_next_event ( cyaml_ctx_t ctx)
static

Helper function to read the next YAML input event into the context.

This handles recording the events associated with anchors, and replaying them when an alias event references a valid anchor. If we are not replaying anchored events, this gets the next event from the CYAML load context's libyaml parser object.

Any existing event in the load context is deleted first.

Callers do not always need to delete the previous event from the context before calling this function. However, after the final call, when cleaning up the context, any event must be deleted with a single call to cyaml__delete_yaml_event.

Parameters
[in]ctxThe CYAML loading context.
Returns
CYAML_OK on success, or appropriate error otherwise.

◆ cyaml_load_data()

cyaml_err_t cyaml_load_data ( const uint8_t *  input,
size_t  input_len,
const cyaml_config_t config,
const cyaml_schema_value_t schema,
cyaml_data_t **  data_out,
unsigned *  seq_count_out 
)

Load a YAML document from a data buffer.

Note
In the event of the top-level mapping having only optional fields, and the YAML not setting any of them, this function can return CYAML_OK, and NULL in the data_out parameter.
Parameters
[in]inputBuffer to load YAML data from.
[in]input_lenLength of input in bytes.
[in]configClient's CYAML configuration structure.
[in]schemaCYAML schema for the YAML to be loaded.
[out]data_outReturns the caller-owned loaded data on success. Untouched on failure.
[out]seq_count_outOn success, returns the sequence entry count. Untouched on failure. Must be non-NULL if top-level schema type is CYAML_SEQUENCE, otherwise, must be NULL.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml_load_file()

cyaml_err_t cyaml_load_file ( const char *  path,
const cyaml_config_t config,
const cyaml_schema_value_t schema,
cyaml_data_t **  data_out,
unsigned *  seq_count_out 
)

Load a YAML document from a file at the given path.

Note
In the event of the top-level mapping having only optional fields, and the YAML not setting any of them, this function can return CYAML_OK, and NULL in the data_out parameter.
Parameters
[in]pathPath to YAML file to load.
[in]configClient's CYAML configuration structure.
[in]schemaCYAML schema for the YAML to be loaded.
[out]data_outReturns the caller-owned loaded data on success. Untouched on failure.
[out]seq_count_outOn success, returns the sequence entry count. Untouched on failure. Must be non-NULL if top-level schema type is CYAML_SEQUENCE, otherwise, must be NULL.
Returns
CYAML_OK on success, or appropriate error code otherwise.

◆ cyaml_mapping_schema_field()

static const cyaml_schema_field_t * cyaml_mapping_schema_field ( const cyaml_ctx_t ctx)
inlinestatic

Helper to get the current mapping field.

Note
The current load state must be CYAML_STATE_IN_MAP_KEY, or CYAML_STATE_IN_MAP_VALUE, and there must be a current field index in the state.
Parameters
[in]ctxThe CYAML loading context.
Returns
Current mapping field's schema entry.