11 #ifndef MSGPACK_V1_TYPE_CPP20_SPAN_HPP
12 #define MSGPACK_V1_TYPE_CPP20_SPAN_HPP
17 #if MSGPACK_CPP_VERSION > 201703
36 #define MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY(byte_t) \
38 struct convert<std::span<const byte_t> > { \
39 msgpack::object const& operator()(msgpack::object const& o, std::span<const byte_t>& v) const { \
41 case msgpack::type::BIN: \
42 v = std::span(reinterpret_cast<const byte_t*>(o.via.bin.ptr), o.via.bin.size); \
45 throw msgpack::type_error(); \
52 #define MSGPACK_ADAPTOR_PACK_SPAN_BINARY(byte_t) \
54 struct pack<std::span<byte_t> > { \
55 template <typename Stream> \
56 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::span<byte_t>& v) const { \
57 uint32_t size = checked_get_container_size(v.size()); \
60 o.pack_bin_body(reinterpret_cast<char const*>(v.data()), size); \
66 #define MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(byte_t) \
68 struct object<std::span<byte_t> > { \
69 void operator()(msgpack::object& o, const std::span<byte_t>& v) const { \
70 uint32_t size = checked_get_container_size(v.size()); \
71 o.type = msgpack::type::BIN; \
73 o.via.bin.ptr = reinterpret_cast<char const*>(v.data()); \
75 o.via.bin.size = size; \
79 #define MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(byte_t) \
81 struct object_with_zone<std::span<byte_t> > { \
82 void operator()(msgpack::object::with_zone& o, const std::span<byte_t>& v) const { \
83 uint32_t size = checked_get_container_size(v.size()); \
84 o.type = msgpack::type::BIN; \
85 o.via.bin.size = size; \
87 char* ptr = static_cast<char*>(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char))); \
88 o.via.bin.ptr = ptr; \
89 std::memcpy(ptr, v.data(), size); \
94 #define MSGPACK_ADAPTOR_SPAN_BINARY(byte_t) \
95 MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY(byte_t) \
96 MSGPACK_ADAPTOR_PACK_SPAN_BINARY(byte_t) \
97 MSGPACK_ADAPTOR_PACK_SPAN_BINARY(const byte_t) \
98 MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(byte_t) \
99 MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(const byte_t) \
100 MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(byte_t) \
101 MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(const byte_t)
103 MSGPACK_ADAPTOR_SPAN_BINARY(
char)
104 MSGPACK_ADAPTOR_SPAN_BINARY(
unsigned char)
105 MSGPACK_ADAPTOR_SPAN_BINARY(std::byte)
107 #undef MSGPACK_ADAPTOR_SPAN_BINARY
108 #undef MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY
109 #undef MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY
110 #undef MSGPACK_ADAPTOR_PACK_SPAN_BINARY
111 #undef MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY
Definition: adaptor_base.hpp:15
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66