summaryrefslogtreecommitdiff
path: root/cpp/unpack.hpp
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
committerfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
commit7e6b55a71805dabb2ad82bf6802ea81f36bc911a (patch)
tree6a9173e7225d6f30c55bbfa3a0212cff1932b965 /cpp/unpack.hpp
parent990ac38ccdb51acc520fa43c99115cb216ec95e6 (diff)
downloadmsgpack-python-7e6b55a71805dabb2ad82bf6802ea81f36bc911a.tar.gz
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
Diffstat (limited to 'cpp/unpack.hpp')
-rw-r--r--cpp/unpack.hpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/cpp/unpack.hpp b/cpp/unpack.hpp
index df4a636..ae536c9 100644
--- a/cpp/unpack.hpp
+++ b/cpp/unpack.hpp
@@ -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);