HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Common::SerializableHelper< T, typename > Struct Template Reference

Wrapper for classes that implement the Serializable concept. More...

#include <common.h>

+ Inheritance diagram for HF::Common::SerializableHelper< T, typename >:
+ Collaboration diagram for HF::Common::SerializableHelper< T, typename >:

Public Member Functions

uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (ByteArray &array, uint16_t offset=0) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t unpack (const ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
- Public Member Functions inherited from HF::Common::Serializable
virtual ~Serializable ()
 Destructor.
 

Data Fields

data
 Data type instance wrapped.
 

Detailed Description

template<typename T, typename = void>
struct HF::Common::SerializableHelper< T, typename >

Wrapper for classes that implement the Serializable concept.

Template Parameters
Tdata type to warp.
Warning
T should be POD (Plain Old Data)

Definition at line 496 of file inc/hanfun/common.h.

Member Function Documentation

◆ pack()

template<typename T, typename = void>
uint16_t HF::Common::SerializableHelper< T, typename >::pack ( ByteArray array,
uint16_t  offset = 0 
) const
inlinevirtual

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

Implements HF::Common::Serializable.

Definition at line 514 of file inc/hanfun/common.h.

Referenced by HF::Core::SUOTA::UpgradeStatus::pack(), HF::Attributes::Attribute< bool >::pack(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::pack(), and HF::Common::SerializableHelper< std::string >::pack().

515  {
516  HF_SERIALIZABLE_CHECK(array, offset, size());
517  return data.pack(array, offset);
518  }
T data
Data type instance wrapped.
uint16_t size() const
Number bytes needed to serialize the message.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
+ Here is the caller graph for this function:

◆ size()

◆ unpack()

template<typename T, typename = void>
uint16_t HF::Common::SerializableHelper< T, typename >::unpack ( const ByteArray array,
uint16_t  offset = 0 
)
inlinevirtual

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

Implements HF::Common::Serializable.

Definition at line 520 of file inc/hanfun/common.h.

Referenced by HF::Core::SUOTA::UpgradeStatus::unpack(), HF::Attributes::Attribute< bool >::unpack(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::unpack(), and HF::Common::SerializableHelper< std::string >::unpack().

521  {
522  HF_SERIALIZABLE_CHECK(array, offset, size());
523  return data.unpack(array, offset);
524  }
T data
Data type instance wrapped.
uint16_t size() const
Number bytes needed to serialize the message.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
+ Here is the caller graph for this function:

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