Zakero's C++ Header Libraries
A collection of reusable C++ libraries
Public Member Functions | List of all members
zakero::messagepack::Object Struct Reference

A Data Object. More...

Public Member Functions

template<typename T >
const T & as () const noexcept
 Convert to type T. More...
 
template<typename T >
T & as () noexcept
 Convert to type T. More...
 
const messagepack::ArrayasArray () const noexcept
 Convert to an Array. More...
 
messagepack::ArrayasArray () noexcept
 Convert to an Array. More...
 
const std::vector< uint8_t > & asBinary () const noexcept
 Convert to a std::vector<uint8_t>. More...
 
std::vector< uint8_t > & asBinary () noexcept
 Convert to a std::vector<uint8_t>. More...
 
const messagepack::ExtasExt () const noexcept
 Convert to an Ext. More...
 
messagepack::ExtasExt () noexcept
 Convert to an Ext. More...
 
const messagepack::MapasMap () const noexcept
 Convert to a Map. More...
 
messagepack::MapasMap () noexcept
 Convert to a Map. More...
 
const std::string & asString () const noexcept
 Convert to a std::string. More...
 
template<typename T >
constexpr bool is () const noexcept
 Is Object of type T. More...
 
constexpr bool isArray () const noexcept
 Is Object an Array? More...
 
constexpr bool isBinary () const noexcept
 Is Object binary data? More...
 
constexpr bool isExt () const noexcept
 Is Object an Ext? More...
 
constexpr bool isMap () const noexcept
 Is Object a Map? More...
 
constexpr bool isNull () const noexcept
 Does the Object represent a null? More...
 
constexpr bool isString () const noexcept
 Is Object a std::string? More...
 

Detailed Description

The role of this object is to store all the data-types in the MessagePack specification. This is accomplish by using the std::variant and a collection of helper methods to reduce the verbosity of templates.

Note
The std::monostate is used to represent null.

Once an Object has been set to a type, it is an error to cast the object to any other type.

Example
object = {true}; // Object is now a boolean
int64_t value = object.as<int64_t>(); // Error: Object is not a int64_t
// Reusing the same object...
object = {int64_t(42)}; // Object is now a int64_t
value = object.as<int64_t>(); // Ok: Object is a int64_t
A Data Object.
Definition: Zakero_MessagePack.h:337

Member Function Documentation

◆ as() [1/2]

template<typename T >
zakero::messagepack::Object::as ( ) const
inlinenoexcept

The Object will be converted so that it will be treated as the requested T type.

Example
bool b = object.as<bool>();
T & as() noexcept
Convert to type T.
Definition: Zakero_MessagePack.h:352
Returns
The request data-type.
Template Parameters
TThe data-type to convert to.

◆ as() [2/2]

template<typename T >
zakero::messagepack::Object::as ( )
inlinenoexcept

The Object will be converted so that it will be treated as the requested T type.

Example
bool b = object.as<bool>();
Returns
The request data-type.
Template Parameters
TThe data-type to convert to.

◆ asArray() [1/2]

zakero::messagepack::Object::asArray ( ) const
inlinenoexcept

The same as: object.as<zakero::messagepack::Array>()

Returns
A reference to an Array.
See also
as()

◆ asArray() [2/2]

zakero::messagepack::Object::asArray ( )
inlinenoexcept

The same as: object.as<zakero::messagepack::Array>()

Returns
A reference to an Array.
See also
as()

◆ asBinary() [1/2]

zakero::messagepack::Object::asBinary ( ) const
inlinenoexcept

The same as: object.as<std::vector<uint8_t>>()

Returns
A reference to a std::vector<uint8_t>.
See also
as()

◆ asBinary() [2/2]

zakero::messagepack::Object::asBinary ( )
inlinenoexcept

The same as: object.as<std::vector<uint8_t>>()

Returns
A reference to a std::vector<uint8_t>.
See also
as()

◆ asExt() [1/2]

zakero::messagepack::Object::asExt ( ) const
inlinenoexcept

The same as: object.as<zakero::messagepack::Ext>()

Returns
A reference to an Ext.
See also
as()

◆ asExt() [2/2]

zakero::messagepack::Object::asExt ( )
inlinenoexcept

The same as: object.as<zakero::messagepack::Ext>()

Returns
A reference to an Ext.
See also
as()

◆ asMap() [1/2]

zakero::messagepack::Object::asMap ( ) const
inlinenoexcept

The same as: object.as<zakero::messagepack::Map>()

Returns
A reference to a Map.
See also
as()

◆ asMap() [2/2]

zakero::messagepack::Object::asMap ( )
inlinenoexcept

The same as: object.as<zakero::messagepack::Map>()

Returns
A reference to a Map.
See also
as()

◆ asString()

zakero::messagepack::Object::asString ( ) const
inlinenoexcept

The same as: object.as<std::string>()

Returns
A reference to a std::string.
See also
as()

◆ is()

template<typename T >
zakero::messagepack::Object::is ( ) const
inlineconstexprnoexcept

The Object will be checked to see if it is of type T.

Example
zakero::messagepack::Object object = {int64_t(123)};
bool is_int = object.is<int64_t>();
constexpr bool is() const noexcept
Is Object of type T.
Definition: Zakero_MessagePack.h:367
Return values
trueThe Object is of type T
falseThe Object is not of type T
Template Parameters
TThe data-type to check.

◆ isArray()

zakero::messagepack::Object::isArray ( ) const
inlineconstexprnoexcept

The same as: object.is<zakero::messagepack::Array>()

Return values
trueThe Object is an Array
falseThe Object is not an Array
See also
is()

◆ isBinary()

zakero::messagepack::Object::isBinary ( ) const
inlineconstexprnoexcept

The same as: object.is<std::vector<uint8_t>>()

Return values
trueThe Object is a std::vector<uint8_t>
falseThe Object is not a std::vector<uint8_t>
See also
is()

◆ isExt()

zakero::messagepack::Object::isExt ( ) const
inlineconstexprnoexcept

The same as: object.is<zakero::messagepack::Ext>()

Return values
trueThe Object is an Ext
falseThe Object is not an Ext
See also
is()

◆ isMap()

zakero::messagepack::Object::isMap ( ) const
inlineconstexprnoexcept

The same as: object.is<zakero::messagepack::Map>()

Return values
trueThe Object is a Map
falseThe Object is not a Map
See also
is()

◆ isNull()

zakero::messagepack::Object::isNull ( ) const
inlineconstexprnoexcept

The same as: object.is<std::monostate>()

Return values
trueThe Object is a std::monostate
falseThe Object is not a std::monostate
See also
is()

◆ isString()

zakero::messagepack::Object::isString ( ) const
inlineconstexprnoexcept

The same as: object.is<std::string>()

Return values
trueThe Object is a std::string
falseThe Object is not a std::string
See also
is()

The documentation for this struct was generated from the following file: