mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-13 14:45:38 +02:00
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:
17
cpp/test.cpp
17
cpp/test.cpp
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user