mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 07:25:55 +02:00
Added reference version of unpacker::next().
This commit is contained in:
parent
e4d32b176e
commit
fd566afeb4
@ -786,6 +786,7 @@ public:
|
||||
|
||||
/*! 4. repeat next() until it retunrs false */
|
||||
bool next(unpacked* result);
|
||||
bool next(unpacked& result);
|
||||
|
||||
/*! 5. check if the size of message doesn't exceed assumption. */
|
||||
std::size_t message_size() const;
|
||||
@ -1058,7 +1059,7 @@ inline void unpacker::buffer_consumed(std::size_t size)
|
||||
m_free -= size;
|
||||
}
|
||||
|
||||
inline bool unpacker::next(unpacked* result)
|
||||
inline bool unpacker::next(unpacked& result)
|
||||
{
|
||||
int ret = execute_imp();
|
||||
|
||||
@ -1067,18 +1068,23 @@ inline bool unpacker::next(unpacked* result)
|
||||
}
|
||||
|
||||
if(ret == 0) {
|
||||
result->zone().reset();
|
||||
result->set(object());
|
||||
result.zone().reset();
|
||||
result.set(object());
|
||||
return false;
|
||||
|
||||
} else {
|
||||
result->zone().reset( release_zone() );
|
||||
result->set(data());
|
||||
result.zone().reset( release_zone() );
|
||||
result.set(data());
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool unpacker::next(unpacked* result)
|
||||
{
|
||||
return next(*result);
|
||||
}
|
||||
|
||||
|
||||
inline bool unpacker::execute()
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user