Dev Essential
Loading...
Searching...
No Matches
ddl::codec::Codec Class Reference

#include <codec.h>

Inherits ddl::codec::Decoder.

Public Types

typedef CodecElement< CodecElementAccess< Codec > > Element
 
typedef ChildElements< CodecElementAccess< Codec > > Elements
 
- Public Types inherited from ddl::codec::Decoder
typedef DecoderElement< DecoderElementAccess< const Decoder > > Element
 
typedef ChildElements< DecoderElementAccess< const Decoder > > Elements
 
- Public Types inherited from ddl::codec::StaticDecoder
typedef DecoderElement< DecoderElementAccess< const StaticDecoder > > Element
 
typedef ChildElements< DecoderElementAccess< const StaticDecoder > > Elements
 

Public Member Functions

 Codec ()
 
 Codec (Codec &&)
 
Codecoperator= (Codec &&)
 
 Codec (const Codec &)=delete
 
Codecoperator= (const Codec &)=delete
 
Element getElement (const CodecIndex &codec_index)
 
Element getElement (std::string_view full_path)
 
Element getChildElement (const CodecIndex &parent_codec_index, std::string_view relative_path)
 
ElementsgetElements ()
 
template<typename T>
void setElementValue (const CodecIndex &codec_index, const T &value)
 
template<typename T>
void setElementValue (const LeafCodecIndex &leaf_codec_index, const T &value)
 
void setElementVariantValue (const CodecIndex &codec_index, const a_util::variant::Variant &value)
 
void setElementStringValue (const CodecIndex &codec_index, const std::string &value)
 
void setElementRawValue (const CodecIndex &codec_index, const void *value, size_t value_size)
 
void * getElementAddress (const CodecIndex &codec_index)
 
void resetValues (bool zero_values=false)
 
void * getData () noexcept
 Get the current set data.
 
Element getElement (const CodecIndex &codec_index) const
 
Element getElement (std::string_view full_path) const
 
const ElementsgetElements () const
 
- Public Member Functions inherited from ddl::codec::Decoder
 Decoder ()
 
 Decoder (Decoder &&)
 
Decoderoperator= (Decoder &&)
 
 Decoder (const Decoder &)=delete
 
Decoderoperator= (const Decoder &)=delete
 
a_util::result::Result isValid () const override
 
Element getElement (const CodecIndex &codec_index) const
 
Element getElement (std::string_view full_path) const
 
Element getChildElement (const CodecIndex &parent_codec_index, std::string_view relative_path) const
 
const ElementsgetElements () const
 
size_t getBufferSize () const
 Gets the buffer size in bytes for the main structure.
 
size_t getBufferSize (DataRepresentation representation) const
 Gets the buffer size in bytes for the main structure.
 
Codec makeCodecFor (void *data, size_t data_size, DataRepresentation representation) const
 
- Public Member Functions inherited from ddl::codec::StaticDecoder
 ~StaticDecoder ()=default
 DTOR.
 
 StaticDecoder ()
 
 StaticDecoder (const StaticDecoder &)=delete
 
StaticDecoderoperator= (const StaticDecoder &)=delete
 
 StaticDecoder (StaticDecoder &&)
 
StaticDecoderoperator= (StaticDecoder &&)
 
Element getElement (const CodecIndex &codec_index) const
 
Element getElement (std::string_view full_path) const
 
Element getChildElement (const CodecIndex &parent_codec_index, std::string_view relative_path) const
 
const ElementsgetElements () const
 
size_t getElementChildCount (const CodecIndex &codec_index=CodecIndex()) const
 
std::string getElementFullName (const CodecIndex &codec_index) const
 Retrieves the full name of the element within its main structure.
 
std::string getElementName (const CodecIndex &codec_index) const
 Retrieves the name of the element within its structured element.
 
const std::string & getElementBaseName (const CodecIndex &codec_index) const
 Retrieves the base name of the element within its structured element.
 
template<typename T>
getElementValue (const CodecIndex &codec_index) const
 
template<typename T>
getElementValue (const LeafCodecIndex &leaf_codec_index) const
 
a_util::variant::Variant getElementVariantValue (const CodecIndex &codec_index) const
 
void getElementVariantValue (const CodecIndex &codec_index, a_util::variant::Variant &value) const
 
std::string getElementStringValue (const CodecIndex &codec_index) const
 
void getElementRawValue (const CodecIndex &index, void *value, size_t value_size) const
 
const void * getElementAddress (const CodecIndex &index) const
 
size_t getStaticBufferSize () const
 Gets the static buffer size in bytes for the main structure.
 
size_t getStaticBufferSize (DataRepresentation rep) const
 Gets the static buffer size in bytes for the main structure.
 
DataRepresentation getRepresentation () const
 
CodecIndex resolve (size_t leaf_index) const
 
CodecIndex resolve (size_t leaf_index, std::string &element_full_name) const
 
size_t getElementCount () const
 
a_util::result::Result getElement (size_t leaf_index, const ddl::StructElement *&legacy_struct_element) const
 
void resolve (CodecIndex &codec_index) const
 
const void * getData () const noexcept
 Get the current set data.
 
size_t getDataSize () const noexcept
 Get the current size (in bytes) of the data.
 

Protected Member Functions

 Codec (std::shared_ptr< const StructAccess > codec_access, void *data, size_t data_size, ddl::DataRepresentation rep)
 For internal use only.
 
 Codec (const Decoder &decoder, void *data, size_t data_size, ddl::DataRepresentation representation)
 For internal use only.
 
- Protected Member Functions inherited from ddl::codec::Decoder
 Decoder (std::shared_ptr< const StructAccess > codec_access, const void *data, size_t data_size, DataRepresentation representation)
 For internal use only.
 
 Decoder (const Decoder &decoder, const void *data, size_t data_size, DataRepresentation representation)
 For internal use only.
 
- Protected Member Functions inherited from ddl::codec::StaticDecoder
 StaticDecoder (std::shared_ptr< const StructAccess > codec_access, const void *data, size_t data_size, DataRepresentation representation)
 For internal use only.
 

Friends

class CodecFactory
 
class Decoder
 

Additional Inherited Members

- Protected Attributes inherited from ddl::codec::StaticDecoder
std::shared_ptr< const StructAccess > _codec_access
 For internal use only.
 
const void * _data = nullptr
 For internal use only.
 
size_t _data_size = 0
 For internal use only.
 
const ddl::codec::ElementAccessor * _element_accessor
 For internal use only.
 

Detailed Description

Decoder for dynamic structures defined by a DataDefinition definition. Currently the amount of dynamic elements is determined during construction only (by the current values in the structure).

Member Typedef Documentation

◆ Element

◆ Elements

Constructor & Destructor Documentation

◆ Codec() [1/3]

ddl::codec::Codec::Codec ( )

Default constructor.

◆ Codec() [2/3]

ddl::codec::Codec::Codec ( Codec && )

Move constructor.

◆ Codec() [3/3]

ddl::codec::Codec::Codec ( const Codec & )
delete

No copy constructor.

Member Function Documentation

◆ getChildElement()

Element ddl::codec::Codec::getChildElement ( const CodecIndex & parent_codec_index,
std::string_view relative_path )

Retrieves an element instance based on the child name of the element.

Parameters
[in]parent_codec_indexThe parent codec index.
[in]relative_pathThe child name of the element in point notation (i.e. "child_element[4].element_value").

By using an empty string the deserialized decoding information within CodecIndex will retrieve the same codec index as it is before.

Returns
The child Codec Index of the Codec.
Remarks
The element is only valid as long as the Codec exists.
Exceptions
throwsstd::runtime_error if not found.

◆ getData()

void * ddl::codec::Codec::getData ( )
noexcept

Get the current set data.

Remarks
For performance issues this will not check any validity!
Returns
void* The data pointer

◆ getElement() [1/4]

Element ddl::codec::Codec::getElement ( const CodecIndex & codec_index)

Retrieves an element instance based on the codec index of that element.

Parameters
[in]codec_indexThe codec index.
Returns
The Codec Index of the CodecElement.
Remarks
The element is only valid as long as the codec exists.
Exceptions
throwsstd::runtime_error if not found.

◆ getElement() [2/4]

Element ddl::codec::Decoder::getElement ( const CodecIndex & codec_index) const

Retrieves an element instance based on the codec index of that element.

Parameters
[in]codec_indexThe codec index.
Returns
The DecoderElement for the given codec index.
Remarks
The element is only valid as long as the factory exists.
Exceptions
throwsstd::runtime_error if not found.

◆ getElement() [3/4]

Element ddl::codec::Codec::getElement ( std::string_view full_path)

Retrieves an element instance based on the full name of the element.

Parameters
[in]full_pathThe full name of the element in point notation (i.e. "element1.child_element[4].element_value").

By using an empty string the deserialized decoding information within CodecIndex will retrieve the buffers first address and whole buffersize. By refering an array without dedicated array index position the deserialized decoding information within CodecIndex will be set to the arrays first address and the whole array size. By refering an structured value (not a leaf value) the deserialized decoding information within CodecIndex will be set to the structs first address and the whole struct size.

Returns
The Codec Index of the CodecElement.
Remarks
The element is only valid as long as the codec exists.
Exceptions
throwsstd::runtime_error if not found.

◆ getElement() [4/4]

Element ddl::codec::Decoder::getElement ( std::string_view full_path) const

Retrieves an element instance based on the full name of the element.

Parameters
[in]full_pathThe full name of the element in point notation (i.e. "element1.child_element[4].element_value").

By using an empty string the deserialized decoding information within CodecIndex will retrieve the buffers first address and whole buffersize. By refering an array without dedicated array index position the deserialized decoding information within CodecIndex will be set to the arrays first address and the whole array size. By refering an structured value (not a leaf value) the deserialized decoding information within CodecIndex will be set to the structs first address and the whole struct size.

Returns
The Codec Index of the DecoderElement.
Remarks
The element is only valid as long as the factory exists.
Exceptions
throwsstd::runtime_error if not found.

◆ getElementAddress()

void * ddl::codec::Codec::getElementAddress ( const CodecIndex & codec_index)
Parameters
[in]codec_indexThe index of the element.
Returns
A pointer to the element for write access.

◆ getElements() [1/2]

Elements & ddl::codec::Codec::getElements ( )

Retrieves the elements of the codec to get element information.

Returns
Elements The elements iterator container.
See also
forEachLeafElement, forEachElement, Codec::Element, CodecIndex

◆ getElements() [2/2]

const Elements & ddl::codec::Decoder::getElements ( ) const

Retrieves the elements of the decoder to get element information and get values.

Returns
Elements The elements iterator container.
See also
forEachLeafElement, forEachElement, Decoder::Element, CodecIndex

◆ operator=() [1/2]

Codec & ddl::codec::Codec::operator= ( Codec && )

Move assignment operator.

◆ operator=() [2/2]

Codec & ddl::codec::Codec::operator= ( const Codec & )
delete

No copy assignment operator.

◆ resetValues()

void ddl::codec::Codec::resetValues ( bool zero_values = false)

Sets all elements to their default values, constant values defined in the data definition or zero if zero_values is set.

Parameters
[in]zero_valuesset the value to 0 if no constant or default value set in data definition.

◆ setElementRawValue()

void ddl::codec::Codec::setElementRawValue ( const CodecIndex & codec_index,
const void * value,
size_t value_size )

Sets the current value of the given element by copying its data from the passed-in location.

Parameters
[in]codec_indexThe codec index of the element.
[in]valueThe location where the data should be copied from.
[in]value_sizeThe size in bytes of the location (if 0 - unsafe usage!).
Exceptions
throwsstd::runtime_error if not found or value_size is lower then elements value memory to copy.

◆ setElementStringValue()

void ddl::codec::Codec::setElementStringValue ( const CodecIndex & codec_index,
const std::string & value )

Sets the current value of the given element from the given string. This will cast the given value to the elements data type!

Parameters
[in]codec_indexThe index of the element.
[in]valueThe value to set.
Exceptions
throwsstd::runtime_error if not found.

◆ setElementValue() [1/2]

template<typename T>
void ddl::codec::Codec::setElementValue ( const CodecIndex & codec_index,
const T & value )
inline

Sets the current value of the given element from given value in type T. This will cast the given value to the elements data type!

Parameters
[in]codec_indexThe index of the element.
[in]valueThe value to set.
Template Parameters
TType of the value to set
Exceptions
throwsstd::runtime_error if not found.

◆ setElementValue() [2/2]

template<typename T>
void ddl::codec::Codec::setElementValue ( const LeafCodecIndex & leaf_codec_index,
const T & value )
inline

Sets the current value of the given element from given value in type T. This will cast the given value to the elements data type!

Parameters
[in]leaf_codec_indexThe leaf codec index of the element.
[in]valueThe value to set.
Template Parameters
TType of the value to set
Exceptions
std::runtime_errorif there is no valid conversion or the given leaf_codec_index is invalid

◆ setElementVariantValue()

void ddl::codec::Codec::setElementVariantValue ( const CodecIndex & codec_index,
const a_util::variant::Variant & value )

Sets the current value of the given element from the given variant. If this element is a enum type the enum types element name can be used in value. Otherwise the string value is automatically converted to the elments data type, if possible.

Parameters
[in]codec_indexThe index of the element.
[in]valueThe value to set.
Exceptions
throwsstd::runtime_error if not found.

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