mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 13:02:13 +01:00
fix msgpack::unpack_return
This commit is contained in:
parent
bdd13859b6
commit
a89dfc70b9
@ -30,6 +30,7 @@ template <typename Stream>
|
|||||||
class packer {
|
class packer {
|
||||||
public:
|
public:
|
||||||
packer(Stream& s);
|
packer(Stream& s);
|
||||||
|
~packer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -129,6 +130,9 @@ private:
|
|||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
packer<Stream>::packer(Stream& s) : m_stream(s) { }
|
packer<Stream>::packer(Stream& s) : m_stream(s) { }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
packer<Stream>::~packer() { }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& packer<Stream>::pack_uint8(uint8_t d)
|
inline packer<Stream>& packer<Stream>::pack_uint8(uint8_t d)
|
||||||
{ _pack_uint8(m_stream, d); return *this; }
|
{ _pack_uint8(m_stream, d); return *this; }
|
||||||
|
@ -128,10 +128,10 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MSGPACK_UNPACK_SUCCESS = 2,
|
UNPACK_SUCCESS = 2,
|
||||||
MSGPACK_UNPACK_EXTRA_BYTES = 1,
|
UNPACK_EXTRA_BYTES = 1,
|
||||||
MSGPACK_UNPACK_CONTINUE = 0,
|
UNPACK_CONTINUE = 0,
|
||||||
MSGPACK_UNPACK_PARSE_ERROR = -1,
|
UNPACK_PARSE_ERROR = -1,
|
||||||
} unpack_return;
|
} unpack_return;
|
||||||
|
|
||||||
static unpack_return unpack(const char* data, size_t len, size_t* off,
|
static unpack_return unpack(const char* data, size_t len, size_t* off,
|
||||||
@ -249,20 +249,20 @@ inline object unpack(const char* data, size_t len, zone& z, size_t* off)
|
|||||||
object result;
|
object result;
|
||||||
|
|
||||||
switch( msgpack::unpack(data, len, off, &z, &result) ) {
|
switch( msgpack::unpack(data, len, off, &z, &result) ) {
|
||||||
case MSGPACK_UNPACK_SUCCESS:
|
case UNPACK_SUCCESS:
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
case MSGPACK_UNPACK_EXTRA_BYTES:
|
case UNPACK_EXTRA_BYTES:
|
||||||
if(off) {
|
if(off) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
throw unpack_error("extra bytes");
|
throw unpack_error("extra bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
case MSGPACK_UNPACK_CONTINUE:
|
case UNPACK_CONTINUE:
|
||||||
throw unpack_error("insufficient bytes");
|
throw unpack_error("insufficient bytes");
|
||||||
|
|
||||||
case MSGPACK_UNPACK_PARSE_ERROR:
|
case UNPACK_PARSE_ERROR:
|
||||||
default:
|
default:
|
||||||
throw unpack_error("parse error");
|
throw unpack_error("parse error");
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,7 @@ int main(void)
|
|||||||
|
|
||||||
// client thread:
|
// client thread:
|
||||||
fwriter writer(pair[1]);
|
fwriter writer(pair[1]);
|
||||||
|
msgpack::packer<fwriter> pk(writer);
|
||||||
|
|
||||||
typedef msgpack::type::tuple<std::string, std::string, std::string> put_t;
|
typedef msgpack::type::tuple<std::string, std::string, std::string> put_t;
|
||||||
typedef msgpack::type::tuple<std::string, std::string> get_t;
|
typedef msgpack::type::tuple<std::string, std::string> get_t;
|
||||||
@ -120,9 +121,9 @@ int main(void)
|
|||||||
put_t req1("put", "apple", "red");
|
put_t req1("put", "apple", "red");
|
||||||
put_t req2("put", "lemon", "yellow");
|
put_t req2("put", "lemon", "yellow");
|
||||||
get_t req3("get", "apple");
|
get_t req3("get", "apple");
|
||||||
msgpack::pack(writer, req1);
|
pk.pack(req1);
|
||||||
msgpack::pack(writer, req2);
|
pk.pack(req2);
|
||||||
msgpack::pack(writer, req3);
|
pk.pack(req3);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user