SatCat5
satcat5::cbor::ListWriterStatic< SIZE > Class Template Reference

Detailed Description

template<unsigned SIZE = SATCAT5_QCBOR_BUFFER>
class satcat5::cbor::ListWriterStatic< SIZE >

ListWriter variant with a statically-allocated buffer.

Most users should instantiate this instead of ListWriter. Optional template parameter specifies buffer size.

Write a series of consecutive items to a CBOR message.

See also
satcat5::ListWriterStatic, satcat5::cbor::MapWriter

Creates an ephemeral writer for the Concise Binary Object Representation (CBOR, IETF RFC8949), holding underlying objects and adapting output to an io::Writeable destination. This writer wraps the QCBOR library into a more familiar interface that performs stack buffer allocation and io::Writeable handling automatically. Since CBOR key/value pairs and arrays require a length prefix, QCBOR requires a working buffer to hold the in-progress object, which is stack-allocated with size SATCAT5_QCBOR_BUFFER.

Most users should be able to hit target functionality with usage of cbor::MapWriter or other future wrappers. However, the QCBOR encode context cbor is a public member variable that may be used for calls to QCBOREncode_* functions for complex use-cases outside the scope of given wrapper classes.

Usage:

Most users should instantiate CborMapWriterStatic instead of this to perform all stack buffer allocation.

See also
satcat5::cbor::ListWriter, satcat5::cbor::MapWriter.

Definition at line 403 of file io_cbor.h.

#include <io_cbor.h>

Inheritance diagram for satcat5::cbor::ListWriterStatic< SIZE >:
[legend]
Collaboration diagram for satcat5::cbor::ListWriterStatic< SIZE >:
[legend]

Public Member Functions

 ListWriterStatic (satcat5::io::Writeable *dst=nullptr)
 Create this object and set the destination. More...
 
QCBOREncodeContext * open_list ()
 Add a nested list to the List. More...
 
QCBOREncodeContext * open_map ()
 Add a nested dictionary to the List. More...
 
void add_string (const char *value) const
 Write a null-terminated string to the Map.
 
void add_null () const
 Write a key with a null value to the Map.
 
bool close ()
 Close the QCBOR encoder by calling QCBOREncode_Finish and copy the resulting bytes to m_dst, if one was provided.
 
bool close_and_finalize ()
 Calls close() then m_dst.write_finalize().
 
UsefulBufC get_encoded ()
 Get encoded data as a UsefulBuf, useful if no dst was given. More...
 
satcat5::io::Readableget_buffer ()
 Get encoded data as a Readable, useful if no dst was given. More...
 
void close_list ()
 Finish writing a list to the List. More...
 
void close_map ()
 Finish writing a nested dictionary to the Map. More...
 
void add_bool (bool value) const
 Write a scalar value to the List.
 
void add_item (s8 value) const
 Write a scalar value to the List.
 
void add_item (s16 value) const
 Write a scalar value to the List.
 
void add_item (s32 value) const
 Write a scalar value to the List.
 
void add_item (s64 value) const
 Write a scalar value to the List.
 
void add_item (u8 value) const
 Write a scalar value to the List.
 
void add_item (u16 value) const
 Write a scalar value to the List.
 
void add_item (u32 value) const
 Write a scalar value to the List.
 
void add_item (u64 value) const
 Write a scalar value to the List.
 
void add_item (float value) const
 Write a scalar value to the List.
 
void add_item (double value) const
 Write a scalar value to the List.
 
void add_array (u32 len, const bool *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const s8 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const s16 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const s32 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const s64 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const u8 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const u16 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const u32 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const u64 *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const float *value) const
 Write an array of scalar values to the List.
 
void add_array (u32 len, const double *value) const
 Write an array of scalar values to the List.
 
void add_bytes (u32 len, const u8 *value) const
 Write a byte sequence to the List.
 
void add_bytes (const u8 *value, u32 len) const
 Write a byte sequence to the List.
 

Public Attributes

QCBOREncodeContext *const cbor
 QCBOR context pointer.
 

Protected Member Functions

template<typename T >
void add_unsigned_array (unsigned len, const T *value) const
 Templated function to add an array of unsigned values.
 
template<typename T >
void add_signed_array (unsigned len, const T *value) const
 Templated function to add an array of signed values.
 

Protected Attributes

satcat5::io::Writeable *const m_dst
 Writeable sink.
 
const u8 * m_encoded
 Encoded data.
 
unsigned m_encoded_len
 Encoded length.
 
u8 m_auto_close
 Auto-close QCBOR Type.
 
satcat5::io::ArrayRead m_read
 Reads working buffer.
 

Private Attributes

QCBOREncodeContext m_cbor
 
u8 m_raw [SIZE]
 

Constructor & Destructor Documentation

◆ ListWriterStatic()

template<unsigned SIZE = SATCAT5_QCBOR_BUFFER>
satcat5::cbor::ListWriterStatic< SIZE >::ListWriterStatic ( satcat5::io::Writeable dst = nullptr)
inlineexplicit

Create this object and set the destination.

Parameters
dstWriteable destination, or NULL if child classes will access the buffer directly after close().

Definition at line 408 of file io_cbor.h.

Member Function Documentation

◆ close_list()

void satcat5::cbor::CborWriter::close_list ( )
inlineinherited

Finish writing a list to the List.

When closing a List, the caller may use the original object that opened it or another CborWriter derived from the same context.

See also
ListWriter::open_list, MapWriter::open_list.

Definition at line 113 of file io_cbor.h.

◆ close_map()

void satcat5::cbor::CborWriter::close_map ( )
inlineinherited

Finish writing a nested dictionary to the Map.

When closing a Map, the caller may use the original object that opened it or another CborWriter derived from the same context.

See also
ListWriter::open_map, MapWriter::open_map.

Definition at line 120 of file io_cbor.h.

◆ get_buffer()

Readable * satcat5::cbor::CborWriter::get_buffer ( )
inherited

Get encoded data as a Readable, useful if no dst was given.

Automatically calls close() if the buffer is still open.

Definition at line 56 of file io_cbor.cc.

◆ get_encoded()

UsefulBufC satcat5::cbor::CborWriter::get_encoded ( )
inherited

Get encoded data as a UsefulBuf, useful if no dst was given.

Automatically calls close() if the buffer is still open.

Definition at line 51 of file io_cbor.cc.

◆ open_list()

QCBOREncodeContext * satcat5::cbor::ListWriter::open_list ( )
inherited

Add a nested list to the List.

See also
close_list. This allows creation of a sub-item containing an array or list of items with various type(s). The user should call open_list(), write value(s) as desired, then call close_map().

Definition at line 143 of file io_cbor.cc.

◆ open_map()

QCBOREncodeContext * satcat5::cbor::ListWriter::open_map ( )
inherited

Add a nested dictionary to the List.

See also
close_map. Append a self-contained key/value dictionary. The user should call open_map(), write key/value pairs, then call close_map().

Definition at line 161 of file io_cbor.cc.


The documentation for this class was generated from the following file: