xentara-utils v2.0.4
The Xentara Utility 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 <xentara/utils/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.
 
template<typename Value >
requires (!std::same_as<Value, NullTag> && !std::same_as<Value, BreakTag>)
auto operator<< (const std::optional< Value > &optional) -> Encoder &
 Encodes an option value.
 
auto operator<< (BreakTag tag) -> Encoder &
 Encodes a CBOR break value (simple value 31)
 
auto operator<< (AlternativeValue value) -> Encoder &
 Encodes a CBOR alternative value.
 

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/16]

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

Encodes a CBOR alternative value.

Parameters
valueA value to encode
Returns
A reference to this object
See also
section 9.1).

◆ operator<<() [2/16]

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

Encodes bool value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [3/16]

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<<() [4/16]

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<<() [5/16]

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<<() [6/16]

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<<() [7/16]

template<typename Value >
requires (!std::same_as<Value, NullTag> && !std::same_as<Value, BreakTag>)
auto xentara::utils::cbor::Encoder::operator<< ( const std::optional< Value > &  optional) -> Encoder &

Encodes an option value.

If optional contains a value, it is encoded normally. If optional does not contain a value, a CBOR null value (simple value 22) is encoded instead.

Parameters
optionalA value to encode
Returns
A reference to this object

◆ operator<<() [8/16]

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<<() [9/16]

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

Encodes double value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [10/16]

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

Encodes float value.

Parameters
valueA value to encode
Returns
A reference to this object

◆ operator<<() [11/16]

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<<() [12/16]

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<<() [13/16]

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<<() [14/16]

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<<() [15/16]

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<<() [16/16]

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.