Generic types

The classes representing data buffers, data encoding, timestamp, etc. There types are frequently used by other parts of the API.

class BytesView : public zenohcxx::Copyable<::z_bytes_t>

Represents non-owned read only array of bytes.

Constructors

inline BytesView(nullptr_t)

Constructs an uninitialized instance.

inline BytesView(const void *s, size_t _len)

Constructs an instance from an array of bytes

Parameters:
  • s – the array of bytes

  • _len – the length of the array

inline BytesView(const char *s)

Constructs an instance from a null-terminated string

Parameters:

s – the null-terminated string

template<typename T>
inline BytesView(const std::vector<T> &v)

Constructs an instance from a std::vector of type T

Parameters:

v – the std::vector of type T

inline BytesView(const std::string_view &s)

Constructs an instance from a std::string_view

Parameters:

s – the std::string_view

inline BytesView(const std::string &s)

Constructs an instance from a std::string

Parameters:

s – the std::string

Operators

inline std::string_view as_string_view() const

Returns a std::string_view representation of the array of bytes

Returns:

a std::string_view representation of the array of bytes

inline bool operator==(const BytesView &v) const

Compares two instances of BytesView

Parameters:

v – the other instance of BytesView

Returns:

true if the two instances are equal, false otherwise

inline bool operator!=(const BytesView &v) const

Compares two instances of BytesView

Parameters:

v – the other instance of BytesView

Returns:

true if the two instances are not equal, false otherwise

Methods

inline size_t get_len() const

Returns the length of the array

Returns:

the length of the array

inline bool check() const

Checks if the array is initialized

Returns:

true if the array is initialized

class Str : public zenohcxx::Owned<::z_owned_str_t>

Owned string returned from zenoh. It is automatically freed when the object is destroyed.

Methods

inline const char *c_str() const

Get the string value.

Returns:

const char* null-terminated string pointer

Operators

inline operator const char*() const

Get the string value.

Returns:

const char* null-terminated string pointer

inline bool operator==(const std::string_view &s) const

Equality operator.

Parameters:

s – the std::string_view to compare with

Returns:

true if the two strings are equal

inline bool operator==(const char *s) const

Equality operator.

Parameters:

s – the null-terminated string to compare with

Returns:

true if the two strings are equal

struct StrArrayView : public zenoh::_StrArrayView<::z_str_array_t>

Represents non-owned read only array of char* Impmemented in a template zenoh::_StrArrayView to handle with different const definitions in ::z_str_array_t struct in zenoh-pico and zenoh-c

template<typename Z_STR_ARRAY_T>
struct _StrArrayView : public zenohcxx::Copyable<Z_STR_ARRAY_T>

Constructors

inline _StrArrayView()

Constructs an uninitialized instance.

inline _StrArrayView(const std::vector<const char*> &v)

Constructs an instance from a std::vector of const char*

Parameters:

v – the std::vector of const char*

inline _StrArrayView(const char **v, size_t len)

Constructs an instance from an array of const char*

Parameters:
  • v – the array of const char*

  • len – the length of the array

inline _StrArrayView(const char *const *v, size_t len)

Constructs an instance from an constant array of const char*

Parameters:
  • v – the array of const char*

  • len – the length of the array

Operators

inline const char *operator[](size_t pos) const

Operator to access an element of the array by index

Parameters:

pos – the index of the element

Returns:

the element at the given index

Methods

inline size_t get_len() const

Returns the length of the array

Returns:

the length of the array

struct Encoding : public zenohcxx::Copyable<::z_encoding_t>

The encoding of a payload, in a MIME-like format.

For wire and matching efficiency, common MIME types are represented using an integer as “prefix”, and a “suffix” may be used to either provide more detail, or in combination with the Z_ENCODING_PREFIX_EMPTY value of zenoh::EncodingPrefix to write arbitrary MIME types.

Constructors

inline Encoding()

Default encoding.

inline Encoding(EncodingPrefix _prefix)

Encoding with a prefix.

inline Encoding(EncodingPrefix _prefix, const char *_suffix)

Encoding with a prefix and a suffix.

Methods

inline Encoding &set_prefix(EncodingPrefix _prefix)

Set the prefix for the encoding.

Parameters:

_prefix – value of zenoh::EncodingPrefix type

Returns:

Reference to the Encoding object

inline Encoding &set_suffix(const zenoh::BytesView &_suffix)

Set the suffix for the encoding.

Parameters:

_suffixzenoh::BytesView representing the suffix

Returns:

Reference to the Encoding object

inline EncodingPrefix get_prefix() const

Get the prefix of the encoding.

Returns:

value of zenoh::EncodingPrefix type

inline const zenoh::BytesView &get_suffix() const

Get the suffix of the encoding.

Returns:

zenoh::BytesView representing the suffix

Operators

inline bool operator==(const Encoding &v) const

Equality operator.

Parameters:

v – other Encoding object

Returns:

true if the encodings are equal

inline bool operator!=(const Encoding &v) const

Inequality operator.

Parameters:

v – other Encoding object

Returns:

true if the encodings are not equal

struct Id : public zenohcxx::Copyable<::z_id_t>

Represents a Zenoh ID. In general, valid Zenoh IDs are LSB-first 128bit unsigned and non-zero integers.

See also: operator<<(std::ostream& os, const z::Id& id)

Methods

inline bool is_some() const

Checks if the ID is valid

Returns:

true if the ID is valid

std::ostream &zenoh::operator<<(std::ostream &os, const zenoh::Id &id)

Output operator for Id.

Parameters:
  • os – the output stream

  • id – reference to the Id

Returns:

the output stream

struct Timestamp : public zenohcxx::Copyable<::z_timestamp_t>

Represents timestamp value in zenoh.

Methods

inline uint64_t get_time() const

Get the time part of timestamp in NTP64 format.

Returns:

timestamp value

inline zenoh::Id get_id() const

Get the unique part of the timestamp.

Returns:

unique id

inline bool check() const

Check if the timestamp is valid.

Returns:

true if the timestamp is valid

struct Value : public zenohcxx::Copyable<::z_value_t>

A zenoh value. Contans refrence to data and it’s encoding.

Constructors

inline Value(const zenoh::BytesView &payload, const zenoh::Encoding &encoding)

Create a new value with the given payload and encoding.

Parameters:
inline Value(const zenoh::BytesView &payload)

Create a new value with the default encoding.

Parameters:

payloadBytesView object

inline Value(const char *payload)

Create a new value from null-terminated string with the default encoding.

Parameters:

payload – null-terminated string

Methods

inline const zenoh::BytesView &get_payload() const

The payload of this value.

Returns:

BytesView object

inline Value &set_payload(const zenoh::BytesView &_payload)

Set payload of this value.

Parameters:

_payloadBytesView object

Returns:

referencew the value itself

inline const zenoh::Encoding &get_encoding() const

The encoding of this value.

Returns:

Encoding object

inline Value &set_encoding(const zenoh::Encoding &_encoding)

Set encoding of this value.

Parameters:

_encodingEncoding object

Returns:

referencew the value itself

inline std::string_view as_string_view() const

The payload of this value as a std::string_view

Returns:

std::string_view object

Operators

inline bool operator==(const Value &v) const

Equality operator.

Parameters:

v – the other Value to compare with

Returns:

true if the two values are equal (have the same payload and encoding)

inline bool operator!=(const Value &v) const

Inequality operator.

Parameters:

v – the other Value to compare with

Returns:

true if the two values are not equal (have different payload or encoding)