xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::cbor::Encoder Class Reference

A class that encodes CBOR data types that includes: unsigned integers, negative integers, byte strings, text strings encoded as UTF8, simple values and float-point number. More...

#include <cbor/Encoder.hpp>

Public Member Functions

 Encoder (std::reference_wrapper< OutputStream< std::byte > > stream)
 An Encoder Constructor that sets an output stream.
 
template<tools::UnsignedIntegral Type>
auto operator<< (Type value) -> Encoder &
 Enocdes a unsigned integeral value.
 
template<tools::SignedIntegral Type>
auto operator<< (Type value) -> Encoder &
 Encodes signed/unsigned integeral value.
 
template<std::ranges::contiguous_range Data>
requires std::same_as<std::remove_cv_t<std::ranges::range_value_t<Data>>, std::byte>
auto operator<< (const Data &data) -> Encoder &
 Encodes byte string of opaque bytes.
 
template<std::convertible_to< std::string_view > String>
auto operator<< (const String &string) -> Encoder &
 Encodes text string of unicode characters that is encoded as UTF-8.
 
auto operator<< (float value) -> Encoder &
 Encodes float value.
 
auto operator<< (double value) -> Encoder &
 Encodes double value.
 
auto operator<< (bool value) -> Encoder &
 Encodes bool value.
 
auto operator<< (NullTag tag) -> Encoder &
 Encodes a CBOR null value (simple value 22)
 
auto operator<< (UndefinedTag tag) -> Encoder &
 Encodes a CBOR undefined value (simple value 23)
 
auto operator<< (Tag value) -> Encoder &
 Encodes a CBOR data item tag.
 
auto operator<< (SimpleValue value) -> Encoder &
 Encodes an arbitrary CBOR simple value.
 
auto operator<< (const Array &array) -> Encoder &
 Encodes the header of a CBOR array.
 
auto operator<< (const Map &map) -> Encoder &
 Encodes the header of a CBOR array.
 
auto operator<< (BreakTag tag) -> Encoder &
 Encodes a CBOR break value (simple value 31)
 

Detailed Description

A class that encodes CBOR data types that includes: unsigned integers, negative integers, byte strings, text strings encoded as UTF8, simple values and float-point number.

Constructor & Destructor Documentation

◆ Encoder()

xentara::utils::cbor::Encoder::Encoder ( std::reference_wrapper< OutputStream< std::byte > >  stream)

An Encoder Constructor that sets an output stream.

Parameters
streamOutput Stream

Member Function Documentation

◆ operator<<() [1/14]

auto xentara::utils::cbor::Encoder::operator<< ( bool  value) -> Encoder &

Encodes bool value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [2/14]

auto xentara::utils::cbor::Encoder::operator<< ( BreakTag  tag) -> Encoder &

Encodes a CBOR break value (simple value 31)

Parameters
tagAlways pass kBreak as this parameter
Returns
A reference to this object
See also
section 3.2.1) RFC 8949.

◆ operator<<() [3/14]

auto xentara::utils::cbor::Encoder::operator<< ( const Array array) -> Encoder &

Encodes the header of a CBOR array.

This function only encodes the header of the array, consisting of the major type and the length. The array elements and (for indefinite length arrays) the stop code must be encoded separately.

Parameters
arrayThe array header to encode
Returns
A reference to this object

◆ operator<<() [4/14]

template<std::ranges::contiguous_range Data>
requires std::same_as<std::remove_cv_t<std::ranges::range_value_t<Data>>, std::byte>
auto xentara::utils::cbor::Encoder::operator<< ( const Data &  data) -> Encoder &

Encodes byte string of opaque bytes.

Parameters
dataThe data block to encode
Returns
A reference to this object

◆ operator<<() [5/14]

auto xentara::utils::cbor::Encoder::operator<< ( const Map map) -> Encoder &

Encodes the header of a CBOR array.

This function only encodes the header of the map, consisting of the major type and the length. The keys and values and (for indefinite length maps) the stop code must be encoded separately.

Parameters
mapThe map header to encode
Returns
A reference to this object

◆ operator<<() [6/14]

auto xentara::utils::cbor::Encoder::operator<< ( const String &  string) -> Encoder &

Encodes text string of unicode characters that is encoded as UTF-8.

Parameters
stringA string to encode
Returns
A reference to this object

◆ operator<<() [7/14]

auto xentara::utils::cbor::Encoder::operator<< ( double  value) -> Encoder &

Encodes double value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [8/14]

auto xentara::utils::cbor::Encoder::operator<< ( float  value) -> Encoder &

Encodes float value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [9/14]

auto xentara::utils::cbor::Encoder::operator<< ( NullTag  tag) -> Encoder &

Encodes a CBOR null value (simple value 22)

Parameters
tagAlways pass kNull as this parameter
Returns
A reference to this object

◆ operator<<() [10/14]

auto xentara::utils::cbor::Encoder::operator<< ( SimpleValue  value) -> Encoder &

Encodes an arbitrary CBOR simple value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [11/14]

auto xentara::utils::cbor::Encoder::operator<< ( Tag  value) -> Encoder &

Encodes a CBOR data item tag.

Parameters
valueA value to encode
Returns
A reference to this object
See also
section 3.4) of RFC 8949.

◆ operator<<() [12/14]

template<tools::UnsignedIntegral Type>
auto xentara::utils::cbor::Encoder::operator<< ( Type  value) -> Encoder &

Enocdes a unsigned integeral value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [13/14]

template<tools::SignedIntegral Type>
auto xentara::utils::cbor::Encoder::operator<< ( Type  value) -> Encoder &

Encodes signed/unsigned integeral value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [14/14]

auto xentara::utils::cbor::Encoder::operator<< ( UndefinedTag  tag) -> Encoder &

Encodes a CBOR undefined value (simple value 23)

Parameters
tagAlways pass kUndefined as this parameter
Returns
A reference to this object
See also
section 5.7) of RFC 8949.