1 #ifndef PROTON_CODEC_ENCODER_HPP
2 #define PROTON_CODEC_ENCODER_HPP
26 #include "../internal/type_traits.hpp"
27 #include "../types_fwd.hpp"
47 explicit encoder(
const data& d) : data(d) {}
50 PN_CPP_EXTERN
explicit encoder(internal::value_base& v);
60 PN_CPP_EXTERN
bool encode(
char* buffer,
size_t& size);
64 PN_CPP_EXTERN
void encode(std::string&);
68 PN_CPP_EXTERN std::string
encode();
72 PN_CPP_EXTERN
encoder& operator<<(
bool);
73 PN_CPP_EXTERN
encoder& operator<<(uint8_t);
74 PN_CPP_EXTERN
encoder& operator<<(int8_t);
75 PN_CPP_EXTERN
encoder& operator<<(uint16_t);
76 PN_CPP_EXTERN
encoder& operator<<(int16_t);
77 PN_CPP_EXTERN
encoder& operator<<(uint32_t);
78 PN_CPP_EXTERN
encoder& operator<<(int32_t);
79 PN_CPP_EXTERN
encoder& operator<<(
wchar_t);
80 PN_CPP_EXTERN
encoder& operator<<(uint64_t);
81 PN_CPP_EXTERN
encoder& operator<<(int64_t);
83 PN_CPP_EXTERN
encoder& operator<<(
float);
84 PN_CPP_EXTERN
encoder& operator<<(
double);
89 PN_CPP_EXTERN
encoder& operator<<(
const std::string&);
92 PN_CPP_EXTERN
encoder& operator<<(
const internal::scalar_base&);
93 PN_CPP_EXTERN
encoder& operator<<(
const null&);
100 PN_CPP_EXTERN
encoder& operator<<(
const internal::value_base&);
111 template <
class T>
void* operator<<(
const T*);
113 template <
class T>
struct list_cref { T& ref; list_cref(T& r) : ref(r) {} };
114 template <
class T>
struct map_cref { T& ref; map_cref(T& r) : ref(r) {} };
116 template <
class T>
struct array_cref {
119 array_cref(T& r,
type_id el,
bool described) : array_start(
ARRAY, el, described), ref(r) {}
122 template <
class T>
static list_cref<T> list(T& x) {
return list_cref<T>(x); }
123 template <
class T>
static map_cref<T> map(T& x) {
return map_cref<T>(x); }
124 template <
class T>
static array_cref<T> array(T& x,
type_id element,
bool described=
false) {
125 return array_cref<T>(x, element, described);
128 template <
class T>
encoder& operator<<(const map_cref<T>& x) {
129 state_guard sg(*
this);
130 *
this << start::map();
131 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
132 *
this << i->first << i->second;
137 template <
class T>
encoder& operator<<(const list_cref<T>& x) {
138 state_guard sg(*
this);
139 *
this << start::list();
140 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
146 template <
class T>
encoder& operator<<(const array_cref<T>& x) {
147 state_guard sg(*
this);
148 *
this << x.array_start;
149 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
157 template<
class T,
class U>
encoder& insert(
const T& x,
int (*put)(pn_data_t*, U));
158 void check(
long result);
165 template <
class T>
typename internal::enable_if<internal::is_unknown_integer<T>::value, encoder&>::type
167 using namespace internal;
168 return e << static_cast<typename integer_type<sizeof(T), is_signed<T>::value>::type>(i);
173 namespace is_encodable_impl {
175 using namespace internal;
177 sfinae::no
operator<<(sfinae::wildcard, sfinae::wildcard);
179 template<
typename T>
struct is_encodable :
public sfinae {
180 static yes test(encoder);
184 static bool const value =
sizeof(test(e << t)) ==
sizeof(yes);
188 template <>
struct is_encodable<value> :
public true_type {};
192 using is_encodable_impl::is_encodable;
Experimental - Start encoding a complex type.
Definition: data.hpp:105
Experimental - Stream-like encoder from AMQP bytes to C++ values.
Definition: encoder.hpp:44
A sequence of values of the same type.
Definition: type_id.hpp:61
encoder & operator<<(encoder &e, const std::deque< T, A > &x)
std::deque<T> for most T is encoded as an amqp::ARRAY (same type elements)
Definition: deque.hpp:34
A 16-byte universally unique identifier.
Definition: uuid.hpp:34
64-bit decimal floating point.
Definition: decimal.hpp:51
encoder(const data &d)
Wrap Proton-C data object.
Definition: encoder.hpp:47
A std::string that represents the AMQP symbol type.
Definition: symbol.hpp:30
Arbitrary binary data.
Definition: binary.hpp:34
128-bit decimal floating point.
Definition: decimal.hpp:54
type_id
An identifier for AMQP types.
Definition: type_id.hpp:38
32-bit decimal floating point.
Definition: decimal.hpp:48
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:30
A holder for any AMQP value, simple or complex.
Definition: value.hpp:69
std::string encode()
Encode the current values into a std::string.
Experimental - Finish inserting or extracting a complex type.
Definition: data.hpp:128