summaryrefslogtreecommitdiff
path: root/cpp/unpack.hpp
blob: 61ba781a036d2e811520709d551a6b381096fcfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef MSGPACK_UNPACK_HPP__
#define MSGPACK_UNPACK_HPP__

#include "msgpack/object.hpp"
#include "msgpack/zone.hpp"
#include <stdexcept>

namespace msgpack {


struct unpack_error : public std::runtime_error {
	unpack_error(const std::string& msg) :
		std::runtime_error(msg) { }
};


class unpacker {
public:
	unpacker(zone& z);
	~unpacker();
public:
	size_t execute(const void* data, size_t len, size_t off);
	bool is_finished() { return m_finished; }
	object data();
	void reset();
private:
	struct context;
	context* m_ctx;
	zone& m_zone;
	bool m_finished;
private:
	unpacker();
	unpacker(const unpacker&);
public:
	static object unpack(const void* data, size_t len, zone& z);
};


inline object unpack(const void* data, size_t len, zone& z)
{
	return unpacker::unpack(data, len, z);
}


}  // namespace msgpack

#endif /* msgpack/unpack.hpp */