Go to the documentation of this file. 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"
30 #include <proton/type_compat.h>
53 explicit encoder(
const data& d) : data(d) {}
56 PN_CPP_EXTERN
explicit encoder(internal::value_base& v);
66 PN_CPP_EXTERN
bool encode(
char* buffer,
size_t& size);
70 PN_CPP_EXTERN
void encode(std::string&);
78 PN_CPP_EXTERN
encoder& operator<<(
bool);
79 PN_CPP_EXTERN
encoder& operator<<(uint8_t);
80 PN_CPP_EXTERN
encoder& operator<<(int8_t);
81 PN_CPP_EXTERN
encoder& operator<<(uint16_t);
82 PN_CPP_EXTERN
encoder& operator<<(int16_t);
83 PN_CPP_EXTERN
encoder& operator<<(uint32_t);
84 PN_CPP_EXTERN
encoder& operator<<(int32_t);
85 PN_CPP_EXTERN
encoder& operator<<(
wchar_t);
86 PN_CPP_EXTERN
encoder& operator<<(uint64_t);
87 PN_CPP_EXTERN
encoder& operator<<(int64_t);
89 PN_CPP_EXTERN
encoder& operator<<(
float);
90 PN_CPP_EXTERN
encoder& operator<<(
double);
95 PN_CPP_EXTERN
encoder& operator<<(
const std::string&);
99 PN_CPP_EXTERN
encoder& operator<<(
const null&);
117 template <
class T>
void* operator<<(
const T*);
119 template <
class T>
struct list_cref { T& ref; list_cref(T& r) : ref(r) {} };
120 template <
class T>
struct map_cref { T& ref; map_cref(T& r) : ref(r) {} };
122 template <
class T>
struct array_cref {
125 array_cref(T& r,
type_id el,
bool described) : array_start(
ARRAY, el, described), ref(r) {}
128 template <
class T>
static list_cref<T> list(T& x) {
return list_cref<T>(x); }
129 template <
class T>
static map_cref<T> map(T& x) {
return map_cref<T>(x); }
130 template <
class T>
static array_cref<T> array(T& x,
type_id element,
bool described=
false) {
131 return array_cref<T>(x, element, described);
134 template <
class T>
encoder& operator<<(
const map_cref<T>& x) {
135 internal::state_guard sg(*
this);
136 *
this << start::map();
137 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
138 *
this << i->first << i->second;
143 template <
class T>
encoder& operator<<(
const list_cref<T>& x) {
144 internal::state_guard sg(*
this);
145 *
this << start::list();
146 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
152 template <
class T>
encoder& operator<<(
const array_cref<T>& x) {
153 internal::state_guard sg(*
this);
154 *
this << x.array_start;
155 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
163 template<
class T,
class U>
encoder& insert(
const T& x,
int (*put)(pn_data_t*, U));
164 void check(
long result);
171 template <
class T>
typename internal::enable_if<internal::is_unknown_integer<T>::value,
encoder&>::type
173 using namespace internal;
174 return e <<
static_cast<typename integer_type<sizeof(T), is_signed<T>::value
>::type>(i);
179 namespace is_encodable_impl {
181 using namespace internal;
183 sfinae::no
operator<<(encoder
const&,
const sfinae::any_t &);
185 template<
typename T>
struct is_encodable :
public sfinae {
186 static yes test(encoder&);
190 static bool const value =
sizeof(test(*e << *t)) ==
sizeof(yes);
194 template <>
struct is_encodable<value> :
public true_type {};
198 using is_encodable_impl::is_encodable;
201 template <
class M,
class K,
class T,
class Enable =
void>
202 struct is_encodable_map :
public internal::false_type {};
204 template <
class M,
class K,
class T>
struct is_encodable_map<
205 M, K, T, typename internal::enable_if<
206 internal::is_same<K, typename M::key_type>::value &&
207 internal::is_same<T, typename M::mapped_type>::value &&
208 is_encodable<M>::value
210 > :
public internal::true_type {};
A 32-bit decimal floating-point value.
Definition: decimal.hpp:46
The base class for scalar types.
Definition: scalar_base.hpp:60
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
A 64-bit decimal floating-point value.
Definition: decimal.hpp:49
encoder & operator<<(const start &)
Start a complex type.
void encode(std::string &)
Encode the current values into a std::string and resize the string if necessary.
encoder(internal::value_base &v)
Encoder into v. Clears any current value in v.
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:37
encoder & operator<<(const internal::value_base &)
Insert a proton::value.
std::string encode()
Encode the current values into a std::string.
type_id
An identifier for AMQP types.
Definition: type_id.hpp:37
A string that represents the AMQP symbol type.
Definition: symbol.hpp:35
encoder & operator<<(const finish &)
Finish a complex type.
encoder(const data &d)
Wrap Proton-C data object.
Definition: encoder.hpp:53
Unsettled API - Start encoding a complex type.
Definition: common.hpp:34
@ ARRAY
A sequence of values of the same type.
Definition: type_id.hpp:60
bool encode(char *buffer, size_t &size)
Encode the current values into buffer and update size to reflect the number of bytes encoded.
A 16-byte universally unique identifier.
Definition: uuid.hpp:37
Unsettled API - A stream-like encoder from C++ values to AMQP bytes.
Definition: encoder.hpp:50
The main Proton namespace.
Definition: annotation_key.hpp:33
Unsettled API - Finish inserting or extracting a complex type.
Definition: common.hpp:57
A 128-bit decimal floating-point value.
Definition: decimal.hpp:52
Arbitrary binary data.
Definition: binary.hpp:40
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:35