Skip to content

Commit 11fff6e

Browse files
committed
Remove experimental c++ trait-detection
1 parent 863d337 commit 11fff6e

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

src/MsgPack/Packer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ namespace msgpack {
365365

366366
// ---------- CUSTOM format ----------
367367

368-
template <typename C>
369-
auto pack(const C& c) -> typename std::enable_if<has_to_msgpack<C, Packer&>::value>::type {
370-
c.to_msgpack(*this);
371-
}
368+
// template <typename C>
369+
// auto pack(const C& c) -> typename std::enable_if<has_to_msgpack<C, Packer&>::value>::type {
370+
// c.to_msgpack(*this);
371+
// }
372372

373373
// ---------- Array/Map Size format ----------
374374

src/MsgPack/Types.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,17 @@ namespace msgpack {
260260
MAP4 = 0x0F, // same as FIXMAP
261261
};
262262

263-
template <typename ClassType, typename ArgType>
264-
using has_to_msgpack_impl = typename std::enable_if<
265-
std::is_same<decltype(&ClassType::to_msgpack), void (ClassType::*)(ArgType) const>::value>::type;
266-
template <typename ClassType, typename ArgType>
267-
using has_to_msgpack = arx::is_detected<has_to_msgpack_impl, ClassType, ArgType>;
263+
// template <typename ClassType, typename ArgType>
264+
// using has_to_msgpack_impl = typename std::enable_if<
265+
// std::is_same<decltype(&ClassType::to_msgpack), void (ClassType::*)(ArgType) const>::value>::type;
266+
// template <typename ClassType, typename ArgType>
267+
// using has_to_msgpack = arx::is_detected<has_to_msgpack_impl, ClassType, ArgType>;
268268

269-
template <typename ClassType, typename ArgType>
270-
using has_from_msgpack_impl = typename std::enable_if<
271-
std::is_same<decltype(&ClassType::from_msgpack), void (ClassType::*)(ArgType)>::value>::type;
272-
template <typename ClassType, typename ArgType>
273-
using has_from_msgpack = arx::is_detected<has_from_msgpack_impl, ClassType, ArgType>;
269+
// template <typename ClassType, typename ArgType>
270+
// using has_from_msgpack_impl = typename std::enable_if<
271+
// std::is_same<decltype(&ClassType::from_msgpack), void (ClassType::*)(ArgType)>::value>::type;
272+
// template <typename ClassType, typename ArgType>
273+
// using has_from_msgpack = arx::is_detected<has_from_msgpack_impl, ClassType, ArgType>;
274274

275275
} // namespace msgpack
276276
} // namespace arduino
@@ -279,16 +279,16 @@ namespace msgpack {
279279
void to_msgpack(MsgPack::Packer& packer) const { \
280280
packer.to_array(__VA_ARGS__); \
281281
} \
282-
void from_msgpack(MsgPack::Unpacker& unpacker) { \
283-
unpacker.from_array(__VA_ARGS__); \
282+
bool from_msgpack(MsgPack::Unpacker& unpacker) { \
283+
return unpacker.from_array(__VA_ARGS__); \
284284
}
285285

286286
#define MSGPACK_DEFINE_MAP(...) \
287287
void to_msgpack(MsgPack::Packer& packer) const { \
288288
packer.to_map(__VA_ARGS__); \
289289
} \
290-
void from_msgpack(MsgPack::Unpacker& unpacker) { \
291-
unpacker.from_map(__VA_ARGS__); \
290+
bool from_msgpack(MsgPack::Unpacker& unpacker) { \
291+
return unpacker.from_map(__VA_ARGS__); \
292292
}
293293

294294
#define MSGPACK_BASE(base) (*const_cast<base*>(static_cast<base const*>(this)))

src/MsgPack/Unpacker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ namespace msgpack {
443443

444444
// ---------- CUSTOM format ----------
445445

446-
template <typename C>
447-
auto unpack(C& c) -> typename std::enable_if<has_from_msgpack<C, Unpacker&>::value, bool>::type {
448-
c.from_msgpack(*this);
449-
return b_decode_success;
450-
}
446+
// template <typename C>
447+
// auto unpack(C& c) -> typename std::enable_if<has_from_msgpack<C, Unpacker&>::value, bool>::type {
448+
// c.from_msgpack(*this);
449+
// return b_decode_success;
450+
// }
451451

452452
// ---------- Array/Map Size format ----------
453453

src/decoder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class RpcDecoder {
7979
MsgPack::object::nil_t nil;
8080
if (unpacker.unpackable(nil)){ // No error
8181
if (!unpacker.deserialize(nil, result)) return false;
82-
} else { // RPC returned an error
83-
if (!unpacker.deserialize(error, nil)) return false;
82+
} else {
83+
// RPC returned an error
84+
if (!error.from_msgpack(unpacker)) return false;
85+
if (!unpacker.deserialize(nil)) return false;
8486
}
8587

8688
reset_packet();

src/dispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RpcFunctionDispatcher {
6161

6262
// handler not found
6363
MsgPack::object::nil_t nil;
64-
packer.serialize(RpcError(FUNCTION_NOT_FOUND_ERR, name), nil);
64+
RpcError(FUNCTION_NOT_FOUND_ERR, name).to_msgpack(packer);
6565
return false;
6666
}
6767

src/wrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
5858
// First check the parameters size
5959
if (!unpacker.isArray()){
6060
RpcError error(MALFORMED_CALL_ERR, "Unserializable parameters array");
61-
packer.serialize(error, nil);
61+
error.to_msgpack(packer);
6262
return false;
6363
}
6464

@@ -67,13 +67,13 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
6767
unpacker.deserialize(param_size);
6868
if (param_size.size() < sizeof...(Args)){
6969
RpcError error(MALFORMED_CALL_ERR, "Missing call parameters (WARNING: Default param resolution is not implemented)");
70-
packer.serialize(error, nil);
70+
error.to_msgpack(packer);
7171
return false;
7272
}
7373

7474
if (param_size.size() > sizeof...(Args)){
7575
RpcError error(MALFORMED_CALL_ERR, "Too many parameters");
76-
packer.serialize(error, nil);
76+
error.to_msgpack(packer);
7777
return false;
7878
}
7979

0 commit comments

Comments
 (0)