dmi_writer_initialize

Synopsis

#include <opendmi/writer.h>

bool dmi_writer_initialize(
        dmi_writer_t *writer,
        dmi_buffer_t *buffer,
        size_t        offset,
        ssize_t       length);

Description

The dmi_writer_initialize function sets the writer up over the range beginning at offset within buffer. The cursor is positioned at the beginning of the range, which the data is written into and past: a range beginning at the end of the buffer appends to it, and one beginning within the data written already writes over it.

A writer writes bytes into a range of a dmi_buffer_t, which holds them, the way dmi_reader_t reads them out of one. What the bytes stand for is of no concern to the writer: the caller writes the structures, the entry points and whatever else the data is made of. Writing the values of a structure is what dmi_encoder_t does over a writer, see dmi_encoder_initialize.

A range of a length of its own is one which something else follows, such as a record of a declared length or an area of a fixed size, and the writer refuses to write past it rather than writing over whatever comes next. A negative length gives a range bounded by nothing but the data itself.

The writer holds no memory of its own, so there is nothing to destroy: the data belongs to the buffer and outlives the writers of it.

Parameters

writer

Writer to initialize.

buffer

Buffer to write the data into.

offset

Offset the range begins at within the buffer.

length

Number of the bytes the range holds at most, or a negative number for a range of no length of its own.

Return value

true on success, false if writer or buffer is nullptr, or if the buffer holds fewer bytes than offset.

Errors

None.