7 #ifndef _XDRPP_MARSHAL_H_HEADER_INCLUDED_ 8 #define _XDRPP_MARSHAL_H_HEADER_INCLUDED_ 1 26 u64conv(std::uint64_t u) : u64(u) {}
32 static void get_bytes(
const std::uint32_t *&pr,
void *buf, std::size_t len);
35 static void put_bytes(std::uint32_t *&pr,
const void *buf, std::size_t len);
41 static void put32(std::uint32_t *&p, std::uint32_t v) { *p++ = v; }
42 static void put64(std::uint32_t *&p,
u64conv u) {
47 static std::uint32_t get32(
const std::uint32_t *&p) {
return *p++; }
48 static std::uint64_t get64(
const std::uint32_t *&p) {
59 static void put32(std::uint32_t *&p, std::uint32_t v) {
62 static void put64(std::uint32_t *&p,
u64conv u) {
66 static std::uint32_t get32(
const std::uint32_t *&p) {
return swap32(*p++); }
67 static std::uint64_t get64(
const std::uint32_t *&p) {
80 using Base::put_bytes;
83 std::uint32_t *
const e_;
88 : p_(reinterpret_cast<std::uint32_t *>(start)),
89 e_(reinterpret_cast<std::uint32_t *>(end)) {
90 assert(!(reinterpret_cast<intptr_t>(start) & 3));
91 assert(!(reinterpret_cast<intptr_t>(end) & 3));
97 void check(std::size_t n)
const {
98 if (n > std::size_t(reinterpret_cast<char *>(e_)
99 - reinterpret_cast<char *>(p_)))
100 throw xdr_overflow(
"insufficient buffer space in xdr_generic_put");
103 template<
typename T>
typename std::enable_if<
104 std::is_same<std::uint32_t, typename xdr_traits<T>::uint_type>::value>::type
107 template<
typename T>
typename std::enable_if<
108 std::is_same<std::uint64_t, typename xdr_traits<T>::uint_type>::value>::type
111 template<
typename T>
typename std::enable_if<xdr_traits<T>::is_bytes>::type
112 operator()(
const T &t) {
115 put32(p_, size32(t.size()));
122 template<
typename T>
typename std::enable_if<
133 using Base::get_bytes;
135 const std::uint32_t *p_;
136 const std::uint32_t *
const e_;
141 : p_(reinterpret_cast<const std::uint32_t *>(start)),
142 e_(reinterpret_cast<const std::uint32_t *>(end)) {
143 assert(!(reinterpret_cast<intptr_t>(start) & 3));
146 if (reinterpret_cast<intptr_t>(end) & 3)
154 void check(std::size_t n)
const {
155 if (n > std::size_t(reinterpret_cast<const char *>(e_)
156 - reinterpret_cast<const char *>(p_)))
157 throw xdr_overflow(
"insufficient buffer space in xdr_generic_get");
160 template<
typename T>
typename std::enable_if<
161 std::is_same<std::uint32_t, typename xdr_traits<T>::uint_type>::value>::type
164 template<
typename T>
typename std::enable_if<
165 std::is_same<std::uint64_t, typename xdr_traits<T>::uint_type>::value>::type
168 template<
typename T>
typename std::enable_if<xdr_traits<T>::is_bytes>::type
172 std::uint32_t size = get32(p_);
181 template<
typename T>
typename std::enable_if<
191 #if XDRPP_WORDS_BIGENDIAN 194 #else // !XDRPP_WORDS_BIGENDIAN 199 #endif // !XDRPP_WORDS_BIGENDIAN 208 template<
typename T,
typename...Args>
inline std::size_t
209 xdr_argpack_size(
const T &t,
const Args &...a)
211 return xdr_size(t) + xdr_argpack_size(a...);
214 template<
typename Archive>
inline void 215 xdr_argpack_archive(Archive &)
219 template<
typename Archive,
typename T,
typename...Args>
inline void 220 xdr_argpack_archive(Archive &ar, T &&t, Args &&...args)
222 archive(ar, std::forward<T>(t));
223 xdr_argpack_archive(ar, std::forward<Args>(args)...);
230 template<
typename...Args> msg_ptr
235 xdr_argpack_archive(p, args...);
236 assert(p.p_ == p.e_);
246 xdr_put p (m.data(), m.data()+m.size());
247 xdr_argpack_archive(p, args...);
248 assert(p.p_ == p.e_);
256 template<
typename...Args>
void 260 xdr_argpack_archive(g, args...);
268 void bytes_to_void(
const std::uint8_t *);
269 void bytes_to_void(
const char *);
275 template<
typename Bytes,
typename...Args>
auto 277 -> decltype(detail::bytes_to_void(m.data()))
279 xdr_get g(m.data(), m.data()+m.size());
280 xdr_argpack_archive(g, args...);
286 #endif // !_XDRPP_MARSHAL_H_HEADER_INCLUDED_ static void get_bytes(const std::uint32_t *&pr, void *buf, std::size_t len)
Copy len bytes to buf, then consume 0-3 bytes of padding to make the total number of bytes consumed d...
Constexpr std::uint32_t swap32(std::uint32_t v)
Byteswap 32-bit number.
std::size_t xdr_size(const T &t)
Return the marshaled size of an XDR data type.
Type definitions for xdrc compiler output.
Attempt to exceed the bounds of a variable-length array or string.
Archive type for marshaling to a buffer.
static msg_ptr alloc(std::size_t size)
Allocate a new buffer.
auto xdr_from_opaque(const Bytes &m, Args &...args) -> decltype(detail::bytes_to_void(m.data()))
The reverse of xdr::xdr_to_opaque.
Most of the xdrpp library is encapsulated in the xdr namespace.
Archive type for unmarshaling from a buffer.
msg_ptr xdr_to_msg(const Args &...args)
Marshal one or a series of XDR types into a newly allocated buffer referenced xdr::msg_ptr.
static void put_bytes(std::uint32_t *&pr, const void *buf, std::size_t len)
Copy len bytes from buf, then add 0-3 zero-valued padding bytes to make the overall marshaled length ...
Message buffer with space for marshaled length.
Numeric marshaling mixin that byteswaps all numeric values (thus producing RFC4506 output on a little...
Low-level byteswap and miscellaneous OS compatibility routines.
Metadata for all marshalable XDR types.
Message not multiple of 4 bytes, or cannot fully be parsed.
Numeric marshaling mixin that does not byteswap any numeric values (which will produce RFC4506 output...
opaque_vec xdr_to_opaque(const Args &...args)
Marshal one or a series of XDR types into a newly allocated opaque structure for embedding in other X...
Common utility types and functions for all the marshaling classes.
void xdr_from_msg(const msg_ptr &m, Args &...args)
This does the reverse of xdr::xdr_to_msg, unmarshalling one or more types from a message.