Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::CBORObject Class Reference

#include <CBORObject.h>

Classes

class  Array
 Helper class for working with CBOR arrays. More...
 

Public Member Functions

 CBORObject (const CBORObject &)
 Copy constructor (not implemented)
 
CBORObjectoperator= (const CBORObject &)
 Copy assignment operator (not implemented)
 
 CBORObject (Bytes buf)
 Construct a CBORObject from binary CBOR data.
 
 CBORObject ()
 Construct an empty CBORObject.
 
virtual ~CBORObject ()
 Virtual destructor.
 
cn_cbor_errback getLastError ()
 Get the last error that occurred during CBOR operations.
 
bool hasError ()
 
Array putArray (int key)
 Create or get an array at a specific integer key.
 
Array putArray (const char *key)
 Create or get an array at a specific string key.
 
CBORObjectput (int key, int value)
 Put an integer value at a specific integer key.
 
CBORObjectput (int key, uint64_t value)
 Put an unsigned 64-bit integer value at a specific integer key.
 
CBORObjectput (int key, int64_t value)
 Put a 64-bit integer value at a specific integer key.
 
CBORObjectput (int key, const char *value)
 Put a string value at a specific integer key.
 
CBORObjectput (int key, const uint8_t *value, int size)
 Put binary data at a specific integer key.
 
CBORObjectput (const char *key, int value)
 Put an integer value at a specific string key.
 
CBORObjectput (const char *key, uint64_t value)
 Put an unsigned 64-bit integer value at a specific string key.
 
CBORObjectput (const char *key, int64_t value)
 Put a 64-bit integer value at a specific string key.
 
CBORObjectput (const char *key, const char *value)
 Put a string value at a specific string key.
 
CBORObjectput (const char *key, const uint8_t *value, int size)
 Put binary data at a specific string key.
 
CBORObject putMap (const char *key)
 Put a new map at a specific string key, or get the existing one.
 
CBORObject getMap (int key)
 Get a map at a specific integer key.
 
CBORObject getMap (const char *key)
 Get a map at a specific string key.
 
bool getBool (int key) const
 Get a boolean value at a specific integer key.
 
bool getBool (const char *key) const
 Get a boolean value at a specific string key.
 
long getInt (int key) const
 Get an integer value at a specific integer key.
 
long getInt (const char *key) const
 Get an integer value at a specific string key.
 
String getString (int key) const
 Get a string value at a specific integer key.
 
String getString (const char *key) const
 Get a string value at a specific string key.
 
String getValueAsString (int key) const
 Get a value as a string at a specific integer key.
 
String getValueAsString (const char *key) const
 Get a value as a string at a specific string key.
 
Bytes getBytes (int key) const
 Get binary data at a specific integer key.
 
Bytes getBytes (const char *key) const
 Get binary data at a specific string key.
 
void read (const Bytes &buf)
 Read CBOR data from a buffer.
 
Bytes build () const
 Build the CBOR data into binary format.
 
bool isChild () const
 Check if this object is a child node in a CBOR tree.
 
bool dirty () const
 Check if the object has been modified since creation or last read.
 
void forceDirty ()
 Force the object to be marked as dirty (modified)
 
void clean ()
 Reset the object to an empty state.
 

Friends

class COSEMessage
 

Constructor & Destructor Documentation

◆ CBORObject() [1/3]

uniot::CBORObject::CBORObject ( const CBORObject & )
inline

Copy constructor (not implemented)

Parameters
otherThe CBORObject to copy
Note
This constructor logs a warning since copying is not implemented

◆ CBORObject() [2/3]

uniot::CBORObject::CBORObject ( Bytes buf)
inline

Construct a CBORObject from binary CBOR data.

Parameters
bufThe CBOR data in Bytes format

◆ CBORObject() [3/3]

uniot::CBORObject::CBORObject ( )
inline

Construct an empty CBORObject.

Note
Creates an empty CBOR map

◆ ~CBORObject()

virtual uniot::CBORObject::~CBORObject ( )
inlinevirtual

Virtual destructor.

Note
Cleans up resources if this is a root object

Member Function Documentation

◆ build()

Bytes uniot::CBORObject::build ( ) const
inline

Build the CBOR data into binary format.

Parameters
visitSiblingsWhether to include sibling nodes (default is true for root objects)
Return values
BytesThe binary CBOR data

◆ clean()

void uniot::CBORObject::clean ( )
inline

Reset the object to an empty state.

Note
Cleans up resources and creates a new empty CBOR map

◆ dirty()

bool uniot::CBORObject::dirty ( ) const
inline

Check if the object has been modified since creation or last read.

Return values
trueObject is dirty (modified)
falseObject is clean (not modified)

◆ forceDirty()

void uniot::CBORObject::forceDirty ( )
inline

Force the object to be marked as dirty (modified)

Note
This is useful when modifications were made outside the class's interface

◆ getBool() [1/2]

bool uniot::CBORObject::getBool ( const char * key) const
inline

Get a boolean value at a specific string key.

Parameters
keyThe string key
Return values
boolThe boolean value
falseIf the key does not exist or is not a boolean

◆ getBool() [2/2]

bool uniot::CBORObject::getBool ( int key) const
inline

Get a boolean value at a specific integer key.

Parameters
keyThe integer key
Return values
boolThe boolean value
falseIf the key does not exist or is not a boolean

◆ getBytes() [1/2]

Bytes uniot::CBORObject::getBytes ( const char * key) const
inline

Get binary data at a specific string key.

Parameters
keyThe string key
Return values
BytesThe binary data
BytesEmpty if the key does not exist or is not binary data

◆ getBytes() [2/2]

Bytes uniot::CBORObject::getBytes ( int key) const
inline

Get binary data at a specific integer key.

Parameters
keyThe integer key
Return values
BytesThe binary data
BytesEmpty if the key does not exist or is not binary data

◆ getInt() [1/2]

long uniot::CBORObject::getInt ( const char * key) const
inline

Get an integer value at a specific string key.

Parameters
keyThe string key
Return values
longThe integer value
0If the key does not exist or is not an integer

◆ getInt() [2/2]

long uniot::CBORObject::getInt ( int key) const
inline

Get an integer value at a specific integer key.

Parameters
keyThe integer key
Return values
longThe integer value
0If the key does not exist or is not an integer

◆ getLastError()

cn_cbor_errback uniot::CBORObject::getLastError ( )
inline

Get the last error that occurred during CBOR operations.

Return values
errThe error code

◆ getMap() [1/2]

CBORObject uniot::CBORObject::getMap ( const char * key)
inline

Get a map at a specific string key.

Parameters
keyThe string key
Return values
CBORObjectA new CBORObject representing the map
CBORObjectAn empty object if the key does not exist or is not a map

◆ getMap() [2/2]

CBORObject uniot::CBORObject::getMap ( int key)
inline

Get a map at a specific integer key.

Parameters
keyThe integer key
Return values
CBORObjectA new CBORObject representing the map
CBORObjectAn empty object if the key does not exist or is not a map

◆ getString() [1/2]

String uniot::CBORObject::getString ( const char * key) const
inline

Get a string value at a specific string key.

Parameters
keyThe string key
Return values
StringThe string value
""Empty string, if the key does not exist or is not a string

◆ getString() [2/2]

String uniot::CBORObject::getString ( int key) const
inline

Get a string value at a specific integer key.

Parameters
keyThe integer key
Return values
StringThe string value
""Empty string, if the key does not exist or is not a string

◆ getValueAsString() [1/2]

String uniot::CBORObject::getValueAsString ( const char * key) const
inline

Get a value as a string at a specific string key.

Parameters
keyThe string key
Return values
StringThe value converted to a string
""Empty string, if the key does not exist or is not a string
Note
Converts various types (numbers, booleans, strings) to string representation

◆ getValueAsString() [2/2]

String uniot::CBORObject::getValueAsString ( int key) const
inline

Get a value as a string at a specific integer key.

Parameters
keyThe integer key
Return values
StringThe value converted to a string
""Empty string, if the key does not exist or is not a string
Note
Converts various types (numbers, booleans, strings) to string representation

◆ hasError()

bool uniot::CBORObject::hasError ( )
inline

◆ isChild()

bool uniot::CBORObject::isChild ( ) const
inline

Check if this object is a child node in a CBOR tree.

Return values
trueCurrent object is a child of another CBORObject
falseCurrent object is a root CBORObject

◆ operator=()

CBORObject & uniot::CBORObject::operator= ( const CBORObject & )
inline

Copy assignment operator (not implemented)

Parameters
otherThe CBORObject to assign from
Return values
CBORObject&Reference to this object
Note
This operator logs a warning since copying is not implemented

◆ put() [1/10]

CBORObject & uniot::CBORObject::put ( const char * key,
const char * value )
inline

Put a string value at a specific string key.

Parameters
keyThe string key
valueThe string value to store
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [2/10]

CBORObject & uniot::CBORObject::put ( const char * key,
const uint8_t * value,
int size )
inline

Put binary data at a specific string key.

Parameters
keyThe string key
valuePointer to the binary data
sizeSize of the binary data in bytes
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [3/10]

CBORObject & uniot::CBORObject::put ( const char * key,
int value )
inline

Put an integer value at a specific string key.

Parameters
keyThe string key
valueThe integer value to store
Return values
CBORObject&Reference to this object

◆ put() [4/10]

CBORObject & uniot::CBORObject::put ( const char * key,
int64_t value )
inline

Put a 64-bit integer value at a specific string key.

Parameters
keyThe string key
valueThe 64-bit integer value to store
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [5/10]

CBORObject & uniot::CBORObject::put ( const char * key,
uint64_t value )
inline

Put an unsigned 64-bit integer value at a specific string key.

Parameters
keyThe string key
valueThe unsigned 64-bit integer value to store
Return values
CBORObject&Reference to this object

◆ put() [6/10]

CBORObject & uniot::CBORObject::put ( int key,
const char * value )
inline

Put a string value at a specific integer key.

Parameters
keyThe integer key
valueThe string value to store
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [7/10]

CBORObject & uniot::CBORObject::put ( int key,
const uint8_t * value,
int size )
inline

Put binary data at a specific integer key.

Parameters
keyThe integer key
valuePointer to the binary data
sizeSize of the binary data in bytes
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [8/10]

CBORObject & uniot::CBORObject::put ( int key,
int value )
inline

Put an integer value at a specific integer key.

Parameters
keyThe integer key
valueThe integer value to store
Return values
CBORObject&Reference to this object

◆ put() [9/10]

CBORObject & uniot::CBORObject::put ( int key,
int64_t value )
inline

Put a 64-bit integer value at a specific integer key.

Parameters
keyThe integer key
valueThe 64-bit integer value to store
Return values
CBORObject&Reference to this object
Note
Updates the value if the key already exists

◆ put() [10/10]

CBORObject & uniot::CBORObject::put ( int key,
uint64_t value )
inline

Put an unsigned 64-bit integer value at a specific integer key.

Parameters
keyThe integer key
valueThe unsigned 64-bit integer value to store
Return values
CBORObject&Reference to this object

◆ putArray() [1/2]

Array uniot::CBORObject::putArray ( const char * key)
inline

Create or get an array at a specific string key.

Parameters
keyThe string key
Return values
ArrayArray object representing the array
Note
If the key already exists and is an array, returns that array. Otherwise, creates a new array at the key.

◆ putArray() [2/2]

Array uniot::CBORObject::putArray ( int key)
inline

Create or get an array at a specific integer key.

Parameters
keyThe integer key
Return values
ArrayArray object representing the array
Note
If the key already exists and is an array, returns that array. Otherwise, creates a new array at the key.

◆ putMap()

CBORObject uniot::CBORObject::putMap ( const char * key)
inline

Put a new map at a specific string key, or get the existing one.

Parameters
keyThe string key
Return values
CBORObjectA new CBORObject representing the map
Note
If the key already has a map, returns that map

◆ read()

void uniot::CBORObject::read ( const Bytes & buf)
inline

Read CBOR data from a buffer.

Parameters
bufThe buffer containing CBOR data
Note
This operation fails if the object is a child node

Friends And Related Symbol Documentation

◆ COSEMessage

friend class COSEMessage
friend

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