Loading...
Searching...
No Matches
save.c File Reference

Save client's data structure to YAML, using schema. More...

`#include <inttypes.h>`
`#include <stdbool.h>`
`#include <assert.h>`
`#include <limits.h>`
`#include <yaml.h>`
`#include "mem.h"`
`#include "data.h"`
`#include "util.h"`
Include dependency graph for save.c:

## Data Structures

struct | cyaml_state
struct | cyaml_ctx
struct | cyaml_buffer_ctx

## Typedefs

typedef struct cyaml_state | cyaml_state_t
typedef struct cyaml_ctx | cyaml_ctx_t
typedef struct cyaml_buffer_ctx | cyaml_buffer_ctx_t

## Enumerations

enum | cyaml_emit_style { CYAML_EMIT_STYLE_DEFAULT , CYAML_EMIT_STYLE_BLOCK , CYAML_EMIT_STYLE_FLOW }

## Functions

static cyaml_err_t | cyaml__stack_ensure (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__emit_event_helper (const cyaml_ctx_t *ctx, int valid, yaml_event_t *event)
static enum cyaml_emit_style | cyaml__get_emit_style (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema)
static yaml_sequence_style_t | cyaml__get_emit_style_seq (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema)
static yaml_mapping_style_t | cyaml__get_emit_style_map (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema)
static yaml_scalar_style_t | cyaml__get_emit_style_scalar (const cyaml_schema_value_t *schema)
static bool | cyaml__emit_doc_delim (const cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__stack_push_write_event (const cyaml_ctx_t *ctx, enum cyaml_state_e state, const cyaml_schema_value_t *schema)
static cyaml_err_t | cyaml__stack_push (cyaml_ctx_t *ctx, enum cyaml_state_e state, const cyaml_schema_value_t *schema, const cyaml_data_t *data)
static cyaml_err_t | cyaml__stack_pop_write_event (const cyaml_ctx_t *ctx, enum cyaml_state_e state)
static cyaml_err_t | cyaml__stack_pop (cyaml_ctx_t *ctx, bool emit)
static const uint8_t * | cyaml__data_handle_pointer (const cyaml_config_t *config, const cyaml_schema_value_t *schema, const uint8_t *data_in)
static void | cyaml__backtrace (const cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__emit_scalar (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const char *value, const char *tag)
static const char * | cyaml__get_int (int64_t value)
static const char * | cyaml__get_uint (uint64_t value, bool hex)
static const char * | cyaml__get_float (double value)
static const char * | cyaml__get_double (double value)
static int64_t | cyaml_sign_pad (uint64_t raw, size_t size)
static cyaml_err_t | cyaml__write_int (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_uint (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_bool (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_enum (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_float (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_string (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data)
static cyaml_err_t | cyaml__write_scalar_value (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const cyaml_data_t *data)
static cyaml_err_t | cyaml__emit_flags_sequence (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint64_t number)
static cyaml_err_t | cyaml__write_flags_value (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const cyaml_data_t *data)
static cyaml_err_t | cyaml__emit_bitfield_mapping (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, uint64_t number)
static cyaml_err_t | cyaml__write_bitfield_value (const cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const cyaml_data_t *data)
static cyaml_err_t | cyaml__write_value (cyaml_ctx_t *ctx, const cyaml_schema_value_t *schema, const uint8_t *data, uint64_t seq_count)
static cyaml_err_t | cyaml__write_start (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__write_stream (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__write_doc (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__write_mapping (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__write_sequence (cyaml_ctx_t *ctx)
static cyaml_err_t | cyaml__validate_save_params (const cyaml_config_t *config, const cyaml_schema_value_t *schema, const cyaml_data_t *data, unsigned seq_count)
static cyaml_err_t | cyaml__save (const cyaml_config_t *config, const cyaml_schema_value_t *schema, const cyaml_data_t *data, unsigned seq_count, yaml_emitter_t *emitter)
cyaml_err_t | cyaml_save_file (const char *path, const cyaml_config_t *config, const cyaml_schema_value_t *schema, const cyaml_data_t *data, unsigned seq_count)
static int | cyaml__buffer_handler (void *data, unsigned char *buffer, size_t size)
cyaml_err_t | cyaml_save_data (char **output, size_t *len, const cyaml_config_t *config, const cyaml_schema_value_t *schema, const cyaml_data_t *data, unsigned seq_count)

## Detailed Description

Save client's data structure to YAML, using schema.

This uses libyaml to emit YAML documents, it uses the client-provided schema to access the client data, and validates it before emitting the YAML.

## Typedef Documentation

## cyaml_buffer_ctx_t

typedef struct cyaml_buffer_ctx cyaml_buffer_ctx_t

CYAML save buffer context.

## cyaml_ctx_t

typedef struct cyaml_ctx cyaml_ctx_t

Internal YAML saving context.

## cyaml_state_t

typedef struct cyaml_state cyaml_state_t

A CYAML save state machine stack entry.

## Enumeration Type Documentation

## cyaml_emit_style

enum cyaml_emit_style

The style to use when emitting mappings and sequences.

## Function Documentation

## cyaml__backtrace()

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

static

Dump a backtrace to the log.

Parameters

  [in] | ctx | The CYAML saving context.

Todo
  CYAML_STATE_IN_DOC handling for multi document streams.

## cyaml__buffer_handler()

int cyaml__buffer_handler | ( | void * | data,
|  | unsigned char * | buffer,
|  | size_t | size )

static

Write handler for libyaml.

The write handler is called when the emitter needs to flush the accumulated characters to the output. The handler should write size bytes of the buffer to the output.

Todo
  Could be more efficient about this, but for now, this is fine.

Parameters

  [in] | data | A pointer to cyaml buffer context struture.
  [in] | buffer | The buffer with bytes to be written.
  [in] | size | The number of bytes to be written.

Returns
  1 on sucess, 0 otherwise.

## cyaml__data_handle_pointer()

const uint8_t * cyaml__data_handle_pointer | ( | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data_in )

static

Find address of actual value.

If the value has the pointer flag, the pointer is read, otherwise the address is returned unchanged.

Parameters

  [in] | config | The CYAML client configuration object.
  [in] | schema | CYAML schema for the expected value.
  [in] | data_in | The address to read from.

Returns
  New address or for CYAML_FLAG_POINTER, or data_in.

## cyaml__emit_bitfield_mapping()

cyaml_err_t cyaml__emit_bitfield_mapping | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | uint64_t | number )

static

Emit a mapping of bitfield values.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | number | The value of the bitfield data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__emit_doc_delim()

bool cyaml__emit_doc_delim | ( | const cyaml_ctx_t * | ctx | ) |

inline static

Helper to discern whether to emit document delimiting marks.

These are "---" for document start, and "..." for document end.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  true if delimiters should be emitted, false otherwise.

## cyaml__emit_event_helper()

cyaml_err_t cyaml__emit_event_helper | ( | const cyaml_ctx_t * | ctx,
|  | int | valid,
|  | yaml_event_t * | event )

static

Helper to simplify emitting libyaml events.

This is a slightly peculiar function, but it is intended to reduce the boilerplate required to emit events.

Intended usage is something like:

cyaml_err_t err;
yaml_event_t event;
int ret = yaml_mapping_end_event_initialize(&event);
err = cyaml__emit_event_helper(ctx, ret, &event);
cyaml_err_t
enum cyaml_err cyaml_err_t
cyaml__emit_event_helper
static cyaml_err_t cyaml__emit_event_helper(const cyaml_ctx_t *ctx, int valid, yaml_event_t *event)
Definition save.c:119

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | valid | Whether the event pointer is valid. Typically this will be the value returned by the libyaml call that initialised the event. As such, if valid is non-zero, the helper will try to emit the event, otherwise, it will return CYAML_ERR_LIBYAML_EVENT_INIT.
  [in] | event | The event to try to emit, if valid.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__emit_flags_sequence()

cyaml_err_t cyaml__emit_flags_sequence | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | uint64_t | number )

static

Emit a sequence of flag values.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | number | The value of the flag data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__emit_scalar()

cyaml_err_t cyaml__emit_scalar | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const char * | value,
|  | const char * | tag )

static

Helper to emit YAML scalar events, using libyaml.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to emit.
  [in] | value | The value to emit as a null-terminated C string.
  [in] | tag | YAML tag to use for output.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__get_double()

const char * cyaml__get_double | ( | double | value | ) |

static

Get string representation for double precision floating point values.

Parameters

  [in] | value | The value to convert.

Returns
  String conversion of the value.

## cyaml__get_emit_style()

enum cyaml_emit_style cyaml__get_emit_style | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema )

inline static

Get the style to use for mappings/sequences from value flags and config.

As described in the API, schema flags take priority over config flags, and block has precedence over flow, if both flags are set at the same level.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The CYAML schema for the value expected in state.

Returns
  The generic style to emit the value with.

## cyaml__get_emit_style_map()

yaml_mapping_style_t cyaml__get_emit_style_map | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema )

inline static

Get the style to use for mappings from value flags and config.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The CYAML schema for the value expected in state.

Returns
  The libyaml mapping style to emit the value with.

## cyaml__get_emit_style_scalar()

yaml_scalar_style_t cyaml__get_emit_style_scalar | ( | const cyaml_schema_value_t * | schema | ) |

inline static

Get the style to use for scalar values from value flags.

Parameters

  [in] | schema | The CYAML schema for the scaler value to be emitted.

Returns
  The libyaml scalar style to emit the value with.

## cyaml__get_emit_style_seq()

yaml_sequence_style_t cyaml__get_emit_style_seq | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema )

inline static

Get the style to use for sequences from value flags and config.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The CYAML schema for the value expected in state.

Returns
  The libyaml sequence style to emit the value with.

## cyaml__get_float()

const char * cyaml__get_float | ( | double | value | ) |

static

Get string representation for single precision floating point values.

Parameters

  [in] | value | The value to convert.

Returns
  String conversion of the value.

## cyaml__get_int()

const char * cyaml__get_int | ( | int64_t | value | ) |

static

Convert signed integer to string.

Parameters

  [in] | value | The integer to convert.

Returns
  String conversion of the value.

## cyaml__get_uint()

const char * cyaml__get_uint | ( | uint64_t | value,
|  | bool | hex )

static

Convert unsigned integer to string.

Parameters

  [in] | value | The integer to convert.
  [in] | hex | Whether to render the number as hexadecimal.

Returns
  String conversion of the value.

## cyaml__save()

cyaml_err_t cyaml__save | ( | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data,
|  | unsigned | seq_count,
|  | yaml_emitter_t * | emitter )

static

The main YAML saving 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 saved.
  [in] | data | The caller-owned data to be saved.
  [in] | seq_count | If top level type is sequence, this should be the entry count, otherwise it is ignored.
  [in] | emitter | An initialised libyaml emitter object with its output set.

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 save context has space for a new stack entry.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_pop()

cyaml_err_t cyaml__stack_pop | ( | cyaml_ctx_t * | ctx,
|  | bool | emit )

static

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

This frees any resources owned by the stack entry.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | emit | Whether end events should be emitted.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_pop_write_event()

cyaml_err_t cyaml__stack_pop_write_event | ( | const cyaml_ctx_t * | ctx,
|  | enum cyaml_state_e | state )

static

Emit a YAML end event for the state being popped from the stack.

This frees any resources owned by the stack entry.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | state | The CYAML save state we're popping from the stack.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_push()

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

static

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

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | state | The CYAML save state 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 read from.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__stack_push_write_event()

cyaml_err_t cyaml__stack_push_write_event | ( | const cyaml_ctx_t * | ctx,
|  | enum cyaml_state_e | state,
|  | const cyaml_schema_value_t * | schema )

static

Emit a YAML start event for the state being pushed to the stack.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | state | The CYAML save state we're pushing a stack entry for.
  [in] | schema | The CYAML schema for the value expected in state.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__validate_save_params()

cyaml_err_t cyaml__validate_save_params | ( | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data,
|  | unsigned | seq_count )

inline static

Check that common save params from client are valid.

Parameters

  [in] | config | The client's CYAML library config.
  [in] | schema | The schema describing the content of data.
  [in] | data | Points to client's data.
  [in] | seq_count | Top level sequence count.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_bitfield_value()

cyaml_err_t cyaml__write_bitfield_value | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data )

static

Write a value of type CYAML_BITFIELD.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_bool()

cyaml_err_t cyaml__write_bool | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_BOOL.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_doc()

cyaml_err_t cyaml__write_doc | ( | cyaml_ctx_t * | ctx | ) |

static

YAML saving handler for the CYAML_STATE_IN_DOC state.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_enum()

cyaml_err_t cyaml__write_enum | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_ENUM.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_flags_value()

cyaml_err_t cyaml__write_flags_value | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data )

static

Write a value of type CYAML_FLAGS.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_float()

cyaml_err_t cyaml__write_float | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_FLOAT.

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 saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_int()

cyaml_err_t cyaml__write_int | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_INT.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_mapping()

cyaml_err_t cyaml__write_mapping | ( | cyaml_ctx_t * | ctx | ) |

static

YAML saving handler for the CYAML_STATE_IN_MAP_KEY and CYAML_STATE_IN_MAP_VALUE states.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_scalar_value()

cyaml_err_t cyaml__write_scalar_value | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data )

static

Write a scalar value.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_sequence()

cyaml_err_t cyaml__write_sequence | ( | cyaml_ctx_t * | ctx | ) |

static

YAML saving handler for the CYAML_STATE_IN_SEQUENCE state.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_start()

cyaml_err_t cyaml__write_start | ( | cyaml_ctx_t * | ctx | ) |

static

YAML saving handler for the CYAML_STATE_START state.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_stream()

cyaml_err_t cyaml__write_stream | ( | cyaml_ctx_t * | ctx | ) |

static

YAML saving handler for the CYAML_STATE_IN_STREAM state.

Parameters

  [in] | ctx | The CYAML saving context.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_string()

cyaml_err_t cyaml__write_string | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_STRING.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_uint()

cyaml_err_t cyaml__write_uint | ( | const cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data )

static

Write a value of type CYAML_UINT.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | The schema for the value to be written.
  [in] | data | The place to read the value from in the client data.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml__write_value()

cyaml_err_t cyaml__write_value | ( | cyaml_ctx_t * | ctx,
|  | const cyaml_schema_value_t * | schema,
|  | const uint8_t * | data,
|  | uint64_t | seq_count )

static

Emit the YAML events required for a CYAML value.

Parameters

  [in] | ctx | The CYAML saving context.
  [in] | schema | CYAML schema for the expected value.
  [in] | data | The place to read the value from in the client data.
  [in] | seq_count | Entry count for sequence values. Unused for non-sequence values.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml_save_data()

cyaml_err_t cyaml_save_data | ( | char ** | output,
|  | size_t * | len,
|  | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data,
|  | unsigned | seq_count )

Save a YAML document into a string in memory.

This allocates a buffer containing the serialised YAML data.

To free the returned YAML string, clients should use the cyaml_mem_fn_t function set in the cyaml_config_t passed to this function. For example:

char *yaml;
size_t len;
err = cyaml_save_file(&yaml, &len, &config, &client_schema, client_data, 0);
if (err == CYAML_OK) {
// Use `yaml`:
printf("%*s\n", len, yaml);
// Free `yaml`:
config.mem_fn(config.mem_ctx, yaml, 0);
}
cyaml_save_file
cyaml_err_t cyaml_save_file(const char *path, const cyaml_config_t *config, const cyaml_schema_value_t *schema, const cyaml_data_t *data, unsigned seq_count)
Definition save.c:1377
CYAML_OK
@ CYAML_OK
Definition cyaml.h:586

Note
  The returned YAML string does not have a trailing '\0'.

Parameters

  [out] | output | Returns the caller-owned serialised YAML data on success, untouched on failure. Clients should use the cyaml_mem_fn_t function set in the cyaml_config_t to free the data.
  [out] | len | Returns the length of the data in output on success, untouched on failure.
  [in] | config | Client's CYAML configuration structure.
  [in] | schema | CYAML schema for the YAML to be saved.
  [in] | data | The caller-owned data to be saved.
  [in] | seq_count | If top level type is sequence, this should be the entry count, otherwise it is ignored.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml_save_file()

cyaml_err_t cyaml_save_file | ( | const char * | path,
|  | const cyaml_config_t * | config,
|  | const cyaml_schema_value_t * | schema,
|  | const cyaml_data_t * | data,
|  | unsigned | seq_count )

Save a YAML document to a file at the given path.

Parameters

  [in] | path | Path to YAML file to write.
  [in] | config | Client's CYAML configuration structure.
  [in] | schema | CYAML schema for the YAML to be saved.
  [in] | data | The caller-owned data to be saved.
  [in] | seq_count | If top level type is sequence, this should be the entry count, otherwise it is ignored.

Returns
  CYAML_OK on success, or appropriate error code otherwise.

## cyaml_sign_pad()

int64_t cyaml_sign_pad | ( | uint64_t | raw,
|  | size_t | size )

static

Pad a signed value that's smaller than 64-bit to an int64_t.

This sets all the bits in the padded region.

Parameters

  [in] | raw | Contains a signed value of size bytes.
  [in] | size | Number of bytes used in raw.

Returns
  Value padded to 64-bit signed.