2#ifdef MSGPACK_DEFINE_MAP
3#error "webcface/common/internal/pack.h must be included first"
14#if defined(__GNUC__) && !defined(__clang__)
15#pragma GCC diagnostic push
16#pragma GCC diagnostic ignored "-Wabi"
18#include <spdlog/logger.h>
19#if defined(__GNUC__) && !defined(__clang__)
20#pragma GCC diagnostic pop
40std::vector<std::pair<int, std::shared_ptr<void>>>
41unpack(
const std::string &message,
42 const std::shared_ptr<spdlog::logger> &logger);
50 msgpack::type::tuple<int, T> src(
static_cast<int>(T::kind), obj);
51 std::stringstream buffer;
52 msgpack::pack(buffer, src);
61void pack(std::stringstream &buffer,
int &len,
const T &obj) {
62 msgpack::pack(buffer,
static_cast<int>(T::kind));
63 msgpack::pack(buffer, obj);
67inline std::string
packDone(std::stringstream &buffer,
int len) {
68 std::stringstream buffer2;
69 msgpack::packer packer(buffer2);
70 packer.pack_array(len);
71 buffer2 << buffer.rdbuf();
79MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
92 template <
typename Stream>
93 packer<Stream> &operator()(msgpack::packer<Stream> &o,
double v)
const {
97 v <=
double(std::numeric_limits<uint64_t>::max()) &&
98 v ==
static_cast<double>(
static_cast<uint64_t
>(v))) {
99 o.pack_uint64(
static_cast<std::uint64_t
>(v));
102 v >=
double(std::numeric_limits<int64_t>::min()) &&
103 v ==
static_cast<double>(
static_cast<int64_t
>(v))) {
104 o.pack_int64(
static_cast<std::int64_t
>(v));
106 }
else if (std::abs(v) <= std::numeric_limits<float>::max() &&
107 v ==
static_cast<double>(
static_cast<float>(v))) {
108 o.pack_float(
static_cast<float>(v));
118 struct convert<
webcface::SharedString> {
119 msgpack::object
const &operator()(msgpack::object
const &o,
122 std::string(o.via.bin.ptr, o.via.bin.size)));
128 template <
typename Stream>
129 msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o,
131 o.pack(std::string_view(
v.u8StringView()));
137 struct convert<
webcface::ValAdaptor> {
138 msgpack::object
const &operator()(msgpack::object
const &o,
141 case msgpack::type::FLOAT32:
142 case msgpack::type::FLOAT64:
145 case msgpack::type::POSITIVE_INTEGER:
148 case msgpack::type::NEGATIVE_INTEGER:
151 case msgpack::type::BOOLEAN:
154 case msgpack::type::BIN:
155 case msgpack::type::STR:
157 std::string(o.via.bin.ptr, o.via.bin.size)));
160 throw msgpack::type_error();
167 template <
typename Stream>
168 msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o,
170 switch (
v.valType()) {
172 o.pack(
static_cast<bool>(v));
175 o.pack(
static_cast<std::int64_t
>(v));
178 o.pack(
static_cast<double>(v));
182 o.pack(std::string_view(
v.asU8StringView()));
190 struct convert<
webcface::ValAdaptorVector> {
191 msgpack::object
const &operator()(msgpack::object
const &o,
194 case msgpack::type::ARRAY: {
195 std::vector<webcface::ValAdaptor> vec;
196 vec.reserve(o.via.array.size);
197 for (std::size_t i = 0; i < o.via.array.size; i++) {
213 template <
typename Stream>
214 msgpack::packer<Stream> &
215 operator()(msgpack::packer<Stream> &o,
220 o.pack_array(
static_cast<std::uint32_t
>(
v.size()));
230 struct convert<
webcface::MutableNumVector> {
231 msgpack::object
const &operator()(msgpack::object
const &o,
233 if (o.type != msgpack::type::ARRAY) {
234 throw msgpack::type_error();
236 if (o.via.array.size == 0) {
238 }
else if (o.via.array.size == 1) {
239 v.assign(o.via.array.ptr[0].as<
double>());
241 std::vector<double> vec;
242 vec.reserve(o.via.array.size);
243 for (std::size_t i = 0; i < o.via.array.size; i++) {
244 vec.push_back(o.via.array.ptr[i].as<
double>());
246 v.assign(std::move(vec));
253 template <
typename Stream>
254 msgpack::packer<Stream> &
255 operator()(msgpack::packer<Stream> &o,
257 o.pack_array(
static_cast<std::uint32_t
>(
v.size()));
265 template <
typename T>
266 struct EmptyConvert {
267 msgpack::object
const &operator()(msgpack::object
const &o, T &)
const {
271 template <
typename T>
273 template <
typename Stream>
274 msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o,
281 struct convert<
webcface::message::Ping>
282 :
public EmptyConvert<webcface::message::Ping> {};
284 struct convert<
webcface::message::PingStatusReq>
285 :
public EmptyConvert<webcface::message::PingStatusReq> {};
288 :
public EmptyPack<webcface::message::Ping> {};
291 :
public EmptyPack<webcface::message::PingStatusReq> {};
shared_ptrで管理されているdoubleのvector
Definition num_vector.h:56
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:170
static SharedString fromU8String(std::string u8s)
Definition encoding.cc:136
ValAdaptorのVector.
Definition val_adaptor_vec.h:17
数値、文字列などの値を相互変換するクラス
Definition val_adaptor.h:81
int v
Definition latency-value.cc:38
std::string packDone(std::stringstream &buffer, int len)
Definition pack.h:67
void pack(std::stringstream &buffer, int &len, const T &obj)
メッセージをシリアル化しbufferに追加
Definition pack.h:61
std::vector< std::pair< int, std::shared_ptr< void > > > unpack(const std::string &message, const std::shared_ptr< spdlog::logger > &logger)
msgpackのメッセージをパースし返す
Definition message.cc:53
std::string packSingle(const T &obj)
メッセージ1つを要素数2の配列としてシリアル化
Definition pack.h:49
std::string messageTrace(const std::string &message)
バイナリを16進数の文字列に変換
Definition message.cc:16
ValType
引数や戻り値の型を表すenum
Definition val_adaptor.h:21
#define WEBCFACE_NS_END
Definition webcface-config.h:113
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:112