HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::UID::URI Struct Reference

URI UID class. More...

#include <uids.h>

+ Inheritance diagram for HF::UID::URI:
+ Collaboration diagram for HF::UID::URI:

Public Member Functions

uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (Common::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 Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
URIclone () const
 Create a clone object of the object where this method is being called. More...
 
int compare (const UID_T &other) const
 Compare the current UID with the given UID. More...
 
std::string str () const
 Return the string value associated with this URI. More...
 
- Public Member Functions inherited from HF::Common::Serializable
virtual ~Serializable ()
 Destructor.
 

Additional Inherited Members

- Static Public Attributes inherited from HF::UID::UID_T
static constexpr uint16_t min_size
 Minimum pack/unpack required data size.
 

Detailed Description

URI UID class.

Definition at line 431 of file uids.h.

Member Function Documentation

◆ clone()

URI* HF::UID::URI::clone ( ) const
inlinevirtual

Create a clone object of the object where this method is being called.

Returns
a new object that is a clone of this object.

Implements HF::Common::Cloneable< UID_T >.

Definition at line 495 of file uids.h.

496  {
497  return new URI(*this);
498  }

◆ compare()

int HF::UID::URI::compare ( const UID_T other) const
inlinevirtual

Compare the current UID with the given UID.

This function returns a value less that 0 if the current UID object order is lower that the given UID, 0 if the UIDs represent the same entity and a value greater that 0 if current UID object is above the given UID.

Parameters
[in]othera pointer to a UID object to compare to.
Return values
<0the current UID is lower that the given UID.
0the current UID is the same as given UID.
>0the current UID is greater that the given UID.

Reimplemented from HF::UID::UID_T.

Definition at line 504 of file uids.h.

References HF::UID::UID_T::compare().

505  {
506  int res = Abstract<URI_UID>::compare(other);
507 
508  return (res == 0 ? value.compare(((URI *) &other)->value) : res);
509  }
virtual int compare(const UID_T &other) const
Compare the current UID with the given UID.
Definition: uids.h:88
+ Here is the call graph for this function:

◆ pack()

uint16_t HF::UID::URI::pack ( Common::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.

Reimplemented from HF::UID::UID_T.

Definition at line 447 of file uids.h.

References HF_SERIALIZABLE_CHECK, HF::UID::UID_T::pack(), size(), and HF::Common::ByteArray::write().

448  {
449  HF_SERIALIZABLE_CHECK(array, offset, size());
450 
451  uint16_t start = offset;
452 
453  offset += Abstract<URI_UID>::pack(array, offset);
454 
455  assert(value.size() <= 0xFF);
456  offset += array.write(offset, (uint8_t) value.size());
457 
458  for (uint8_t i = 0; i < value.size(); i++)
459  {
460  offset += array.write(offset, (uint8_t) value[i]);
461  }
462 
463  return offset - start;
464  }
uint16_t size() const
Number bytes needed to serialize the message.
Definition: uids.h:442
#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...
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: uids.h:104
+ Here is the call graph for this function:

◆ size()

uint16_t HF::UID::URI::size ( ) const
inlinevirtual

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Reimplemented from HF::UID::UID_T.

Definition at line 442 of file uids.h.

References HF::UID::UID_T::size().

Referenced by pack(), and unpack().

443  {
444  return Abstract<URI_UID>::size() + value.size();
445  }
uint16_t size() const
Number bytes needed to serialize the message.
Definition: uids.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str()

std::string HF::UID::URI::str ( ) const
inline

Return the string value associated with this URI.

Returns
the string associated with this URI.

Definition at line 516 of file uids.h.

517  {
518  return value;
519  }

◆ unpack()

uint16_t HF::UID::URI::unpack ( const Common::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.

Reimplemented from HF::UID::UID_T.

Definition at line 466 of file uids.h.

References HF_SERIALIZABLE_CHECK, HF::UID::UID_T::min_size, HF::Common::ByteArray::read(), size(), and HF::UID::UID_T::unpack().

467  {
468  HF_SERIALIZABLE_CHECK(array, offset, min_size);
469 
470  uint16_t start = offset;
471 
472  offset += Abstract<URI_UID>::unpack(array, offset);
473 
474  uint8_t size;
475  offset += array.read(offset, size);
476 
477  HF_SERIALIZABLE_CHECK(array, offset, size);
478 
479  value = std::string(size, 0);
480 
481  for (uint8_t i = 0; i < size; i++)
482  {
483  uint8_t c;
484  offset += array.read(offset, c);
485  value[i] = c;
486  }
487 
488  return offset - start;
489  }
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Definition: uids.h:114
uint16_t size() const
Number bytes needed to serialize the message.
Definition: uids.h:442
#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...
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: uids.h:94
+ Here is the call graph for this function:

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