AMQP and C++ types {#types_page}

An AMQP message body can hold binary data using any encoding you like. AMQP also defines its own encoding and types. The AMQP encoding is often used in message bodies because it is supported by AMQP libraries on many languages and platforms. You also need to use the AMQP types to set and examine message properties.

Scalar types

Each type is identified by a proton::type_id.

C++ typeAMQP type_idDescription
boolproton::BOOLEANBoolean true or false
uint8_tproton::UBYTE8-bit unsigned byte
int8_tproton::BYTE8-bit signed byte
uint16_tproton::USHORT16-bit unsigned integer
int16_tproton::SHORT16-bit signed integer
uint32_tproton::UINT32-bit unsigned integer
int32_tproton::INT32-bit signed integer
uint64_tproton::ULONG64-bit unsigned integer
int64_tproton::LONG64-bit signed integer
wchar_tproton::CHAR32-bit unicode code point
floatproton::FLOAT32-bit binary floating point
doubleproton::DOUBLE64-bit binary floating point
proton::timestampproton::TIMESTAMP64-bit signed milliseconds since 00:00:00 (UTC), 1 January 1970.
proton::decimal32proton::DECIMAL3232-bit decimal floating point
proton::decimal64proton::DECIMAL6464-bit decimal floating point
proton::decimal128proton::DECIMAL128128-bit decimal floating point
proton::uuidproton::UUID128-bit universally-unique identifier
std::stringproton::STRINGUTF-8 encoded Unicode string
proton::symbolproton::SYMBOL7-bit ASCII encoded string
proton::binaryproton::BINARYVariable-length binary data

Holder types

proton::message::body() and other message-related data can contain different types of data at runtime. There are two “holder” types provided to hold runtime typed data:

  • proton::scalar can hold a scalar value of any type.
  • proton::value can hold any AMQP value, scalar or compound.

You can set the value in a holder by assignment, and use the proton::get() and proton::coerce() templates to extract data in a type-safe way. Holders also provide functions to query the type of value they contain.

Compound types

C++ typeAMQP type_idDescription
See belowproton::ARRAYSequence of values of the same type
See belowproton::LISTSequence of values of mixed types
See belowproton::MAPMap of key-value pairs

A proton::value containing a proton::ARRAY can convert to and from C++ sequences of the corresponding C++ type: std::vector, std::deque, std::list, and std::forward_list.

proton::LIST converts to and from sequences of proton::value or proton::scalar, which can hold mixed types of data.

proton::MAP converts to and from std::map, std::unordered_map, and sequences of std::pair.

For example, you can decode a message body with any AMQP map as follows.

proton::message m = ...;
std::map<proton::value, proton::value> map;
proton::get(m.body(), map);

You can encode a message body with a map of string keys and uint64_t values like this:

std::unordered_map<std::string, uint64_t> map;
map["foo"] = 123;
m.body() = map;

Include files

proton/types.hpp includes all available type definitions and conversions. Alternatively, you can selectively include the .hpp files you want.