Loading...
Searching...
No Matches
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_t * | cyaml_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

typedef struct cyaml_event_ctx 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

typedef struct cyaml_event_record 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

typedef struct cyaml_event_replay 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

enum cyaml_event

CYAML events. These correspond to libyaml events.

## Function Documentation

## cyaml__backtrace()

void cyaml__backtrace | ( | cyaml_ctx_t * | ctx | ) |

static

Dump a backtrace to the log.

Parameters

  [in] | ctx | The CYAML loading context.

Todo
  CYAML_STATE_IN_DOC handling for multi document streams.

## cyaml__consume_ignored_value()

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] | ctx | The CYAML loading context.
  [in] | cyaml_event | The event for the value to ignore.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__current_event()

const yaml_event_t * cyaml__current_event | ( | const cyaml_ctx_t * | ctx | ) |

inline static

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] | ctx | The CYAML loading context.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__data_handle_pointer()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for value to get data pointer for.
  [in] | event | The YAML event value to get data pointer for.
  [in,out] | value_data_io | Current 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()

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] | ctx | The CYAML loading context.

## cyaml__doc_end()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__doc_root_value()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__doc_start()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__free_recording()

void cyaml__free_recording | ( | cyaml_ctx_t * | ctx | ) |

static

Free any recordings from the CYAML loading context.

Parameters

  [in] | ctx | The CYAML loading context.

## cyaml__get_bitval_index()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [out] | index_out | Returns bitdefs index on success.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__get_event_type()

cyaml_event_t cyaml__get_event_type | ( | const yaml_event_t * | event | ) |

inline static

Get the CYAML event type from a libyaml event.

Parameters

  [in] | event | The libyaml event.

Returns
  corresponding CYAML event.

## cyaml__get_mapping_field_count()

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_schema | Array of mapping schema fields.

Returns
  Number of entries in mapping_schema array.

## cyaml__get_mapping_field_idx()

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

inline static

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

Parameters

  [in] | cfg | The client's CYAML library config.
  [in] | schema | CYAML schema for the mapping value to be loaded.
  [in] | key | Key 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()

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

static

Get the anchor name for an alias event.

Parameters

  [in] | event | The libyaml event.

Returns
  String representing event's aliased anchor name.

## cyaml__get_yaml_event_anchor()

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] | event | The libyaml event.

Returns
  String representing event's anchor, or NULL.

## cyaml__handle_alias()

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] | ctx | The CYAML loading context.
  [in] | event | The libyaml event.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__handle_anchor()

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] | ctx | The CYAML loading context.
  [in] | event | The libyaml event to handle any anchor for.
  [out] | is_anchor_out | Returns whether the event creates an anchor.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__handle_record()

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] | ctx | The CYAML loading context.
  [in] | event | The libyaml to record.
  [in] | replayed_event | Whether this event is a replay.
  [in] | replay_event_index | Index in events array of replayed event.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__handle_replay()

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] | ctx | The CYAML loading context.
  [out] | event_out | The libyaml event to fill from the recording.
  [out] | event_index_out | The index in events array of the replayed event.

## cyaml__is_sequence()

bool cyaml__is_sequence | ( | const cyaml_schema_value_t * | schema | ) |

inline static

Helper to check if schema is for a CYAML_SEQUENCE type.

Parameters

  [in] | schema | The schema entry for a type.

Returns
  true iff schema is for a CYAML_SEQUENCE type, false otherwise.

## cyaml__libyaml_event_type_str()

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

static

Convert a libyaml event to a human readable string.

Parameters

  [in] | event | The libyaml event.

Returns
  String representing event.

## cyaml__load()

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] | config | Client's CYAML configuration structure.
  [in] | schema | CYAML schema for the YAML to be loaded.
  [out] | data_out | Returns the caller-owned loaded data on success. Untouched on failure.
  [out] | seq_count_out | On 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] | parser | An initialised libyaml parser object with its input set.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__load_event()

cyaml_err_t cyaml__load_event | ( | cyaml_ctx_t * | ctx,
|  | const yaml_event_t * | event )

inline static

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__log_ignored_key()

void cyaml__log_ignored_key | ( | const cyaml_ctx_t * | ctx,
|  | const char * | key )

inline static

Log an ignored mapping key.

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | key | The key that has been ignored.

## cyaml__map_end()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__map_key()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__map_key_check_field()

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] | ctx | The CYAML loading context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__map_value()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__mapping_bitfieid_check()

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] | ctx | The CYAML loading context.

## cyaml__mapping_bitfieid_create()

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] | ctx | The CYAML loading context.
  [in] | state | CYAML load state for a CYAML_STATE_IN_MAP_KEY state.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__mapping_bitfieid_destroy()

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] | ctx | The CYAML loading context.
  [in] | state | CYAML load state for a CYAML_STATE_IN_MAP_KEY state.

## cyaml__mapping_bitfieid_set()

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] | ctx | The CYAML loading context.

## cyaml__mapping_bitfieid_validate()

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] | ctx | The CYAML loading context.

Returns
  CYAML_OK if all required fields are present, or CYAML_ERR_MAPPING_FIELD_MISSING any are missing.

## cyaml__new_anchor()

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] | ctx | The CYAML loading context.
  [in,out] | anchors_count | Count of anchors in array. Updated on success.
  [in,out] | anchors | Anchors array, updated on success.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__read_bitfield_value()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_bool()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_enum()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_flags_value()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_float()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_int()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_scalar_value()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | data | The place to write the value in the output data.
  [in] | event | The libyaml event providing the scalar value data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_string()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_uint()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in] | data | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_uint64_t()

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

inline static

Helper to read a number into a uint64_t.

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | value | String containing scaler value.
  [in] | out | The place to write the value in the output data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__read_value()

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] | ctx | The CYAML loading context.
  [in] | schema | CYAML schema for the expected value.
  [in] | data | Pointer to where value's data should be written.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__record_stack_pop()

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] | ctx | The CYAML loading context.
  [in] | event_index | The current event's index in the recording.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__record_stack_push()

cyaml_err_t cyaml__record_stack_push | ( | cyaml_ctx_t * | ctx,
|  | uint32_t | event_index )

static

Push a recording stack context entry.

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | event_index | The current event's index in the recording.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__seq_end()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__seq_entry()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__set_bitval()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in,out] | bits_out | Current bits, updated on success.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__set_flag()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be read.
  [in] | value | String containing scaler value.
  [in,out] | flags_out | Current flags, updated on success.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_ensure()

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] | ctx | The CYAML loading context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_pop()

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] | ctx | The CYAML loading context.

## cyaml__stack_push()

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] | ctx | The CYAML loading context.
  [in] | state | The CYAML load state we're pushing a stack entry for.
  [in] | event | The YAML event we're pushing a stack entry for.
  [in] | schema | The CYAML schema for the value expected in state.
  [in] | data | Pointer to where value's data should be written.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__store_bool()

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

inline static

Store a boolean to client data structure according to schema.

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be stored.
  [in] | location | The place to write the value in the output data.
  [in] | value | The value to store.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__store_float()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be stored.
  [in] | location | The place to write the value in the output data.
  [in] | value | The value to store.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__store_int()

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

inline static

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

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be stored.
  [in] | location | The place to write the value in the output data.
  [in] | value | The value to store.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__store_string()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be stored.
  [in] | location | The place to write the value in the output data.
  [in] | value | The value to store.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__store_uint()

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

inline static

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

Parameters

  [in] | ctx | The CYAML loading context.
  [in] | schema | The schema for the value to be stored.
  [in] | location | The place to write the value in the output data.
  [in] | value | The value to store.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stream_end()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stream_start()

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] | ctx | The CYAML loading context.
  [in] | event | The YAML event to handle.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__string_is_null_ptr()

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] | schema | CYAML schema for the value to test.
  [in] | value | String value to test.

Returns
  true if string represents a NULL, false otherwise.

## cyaml__update_anchor_recordings()

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] | ctx | The CYAML loading context.
  [in] | event_index | The current event's index in the recording.
  [in] | event | The libyaml event to fill from the recording.

Returns
  CYAML_OK on success, or appropriate error otherwise.

## cyaml__validate_event_type_for_schema()

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] | ctx | The CYAML loading context.
  [in] | schema | The schema for value that the event belongs to.
  [in] | event | The event to be checked.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__validate_load_params()

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 )

inline static

Check that common load parameters from client are valid.

Parameters

  [in] | config | The client's CYAML library config.
  [in] | schema | The schema describing the content of data.
  [in] | data_tgt | Points to client's address to write data to.
  [in] | seq_count_tgt | Points to client's address to write sequence count.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml_get_next_event()

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] | ctx | The 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] | input | Buffer to load YAML data from.
  [in] | input_len | Length of input in bytes.
  [in] | config | Client's CYAML configuration structure.
  [in] | schema | CYAML schema for the YAML to be loaded.
  [out] | data_out | Returns the caller-owned loaded data on success. Untouched on failure.
  [out] | seq_count_out | On 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] | path | Path to YAML file to load.
  [in] | config | Client's CYAML configuration structure.
  [in] | schema | CYAML schema for the YAML to be loaded.
  [out] | data_out | Returns the caller-owned loaded data on success. Untouched on failure.
  [out] | seq_count_out | On 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()

const cyaml_schema_field_t * cyaml_mapping_schema_field | ( | const cyaml_ctx_t * | ctx | ) |

inline static

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] | ctx | The CYAML loading context.

Returns
  Current mapping field's schema entry.