1 #ifndef PROTON_CODEC_ENCODER_HPP 2 #define PROTON_CODEC_ENCODER_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> 50 explicit encoder(
const data& d) : data(d) {}
53 PN_CPP_EXTERN
explicit encoder(internal::value_base& v);
63 PN_CPP_EXTERN
bool encode(
char* buffer,
size_t& size);
67 PN_CPP_EXTERN
void encode(std::string&);
71 PN_CPP_EXTERN std::string encode();
92 PN_CPP_EXTERN encoder&
operator<<(
const std::string&);
96 PN_CPP_EXTERN encoder&
operator<<(
const null&);
103 PN_CPP_EXTERN encoder&
operator<<(
const internal::value_base&);
114 template <
class T>
void*
operator<<(
const T*);
116 template <
class T>
struct list_cref { T& ref; list_cref(T& r) : ref(r) {} };
117 template <
class T>
struct map_cref { T& ref; map_cref(T& r) : ref(r) {} };
119 template <
class T>
struct array_cref {
122 array_cref(T& r,
type_id el,
bool described) : array_start(
ARRAY, el, described), ref(r) {}
125 template <
class T>
static list_cref<T> list(T& x) {
return list_cref<T>(x); }
126 template <
class T>
static map_cref<T> map(T& x) {
return map_cref<T>(x); }
127 template <
class T>
static array_cref<T> array(T& x,
type_id element,
bool described=
false) {
128 return array_cref<T>(x, element, described);
131 template <
class T> encoder& operator<<(const map_cref<T>& x) {
132 internal::state_guard sg(*
this);
133 *
this << start::map();
134 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
135 *
this << i->first << i->second;
140 template <
class T> encoder& operator<<(const list_cref<T>& x) {
141 internal::state_guard sg(*
this);
142 *
this << start::list();
143 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
149 template <
class T> encoder& operator<<(const array_cref<T>& x) {
150 internal::state_guard sg(*
this);
151 *
this << x.array_start;
152 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
160 template<
class T,
class U> encoder& insert(
const T& x,
int (*put)(pn_data_t*, U));
161 void check(
long result);
168 template <
class T>
typename internal::enable_if<internal::is_unknown_integer<T>::value,
encoder&>::type
170 using namespace internal;
171 return e << static_cast<typename integer_type<sizeof(T), is_signed<T>::value>::type>(i);
176 namespace is_encodable_impl {
178 using namespace internal;
182 template<
typename T>
struct is_encodable :
public sfinae {
187 static bool const value =
sizeof(test(*e << *t)) ==
sizeof(yes);
191 template <>
struct is_encodable<value> :
public true_type {};
195 using is_encodable_impl::is_encodable;
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
Experimental - Start encoding a complex type.
Definition: common.hpp:31
Experimental - Stream-like encoder from C++ values to AMQP bytes.
Definition: encoder.hpp:47
A sequence of values of the same type.
Definition: type_id.hpp:61
A 16-byte universally unique identifier.
Definition: uuid.hpp:34
64-bit decimal floating point.
Definition: decimal.hpp:49
encoder(const data &d)
Wrap Proton-C data object.
Definition: encoder.hpp:50
Base class for scalar types.
Definition: scalar_base.hpp:57
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
A holder for any AMQP value, simple or complex.
Definition: value.hpp:55
Experimental - Finish inserting or extracting a complex type.
Definition: common.hpp:54
The main Proton namespace.
Definition: annotation_key.hpp:30