diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-02-03 14:43:54 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-02-03 18:16:46 +0000 |
commit | 57c297bcc6d3b8ef70ef71d7664c6ad51d104e73 (patch) | |
tree | a1e50f0fe465958e00311bf1873989193d945588 /vespalib | |
parent | 289f313a92af8bc25e0e62a354ab55e64e3bda41 (diff) |
added convenience function to add a single byte
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/data/simple_buffer/simple_buffer_test.cpp | 6 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/data/simple_buffer.h | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/vespalib/src/tests/data/simple_buffer/simple_buffer_test.cpp b/vespalib/src/tests/data/simple_buffer/simple_buffer_test.cpp index 41408797b49..5cc62b327ce 100644 --- a/vespalib/src/tests/data/simple_buffer/simple_buffer_test.cpp +++ b/vespalib/src/tests/data/simple_buffer/simple_buffer_test.cpp @@ -67,4 +67,10 @@ TEST("simple buffer") { } } +TEST("require that add works as expected") { + SimpleBuffer buf; + buf.add('a').add('b').add('c'); + EXPECT_EQUAL(buf.get(), Memory("abc")); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/vespa/vespalib/data/simple_buffer.h b/vespalib/src/vespa/vespalib/data/simple_buffer.h index 3f0d5f975de..ef3b6d284dc 100644 --- a/vespalib/src/vespa/vespalib/data/simple_buffer.h +++ b/vespalib/src/vespa/vespalib/data/simple_buffer.h @@ -28,6 +28,11 @@ public: Input &evict(size_t bytes) override; WritableMemory reserve(size_t bytes) override; Output &commit(size_t bytes) override; + SimpleBuffer &add(char c) { + _data.push_back(c); + ++_used; + return *this; + } Memory get() const { return Memory(&_data[0], _used); } bool operator==(const SimpleBuffer &rhs) const { return (get() == rhs.get()); } }; |