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

@@ -24,15 +24,46 @@ public:
~unpacker();
public:
/*! 1. reserve buffer. at least `len' bytes of capacity will be ready */
void reserve_buffer(size_t len);
/*! 2. read data to the buffer() up to buffer_capacity() bytes */
void* buffer();
size_t buffer_capacity() const;
/*! 3. specify the number of bytes actually copied */
void buffer_consumed(size_t len);
/*! 4. repeat execute() until it retunrs false */
bool execute();
zone* release_zone(); // never throw
/*! 5.1. if execute() returns true, take out the parsed object */
object data();
/*! 5.2. the parsed object is valid until the zone is deleted */
// Note that once release_zone() from unpacker, you must delete it
// otherwise the memrory will leak.
zone* release_zone();
/*! 5.3. after release_zone(), re-initialize unpacker */
void reset();
public:
// These functions are usable when non-MessagePack message follows after
// MessagePack message.
// Note that there are no parsed buffer when execute() returned true.
/*! get address of buffer that is not parsed */
void* nonparsed_buffer();
size_t nonparsed_size() const;
/*! get the number of bytes that is already parsed */
size_t parsed_size() const;
/*! remove unparsed buffer from unpacker */
// Note that reset() leaves non-parsed buffer.
void remove_nonparsed_buffer();
private:
zone* m_zone;
@@ -72,6 +103,19 @@ inline void unpacker::buffer_consumed(size_t len)
}
inline void* unpacker::nonparsed_buffer()
{ return (void*)(((char*)m_buffer)+m_off); }
inline size_t unpacker::nonparsed_size() const
{ return m_used - m_off; }
inline size_t unpacker::parsed_size() const
{ return m_off; }
inline void unpacker::remove_nonparsed_buffer()
{ m_used = m_off; }
inline object unpack(const void* data, size_t len, zone& z)
{
return unpacker::unpack(data, len, z);