Added reference version of unpacker::next().

This commit is contained in:
Takatoshi Kondo
2014-08-04 00:52:04 +09:00
parent e4d32b176e
commit fd566afeb4
2 changed files with 57 additions and 5 deletions

View File

@@ -17,6 +17,52 @@ TEST(streaming, basic)
msgpack::unpacker pac;
msgpack::unpacked result;
int count = 0;
while(count < 3) {
pac.reserve_buffer(32*1024);
// read buffer into pac.buffer() upto
// pac.buffer_capacity() bytes.
size_t len = 1;
memcpy(pac.buffer(), input, len);
input += len;
pac.buffer_consumed(len);
while(pac.next(result)) {
msgpack::object obj = result.get();
switch(count++) {
case 0:
EXPECT_EQ(1, obj.as<int>());
break;
case 1:
EXPECT_EQ(2, obj.as<int>());
break;
case 2:
EXPECT_EQ(3, obj.as<int>());
return;
}
}
EXPECT_TRUE(input < eof);
}
}
TEST(streaming, basic_pointer)
{
msgpack::sbuffer buffer;
msgpack::packer<msgpack::sbuffer> pk(&buffer);
pk.pack(1);
pk.pack(2);
pk.pack(3);
const char* input = buffer.data();
const char* const eof = input + buffer.size();
msgpack::unpacker pac;
msgpack::unpacked result;
int count = 0;
while(count < 3) {
pac.reserve_buffer(32*1024);