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>
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.
◆ Encoder() [1/2]
Constructor.
- Parameters
-
| stream | The output stream to write the data to |
◆ Encoder() [2/2]
template<typename UserData >
Constructor that attaches user data to the stream.
- Parameters
-
| stream | The output stream to write the data to |
| userData | Arbitrary user data to attach to the encoder. This can be used to store an API version in the encoder, for example. |
◆ operator<<() [1/16]
Encodes a CBOR alternative value.
- Parameters
-
- 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
-
- 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
-
| tag | Always 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
-
| array | The array header to encode |
- Returns
- A reference to this object
◆ operator<<() [5/16]
| auto xentara::utils::cbor::Encoder::operator<< |
( |
const Data & |
data | ) |
-> Encoder & |
Encodes byte string of opaque bytes.
- Parameters
-
| data | The 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
-
| map | The map header to encode |
- Returns
- A reference to this object
◆ operator<<() [7/16]
| 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
-
| optional | A 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
-
- Returns
- A reference to this object
◆ operator<<() [9/16]
| auto xentara::utils::cbor::Encoder::operator<< |
( |
double |
value | ) |
-> Encoder & |
Encodes double value.
- Parameters
-
- Returns
- A reference to this object
◆ operator<<() [10/16]
| auto xentara::utils::cbor::Encoder::operator<< |
( |
float |
value | ) |
-> Encoder & |
Encodes float value.
- Parameters
-
- 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
-
| tag | Always pass kNull as this parameter |
- Returns
- A reference to this object
◆ operator<<() [12/16]
Encodes an arbitrary CBOR simple value.
- Parameters
-
- 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
-
- 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
-
- 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
-
- Returns
- A reference to this object
◆ operator<<() [16/16]
Encodes a CBOR undefined value (simple value 23)
- Parameters
-
- Returns
- A reference to this object
- See also
- section 5.7 of RFC 8949.
◆ setUserData()
template<typename UserData >
| auto xentara::utils::cbor::Encoder::setUserData |
( |
UserData && |
userData | ) |
-> void
|
Sets the user data.
Any previous user data is overwritten.
- Parameters
-
| userData | Arbitrary user data to attach to the encoder. This can be used to store an API version in the encoder, for example. |
◆ userData()
template<typename UserData >
| auto xentara::utils::cbor::Encoder::userData |
( |
| ) |
const -> const UserData *
|
Gets the user data.
- Template Parameters
-
| UserData | The type of the user data to get |
- Returns
- The user data, or nullptr if no user data is set, or if the user data is of the wrong type