|
CeresEngine 0.2.0
A game development framework
|
The Encoder class is a CBOR (Concise Binary Object Representation) encoder that provides an abstraction for serializing CBOR data to an output stream.
More...
#include <CeresEngine/Foundation/CBOR.hpp>
Public Member Functions | |
| Encoder (OutputStream outputStream) | |
Creates a new CBOR encoder from an OutputStream. | |
| Encoder (IOutputStream &outputStream) | |
Creates a new CBOR encoder from an IOutputStream. | |
| void | write (UInt64 value) |
| Encodes an unsigned integer into the CBOR stream. | |
| void | write (Int64 value) |
| Encodes a signed integer into the CBOR stream. | |
| void | write (float value) |
Encodes a float into the CBOR stream. | |
| void | write (double value) |
Encodes a double into the CBOR stream. | |
| void | write (bool value) |
Encodes a bool into the CBOR stream. | |
| void | write (StringView value) |
Encodes a StringView into the CBOR stream. | |
| void | write (const String &value) |
Encodes a String into the CBOR stream. | |
| void | write (const char *value) |
Encodes a const char* into the CBOR stream. | |
| void | write (Binary value) |
Encodes a Binary into the CBOR stream. | |
| void | write (std::nullptr_t value) |
Encodes a nullptr into the CBOR stream. | |
| void | write (Undefined value) |
Encodes an undefined into the CBOR stream. | |
| void | write (Break value) |
Encodes an Break into the CBOR stream. | |
| void | break_ () |
Encodes an Break into the CBOR stream. | |
| void | write (Array value) |
| Encodes an array header into the CBOR stream. | |
| void | array (const UInt64 size) |
| Encodes an array header into the CBOR stream. | |
| template<typename Func > | |
| void | array (const UInt64 size, Func &&func) |
| Encodes an array header into the CBOR stream. | |
| void | array () |
| Encodes an array header into the CBOR stream. | |
| template<typename Func > | |
| void | array (Func &&func) |
| Encodes an array header into the CBOR stream. | |
| void | write (Map value) |
| Encodes a map header into the CBOR stream. | |
| void | map (const UInt64 size) |
| Encodes an map header into the CBOR stream. | |
| template<typename Func > | |
| void | map (const UInt64 size, Func &&func) |
| Encodes a map header into the CBOR stream. | |
| void | map () |
| Encodes an map header into the CBOR stream. | |
| template<typename Func > | |
| void | map (Func &&func) |
| Encodes a map header into the CBOR stream. | |
| void | write (Tag value) |
| Encodes a tag header into the CBOR stream. | |
| void | tag (const UInt64 id) |
| Encodes an tag header into the CBOR stream. | |
| template<typename Func > | |
| void | tag (const UInt64 id, Func &&func) |
| Encodes a tag header into the CBOR stream. | |
| void | binary (const void *data, size_t length) |
| Encodes binary data into the CBOR stream. | |
| void | binary (const MemoryView< const Byte > &data) |
| Encodes binary data into the CBOR stream. | |
| void | binary (const FunctionView< void(OutputStream &) const > &func) |
| Encodes binary data into the CBOR stream. | |
| void | binary (UInt64 length, const FunctionView< void(OutputStream &) const > &func) |
| Encodes binary data into the CBOR stream. | |
| void | write (Value &&value) |
| Encodes a value into the CBOR stream. | |
| bool | flush () |
| template<typename T > requires std::is_enum_v<T> | |
| void | write (T value) |
| Encodes an enum value into the CBOR stream. | |
Private Attributes | |
| BufferedOutputStream | mStream |
| The stream to write to. | |
The Encoder class is a CBOR (Concise Binary Object Representation) encoder that provides an abstraction for serializing CBOR data to an output stream.
It's designed to encode CBOR values to an instance of an OutputStream. It provides an efficient and convenient way to write and encode CBOR data streams, without having to create a representation of the entire data stream into memory.
|
inlineexplicit |
Creates a new CBOR encoder from an OutputStream.
|
inlineexplicit |
Creates a new CBOR encoder from an IOutputStream.
|
inline |
Encodes an array header into the CBOR stream.
The user is responsible for encoding the correct number of elements.
| size | The number of elements in the array. |
Encodes an array header into the CBOR stream.
| size | The number of elements in the array. |
| func | A function to be called after serializing the header. |
| void CeresEngine::CBOR::Encoder::binary | ( | const FunctionView< void(OutputStream &) const > & | func | ) |
Encodes binary data into the CBOR stream.
This function allows encoding of binary data directly into the CBOR stream by executing the given function with an OutputStream that the user can use to write the binary data. The function passed OutputStream is a special stream that will automatically encode the indefinite length byte string as data is written to it.
| func | A FunctionView that takes an OutputStream reference as an argument. This function is executed to encode the binary data into the CBOR stream. |
|
inline |
Encodes binary data into the CBOR stream.
| data | A pointer to the binary data. |
| length | The length of the binary data. |
Encodes binary data into the CBOR stream.
| data | A pointer to the binary data. |
| length | The length of the binary data. |
| void CeresEngine::CBOR::Encoder::binary | ( | UInt64 | length, |
| const FunctionView< void(OutputStream &) const > & | func | ||
| ) |
Encodes binary data into the CBOR stream.
This function allows encoding of binary data directly into the CBOR stream by executing the given function with an OutputStream that the user can use to write the binary data. The function passed OutputStream is a special stream that will ensure that only the right amount of bytes are written to it.
| length | The number of bytes to encode into the CBOR byte string. The caller must ensure that it writes exactly this many bytes into the given stream. |
| func | A FunctionView that takes an OutputStream reference as an argument. This function is executed to encode the binary data into the CBOR stream. |
|
inline |
|
inline |
Encodes an map header into the CBOR stream.
The user is responsible for encoding the correct number of key-value pairs.
| size | The number of key-value pairs in the map. |
Encodes a map header into the CBOR stream.
| size | The number of key-value pairs in the map. |
| func | A function to be called after serializing the header. |
Encodes an tag header into the CBOR stream.
The user is responsible for encoding the tag contents.
| id | The tag unique identifier. |
Encodes a tag header into the CBOR stream.
| id | The tag unique identifier. |
| func | A function to be called after serializing the header. |
Encodes a const char* into the CBOR stream.
Encodes a String into the CBOR stream.
Encodes a signed integer into the CBOR stream.
| void CeresEngine::CBOR::Encoder::write | ( | std::nullptr_t | value | ) |
Encodes a nullptr into the CBOR stream.
| void CeresEngine::CBOR::Encoder::write | ( | StringView | value | ) |
Encodes a StringView into the CBOR stream.
Encodes an enum value into the CBOR stream.
Encodes an unsigned integer into the CBOR stream.
Encodes an undefined into the CBOR stream.
|
private |
The stream to write to.
This is a buffered OutputStream and it's very important that this is referenced by value (not through the OutputStream wrapper), as it allows to reduce the number of virtual calls and significantly increase the performance.