CatapultServer  v0.5.0.1 (Elephant)
CacheChangesSerializer.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "CacheChanges.h"
23 #include "catapult/io/PodIoUtils.h"
24 #include "catapult/io/Stream.h"
25 #include <vector>
26 
27 namespace catapult { namespace cache {
28 
30  template<typename TSerializer, typename TCacheDelta, typename TValue>
32  auto writeAllFrom = [&outputStream](const auto& source) {
33  for (const auto* pValue : source)
34  TSerializer::Save(*pValue, outputStream);
35  };
36 
37  const auto& addedElements = changes.addedElements();
38  const auto& removedElements = changes.removedElements();
39  const auto& modifiedElements = changes.modifiedElements();
40 
41  io::Write64(outputStream, addedElements.size());
42  io::Write64(outputStream, removedElements.size());
43  io::Write64(outputStream, modifiedElements.size());
44 
45  writeAllFrom(addedElements);
46  writeAllFrom(removedElements);
47  writeAllFrom(modifiedElements);
48  }
49 
51  template<typename TSerializer, typename TValue>
53  auto readAllInto = [&inputStream](auto& dest, auto count) {
54  for (auto i = 0u; i < count; ++i)
55  dest.push_back(TSerializer::Load(inputStream));
56  };
57 
58  auto numAdded = io::Read64(inputStream);
59  auto numRemoved = io::Read64(inputStream);
60  auto numCopied = io::Read64(inputStream);
61 
62  readAllInto(changes.Added, numAdded);
63  readAllInto(changes.Removed, numRemoved);
64  readAllInto(changes.Copied, numCopied);
65  }
66 }}
catapult::cache::WriteCacheChanges
void WriteCacheChanges(const SingleCacheChangesT< TCacheDelta, TValue > &changes, io::OutputStream &outputStream)
Writes serialized cache changes into outputStream.
Definition: CacheChangesSerializer.h:31
catapult::cache::MemoryCacheChangesT::Added
std::vector< TValue > Added
Added elements.
Definition: CacheChanges.h:40
catapult::cache::SingleCacheChangesT
Provides common view of single sub cache changes.
Definition: CacheChanges.h:59
catapult::io::InputStream
Reader interface.
Definition: Stream.h:27
catapult::cache::MemoryCacheChangesT::Copied
std::vector< TValue > Copied
Copied elements.
Definition: CacheChanges.h:46
catapult::cache::ReadCacheChanges
void ReadCacheChanges(io::InputStream &inputStream, MemoryCacheChangesT< TValue > &changes)
Reads serialized cache changes from inputStream.
Definition: CacheChangesSerializer.h:52
catapult::cache::MemoryCacheChangesT
Deserialized cache changes for a single cache.
Definition: CacheChanges.h:38
CacheChanges.h
catapult::io::Write64
void Write64(TIo &output, uint64_t value)
Writes value into output.
Definition: PodIoUtils.h:36
catapult::cache::SingleCacheChangesT::addedElements
PointerContainer addedElements() const
Gets pointers to all added elements.
Definition: CacheChanges.h:78
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::io::Read64
auto Read64(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:66
PodIoUtils.h
catapult::cache::MemoryCacheChangesT::Removed
std::vector< TValue > Removed
Removed elements.
Definition: CacheChanges.h:43
catapult::cache::SingleCacheChangesT::modifiedElements
PointerContainer modifiedElements() const
Gets pointers to all modified elements.
Definition: CacheChanges.h:83
Stream.h
catapult::io::OutputStream
Writer interface.
Definition: Stream.h:41
catapult::cache::SingleCacheChangesT::removedElements
PointerContainer removedElements() const
Gets pointers to all removed elements.
Definition: CacheChanges.h:88