1 #ifndef PROTON_CODEC_DECODER_HPP 2 #define PROTON_CODEC_DECODER_HPP 25 #include "../internal/data.hpp" 26 #include "../internal/type_traits.hpp" 27 #include "../types_fwd.hpp" 28 #include "./common.hpp" 30 #include <proton/type_compat.h> 58 explicit decoder(
const data& d,
bool exact=
false) : data(d), exact_(exact) {}
62 PN_CPP_EXTERN
explicit decoder(
const internal::value_base&,
bool exact=
false);
66 PN_CPP_EXTERN
void decode(
const char* buffer,
size_t size);
70 PN_CPP_EXTERN
void decode(
const std::string&);
73 PN_CPP_EXTERN
bool more();
80 PN_CPP_EXTERN
type_id next_type();
89 PN_CPP_EXTERN decoder& operator>>(uint8_t&);
90 PN_CPP_EXTERN decoder& operator>>(int8_t&);
91 PN_CPP_EXTERN decoder& operator>>(uint16_t&);
92 PN_CPP_EXTERN decoder& operator>>(int16_t&);
93 PN_CPP_EXTERN decoder& operator>>(uint32_t&);
94 PN_CPP_EXTERN decoder& operator>>(int32_t&);
95 PN_CPP_EXTERN decoder& operator>>(
wchar_t&);
96 PN_CPP_EXTERN decoder& operator>>(uint64_t&);
97 PN_CPP_EXTERN decoder& operator>>(int64_t&);
98 PN_CPP_EXTERN decoder& operator>>(
timestamp&);
99 PN_CPP_EXTERN decoder& operator>>(
float&);
100 PN_CPP_EXTERN decoder& operator>>(
double&);
101 PN_CPP_EXTERN decoder& operator>>(
decimal32&);
102 PN_CPP_EXTERN decoder& operator>>(
decimal64&);
103 PN_CPP_EXTERN decoder& operator>>(
decimal128&);
104 PN_CPP_EXTERN decoder& operator>>(
uuid&);
105 PN_CPP_EXTERN decoder& operator>>(std::string&);
106 PN_CPP_EXTERN decoder& operator>>(
symbol&);
107 PN_CPP_EXTERN decoder& operator>>(
binary&);
108 PN_CPP_EXTERN decoder& operator>>(
message_id&);
110 PN_CPP_EXTERN decoder& operator>>(
scalar&);
111 PN_CPP_EXTERN decoder& operator>>(internal::value_base&);
112 PN_CPP_EXTERN decoder& operator>>(null&);
119 PN_CPP_EXTERN decoder& operator>>(
start&);
123 PN_CPP_EXTERN decoder& operator>>(
const finish&);
126 template <
class T>
struct sequence_ref { T& ref; sequence_ref(T& r) : ref(r) {} };
127 template <
class T>
struct associative_ref { T& ref; associative_ref(T& r) : ref(r) {} };
128 template <
class T>
struct pair_sequence_ref { T& ref; pair_sequence_ref(T& r) : ref(r) {} };
130 template <
class T>
static sequence_ref<T> sequence(T& x) {
return sequence_ref<T>(x); }
131 template <
class T>
static associative_ref<T> associative(T& x) {
return associative_ref<T>(x); }
132 template <
class T>
static pair_sequence_ref<T> pair_sequence(T& x) {
return pair_sequence_ref<T>(x); }
141 if (s.is_described) next();
142 r.ref.resize(s.size);
143 for (
typename T::iterator i = r.ref.begin(); i != r.ref.end(); ++i)
149 template <
class T> decoder&
operator>>(associative_ref<T> r) {
150 using namespace internal;
155 for (
size_t i = 0; i < s.size/2; ++i) {
156 typename remove_const<typename T::key_type>::type k;
157 typename remove_const<typename T::mapped_type>::type v;
166 template <
class T> decoder&
operator>>(pair_sequence_ref<T> r) {
167 using namespace internal;
172 for (
size_t i = 0; i < s.size/2; ++i) {
173 typedef typename T::value_type value_type;
174 typename remove_const<typename value_type::first_type>::type k;
175 typename remove_const<typename value_type::second_type>::type v;
177 r.ref.push_back(value_type(k, v));
184 template <
class T,
class U> decoder& extract(T& x, U (*
get)(pn_data_t*));
192 template<
class T> T
get(
decoder& d) {
202 template <
class T>
typename internal::enable_if<internal::is_unknown_integer<T>::value,
decoder&>::type
204 using namespace internal;
205 typename integer_type<sizeof(T), is_signed<T>::value>::type v;
214 #endif // PROTON_CODEC_DECODER_HPP A holder for an instance of any scalar AMQP type.
Definition: scalar.hpp:32
An AMQP message.
Definition: message.hpp:47
Experimental - Start encoding a complex type.
Definition: common.hpp:31
A key for use with AMQP annotation maps.
Definition: annotation_key.hpp:35
A sequence of key-value pairs.
Definition: type_id.hpp:63
A 16-byte universally unique identifier.
Definition: uuid.hpp:34
decoder & operator>>(sequence_ref< T > r)
Extract any AMQP sequence (ARRAY, LIST or MAP) to a C++ sequence container of T if the elements types...
Definition: decoder.hpp:138
decoder & operator>>(associative_ref< T > r)
Extract an AMQP MAP to a C++ associative container.
Definition: decoder.hpp:149
64-bit decimal floating point.
Definition: decimal.hpp:49
A std::string that represents the AMQP symbol type.
Definition: symbol.hpp:32
Arbitrary binary data.
Definition: binary.hpp:37
128-bit decimal floating point.
Definition: decimal.hpp:52
type_id
An identifier for AMQP types.
Definition: type_id.hpp:38
32-bit decimal floating point.
Definition: decimal.hpp:46
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:32
decoder & operator>>(pair_sequence_ref< T > r)
Extract an AMQP MAP to a C++ push_back sequence of pairs preserving encoded order.
Definition: decoder.hpp:166
void assert_type_equal(type_id want, type_id got)
Throw a conversion_error if want != got with a message including the names of the types...
internal::enable_if< internal::is_unknown_integer< T >::value, decoder & >::type operator>>(decoder &d, T &i)
operator>> for integer types that are not covered by the standard overrides.
Definition: decoder.hpp:203
Experimental - Finish inserting or extracting a complex type.
Definition: common.hpp:54
decoder(const data &d, bool exact=false)
Wrap a Proton C data object.
Definition: decoder.hpp:58
The main Proton namespace.
Definition: annotation_key.hpp:30
Experimental - Stream-like decoder from AMQP bytes to C++ values.
Definition: decoder.hpp:53
An AMQP message ID.
Definition: message_id.hpp:44