diff options
| author | Dan Engelbrecht <[email protected]> | 2022-11-18 11:35:13 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-18 02:35:13 -0800 |
| commit | 55225621f018904abf7e212320bb784dc64f8ac3 (patch) | |
| tree | 3fb962e9e0553448f9d42612bb078ff072308e1c /zencore/stream.cpp | |
| parent | move BasicFile to zenutil to remove zenstore dependency from zen command (#190) (diff) | |
| download | zen-55225621f018904abf7e212320bb784dc64f8ac3.tar.xz zen-55225621f018904abf7e212320bb784dc64f8ac3.zip | |
Add `import-project` and `export-project` (#183)
* Add `import-project` and `export-project` command line parsing
Diffstat (limited to 'zencore/stream.cpp')
| -rw-r--r-- | zencore/stream.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/zencore/stream.cpp b/zencore/stream.cpp index 8faf90af2..3402e51be 100644 --- a/zencore/stream.cpp +++ b/zencore/stream.cpp @@ -11,10 +11,28 @@ namespace zen { void -BinaryWriter::Write(const void* data, size_t ByteCount, uint64_t Offset) +BinaryWriter::Write(std::initializer_list<const MemoryView> Buffers) { - RwLock::ExclusiveLockScope _(m_Lock); + size_t TotalByteCount = 0; + for (const MemoryView& View : Buffers) + { + TotalByteCount += View.GetSize(); + } + const size_t NeedEnd = m_Offset + TotalByteCount; + if (NeedEnd > m_Buffer.size()) + { + m_Buffer.resize(NeedEnd); + } + for (const MemoryView& View : Buffers) + { + memcpy(m_Buffer.data() + m_Offset, View.GetData(), View.GetSize()); + m_Offset += View.GetSize(); + } +} +void +BinaryWriter::Write(const void* data, size_t ByteCount, uint64_t Offset) +{ const size_t NeedEnd = Offset + ByteCount; if (NeedEnd > m_Buffer.size()) @@ -28,8 +46,6 @@ BinaryWriter::Write(const void* data, size_t ByteCount, uint64_t Offset) void BinaryWriter::Reset() { - RwLock::ExclusiveLockScope _(m_Lock); - m_Buffer.clear(); m_Offset = 0; } @@ -41,6 +57,18 @@ BinaryWriter::Reset() #if ZEN_WITH_TESTS +TEST_CASE("binary.writer.span") +{ + BinaryWriter Writer; + const MemoryView View1("apa", 3); + const MemoryView View2(" ", 1); + const MemoryView View3("banan", 5); + Writer.Write({View1, View2, View3}); + MemoryView Result = Writer.GetView(); + CHECK(Result.GetSize() == 9); + CHECK(memcmp(Result.GetData(), "apa banan", 9) == 0); +} + void stream_forcelink() { |