lang/c/msgpack: C++ binding: support non-MessagePack message that follows after MessagePack message

git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@56 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
frsyuki
2009-02-15 09:09:56 +00:00
parent 990ac38ccd
commit 7e6b55a718
3 changed files with 64 additions and 7 deletions

View File

@@ -169,7 +169,10 @@ int main(void)
msgpack::unpacker upk;
while(stream.good() && total_bytes > 0) {
// 1. reserve buffer
upk.reserve_buffer(RESERVE_SIZE);
// 2. read data to buffer() up to buffer_capacity() bytes
size_t sz = stream.readsome(
(char*)upk.buffer(),
upk.buffer_capacity());
@@ -179,14 +182,24 @@ int main(void)
<< upk.buffer_capacity() << " bytes"
<< std::endl;
// 3. specify the number of bytes actually copied
upk.buffer_consumed(sz);
// 4. repeat execute() until it returns false
while( upk.execute() ) {
std::cout << "message parsed" << std::endl;
boost::scoped_ptr<msgpack::zone> pz(upk.release_zone());
// 5.1. take out the parsed object
msgpack::object o = upk.data();
upk.reset();
// 5.2. the parsed object is valid until the zone is deleted
boost::scoped_ptr<msgpack::zone> pz(upk.release_zone());
std::cout << o << std::endl;
++num_msg;
// 5.3 re-initialize unpacker
upk.reset();
}
}