Debian Codegraph @

cpp/docs/types.md

raw
1 # AMQP and C++ types {#types_page}
2
3 An AMQP message body can hold binary data using any encoding you
4 like. AMQP also defines its own encoding and types. The AMQP encoding
5 is often used in message bodies because it is supported by AMQP
6 libraries on many languages and platforms. You also need to use the
7 AMQP types to set and examine message properties.
8
9 ## Scalar types
10
11 Each type is identified by a proton::type_id.
12
13 C++ type | AMQP type_id | Description
14 --------------------|----------------------|-----------------------
15 bool | proton::BOOLEAN | Boolean true or false
16 uint8_t | proton::UBYTE | 8-bit unsigned byte
17 int8_t | proton::BYTE | 8-bit signed byte
18 uint16_t | proton::USHORT | 16-bit unsigned integer
19 int16_t | proton::SHORT | 16-bit signed integer
20 uint32_t | proton::UINT | 32-bit unsigned integer
21 int32_t | proton::INT | 32-bit signed integer
22 uint64_t | proton::ULONG | 64-bit unsigned integer
23 int64_t | proton::LONG | 64-bit signed integer
24 wchar_t | proton::CHAR | 32-bit unicode code point
25 float | proton::FLOAT | 32-bit binary floating point
26 double | proton::DOUBLE | 64-bit binary floating point
27 proton::timestamp | proton::TIMESTAMP | 64-bit signed milliseconds since 00:00:00 (UTC), 1 January 1970.
28 proton::decimal32 | proton::DECIMAL32 | 32-bit decimal floating point
29 proton::decimal64 | proton::DECIMAL64 | 64-bit decimal floating point
30 proton::decimal128 | proton::DECIMAL128 | 128-bit decimal floating point
31 proton::uuid | proton::UUID | 128-bit universally-unique identifier
32 std::string | proton::STRING | UTF-8 encoded Unicode string
33 proton::symbol | proton::SYMBOL | 7-bit ASCII encoded string
34 proton::binary | proton::BINARY | Variable-length binary data
35
36 ## Holder types
37
38 `proton::message::body()` and other message-related data can contain
39 different types of data at runtime. There are two "holder" types
40 provided to hold runtime typed data:
41
42 - `proton::scalar` can hold a scalar value of any type.
43 - `proton::value` can hold any AMQP value, scalar or compound.
44
45 You can set the value in a holder by assignment, and use the
46 `proton::get()` and `proton::coerce()` templates to extract data in a
47 type-safe way. Holders also provide functions to query the type of
48 value they contain.
49
50 ## Compound types
51
52 C++ type | AMQP type_id | Description
53 --------------------|----------------------|-----------------------
54 See below | proton::ARRAY | Sequence of values of the same type
55 See below | proton::LIST | Sequence of values of mixed types
56 See below | proton::MAP | Map of key-value pairs
57
58 A `proton::value` containing a `proton::ARRAY` can convert to and from
59 C++ sequences of the corresponding C++ type: `std::vector`,
60 `std::deque`, `std::list`, and `std::forward_list`.
61
62 `proton::LIST` converts to and from sequences of `proton::value` or
63 `proton::scalar`, which can hold mixed types of data.
64
65 `proton::MAP` converts to and from `std::map`, `std::unordered_map`,
66 and sequences of `std::pair`.
67
68 For example, you can decode a message body with any AMQP map as
69 follows.
70
71 proton::message m = ...;
72 std::map<proton::value, proton::value> map;
73 proton::get(m.body(), map);
74
75 You can encode a message body with a map of string keys and `uint64_t`
76 values like this:
77
78 std::unordered_map<std::string, uint64_t> map;
79 map["foo"] = 123;
80 m.body() = map;
81
82 ## Include files
83
84 `proton/types.hpp` includes all available type definitions and
85 conversions. Alternatively, you can selectively include the `.hpp`
86 files you want.