dmi_fields_encode

Synopsis

#include <opendmi/field.h>

bool dmi_fields_encode(dmi_encoder_t *encoder);

Description

The dmi_fields_encode function writes a structure according to the layout its specification declares, undoing what dmi_fields_decode has done.

Fields are written in the order they are declared, after the header the encoder has written, so that a structure which has not been changed gives back the very bytes it has been decoded from. A specification which declares fields and no encoding handler is encoded by this function, which dmi_entity_encode calls on its own, so it rarely has to be named.

The groups the layout declares decide where the structure ends: in the preserve mode it is written as long as it has been read, and in the canonical one as long as the version the encoder is given says, see dmi_encoder_initialize.

The bytes the layout does not describe, such as the bits the specification reserves and the tails of the records longer than the fields they are known to hold, are written with dmi_encoder_copy: taken from the data the structure has been decoded from in the preserve mode, and written as zeros in the canonical one.

Parameters

encoder

Encoder of the structure, see dmi_encoder_initialize.

Return value

true if the structure has been encoded, false otherwise.

Errors

DMI_ERROR_ARGUMENT_NULL

Encoder is nullptr.

DMI_ERROR_ARGUMENT_INVALID

A field declares a number wider than the widest one the engine reads and writes, which is eight bytes.

DMI_ERROR_STATE_INVALID

Structure is not decoded, its specification declares no fields, or a field it cannot write back, e.g. a conversion without the one undoing it.

DMI_ERROR_INTERNAL

Fields reach another offset than the one declared.

DMI_ERROR_OUT_OF_MEMORY

Buffers of the encoder cannot grow.