2#ifdef MSGPACK_DEFINE_MAP
3#error "webcface/common/internal/pack.h must be included first"
14#ifdef WEBCFACE_COMPILER_IS_GCC
15#pragma GCC diagnostic push
16#pragma GCC diagnostic ignored "-Wabi"
18#include <spdlog/logger.h>
19#ifdef WEBCFACE_COMPILER_IS_GCC
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));
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()));
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::MutableNumVector> {
191 msgpack::object
const &operator()(msgpack::object
const &o,
193 if (o.type != msgpack::type::ARRAY) {
194 throw msgpack::type_error();
196 if (o.via.array.size == 0) {
198 }
else if (o.via.array.size == 1) {
199 v.assign(o.via.array.ptr[0].as<
double>());
201 std::vector<double> vec(o.via.array.size);
202 for (std::size_t i = 0; i < o.via.array.size; i++) {
203 vec.at(i) = o.via.array.ptr[i].as<
double>();
205 v.assign(std::move(vec));
212 template <
typename Stream>
213 msgpack::packer<Stream> &
214 operator()(msgpack::packer<Stream> &o,
216 o.pack_array(
static_cast<std::uint32_t
>(
v.size()));
224 template <
typename T>
225 struct EmptyConvert {
226 msgpack::object
const &operator()(msgpack::object
const &o, T &)
const {
230 template <
typename T>
232 template <
typename Stream>
233 msgpack::packer<Stream> &operator()(msgpack::packer<Stream> &o,
240 struct convert<
webcface::message::Ping>
241 :
public EmptyConvert<webcface::message::Ping> {};
243 struct convert<
webcface::message::PingStatusReq>
244 :
public EmptyConvert<webcface::message::PingStatusReq> {};
247 :
public EmptyPack<webcface::message::Ping> {};
250 :
public EmptyPack<webcface::message::PingStatusReq> {};
shared_ptrで管理されているdoubleのvector
Definition num_vector.h:56
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:159
static SharedString fromU8String(std::string u8s)
Definition encoding.cc:106
数値、文字列などの値を相互変換するクラス
Definition val_adaptor.h:87
int v
Definition latency-value.cc:38
webcface::ValAdaptor ValAdaptor
Definition val_adaptor.h:442
webcface::SharedString SharedString
Definition encoding.h:282
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:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117