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>
118 template <
class T>
void*
operator<<(
const T*);
123 template <
class T>
struct array_cref {
126 array_cref(T& r, type_id el,
bool described) : array_start(
ARRAY, el, described), ref(r) {}
129 template <
class T>
static list_cref<T> list(T& x) {
return list_cref<T>(x); }
130 template <
class T>
static map_cref<T> map(T& x) {
return map_cref<T>(x); }
131 template <
class T>
static array_cref<T> array(T& x,
type_id element,
bool described=
false) {
132 return array_cref<T>(x, element, described);
135 template <
class T>
encoder& operator<<(
const map_cref<T>& x) {
136 internal::state_guard sg(*
this);
137 *
this << start::map();
138 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
139 *
this << i->first << i->second;
144 template <
class T>
encoder& operator<<(
const list_cref<T>& x) {
145 internal::state_guard sg(*
this);
146 *
this << start::list();
147 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
153 template <
class T>
encoder& operator<<(
const array_cref<T>& x) {
154 internal::state_guard sg(*
this);
155 *
this << x.array_start;
156 for (
typename T::const_iterator i = x.ref.begin(); i != x.ref.end(); ++i)
164 template<
class T,
class U>
encoder& insert(
const T& x,
int (*put)(pn_data_t*, U));
165 void check(
long result);
172template <
class T>
typename std::enable_if<internal::is_unknown_integer<T>::value,
encoder&>::type
174 using namespace internal;
182using namespace internal;
184sfinae::no
operator<<(encoder
const&,
const sfinae::any_t &);
195template <>
struct is_encodable<value> :
public std::true_type {};
199using is_encodable_impl::is_encodable;
202template <
class M,
class K,
class T,
class Enable =
void>
203struct is_encodable_map :
public std::false_type {};
205template <
class M,
class K,
class T>
struct is_encodable_map<
206 M, K, T, typename std::enable_if<
207 std::is_same<K, typename M::key_type>::value &&
208 std::is_same<T, typename M::mapped_type>::value &&
209 is_encodable<M>::value
211 > :
public std::true_type {};
Arbitrary binary data.
Definition binary.hpp:40
Unsettled API - A stream-like encoder from C++ values to AMQP bytes.
Definition encoder.hpp:50
bool encode(char *buffer, size_t &size)
Encode the current values into buffer and update size to reflect the number of bytes encoded.
encoder & operator<<(const internal::value_base &)
Insert a proton::value.
encoder(const data &d)
Wrap Proton-C data object.
Definition encoder.hpp:53
encoder & operator<<(const start &)
Start a complex type.
encoder(internal::value_base &v)
Encoder into v. Clears any current value in v.
void encode(std::string &)
Encode the current values into a std::string and resize the string if necessary.
std::string encode()
Encode the current values into a std::string.
encoder & operator<<(const finish &)
Finish a complex type.
A 128-bit decimal floating-point value.
Definition decimal.hpp:52
A 32-bit decimal floating-point value.
Definition decimal.hpp:46
A 64-bit decimal floating-point value.
Definition decimal.hpp:49
A collection of key-value pairs.
Definition map.hpp:69
The type of the AMQP null value.
Definition null.hpp:38
The base class for scalar types.
Definition scalar_base.hpp:60
A string that represents the AMQP symbol type.
Definition symbol.hpp:35
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition timestamp.hpp:35
A 16-byte universally unique identifier.
Definition uuid.hpp:37
A holder for any AMQP value, simple or complex.
Definition value.hpp:57
Unsettled API - Shared codec functions.
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
Unsettled API - Finish inserting or extracting a complex type.
Definition common.hpp:57
Unsettled API - Start encoding a complex type.
Definition common.hpp:34
The main Proton namespace.
Definition annotation_key.hpp:33
type_id
An identifier for AMQP types.
Definition type_id.hpp:37
@ ARRAY
A sequence of values of the same type.
Definition type_id.hpp:60