Skip to content

Commit ad65a08

Browse files
author
pfeatherstone
committed
Added deserialization support for bool
1 parent 924652d commit ad65a08

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

include/msgpack.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <unordered_map>
1111
#include <cstring>
1212
#include <endian.h>
13+
#include "msgpack_error.h"
1314

1415
namespace msgpackcpp
1516
{
@@ -19,6 +20,19 @@ namespace msgpackcpp
1920
const uint8_t format = v ? 0xc3 : 0xc2;
2021
out((const char*)&format, 1);
2122
}
23+
24+
template<class Source>
25+
inline void deserialize(Source& in, bool& v)
26+
{
27+
uint8_t tmp{};
28+
in((char*)&tmp, 1);
29+
if (tmp == 0xc2)
30+
v = false;
31+
else if (tmp == 0xc3)
32+
v = true;
33+
else
34+
throw std::system_error(BAD_FORMAT);
35+
}
2236

2337
template<class Stream>
2438
inline void serialize(Stream&& out, uint8_t v)

0 commit comments

Comments
 (0)