CatapultServer  v0.5.0.1 (Elephant)
EntityIoUtils.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "PodIoUtils.h"
25 #include <memory>
26 
27 namespace catapult { namespace io {
28 
30  template<typename TIo>
31  void WriteEntity(TIo& output, const model::SizePrefixedEntity& entity) {
32  output.write({ reinterpret_cast<const uint8_t*>(&entity), entity.Size });
33  }
34 
36  template<typename TEntity, typename TIo>
37  std::unique_ptr<TEntity> ReadEntity(TIo& input) {
38  auto entitySize = Read32(input);
39  auto pEntity = utils::MakeUniqueWithSize<TEntity>(entitySize);
40  input.read({ reinterpret_cast<uint8_t*>(pEntity.get()) + sizeof(uint32_t), entitySize - sizeof(uint32_t) });
41  pEntity->Size = entitySize;
42  return pEntity;
43  }
44 }}
MemoryUtils.h
catapult::io::Read32
auto Read32(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:74
catapult::model::SizePrefixedEntity
Binary layout for a size prefixed entity.
Definition: SizePrefixedEntity.h:30
catapult::io::ReadEntity
std::unique_ptr< TEntity > ReadEntity(TIo &input)
Reads size prefixed entity from input.
Definition: EntityIoUtils.h:37
SizePrefixedEntity.h
catapult
Definition: AddressExtractionExtension.cpp:28
PodIoUtils.h
catapult::io::WriteEntity
void WriteEntity(TIo &output, const model::SizePrefixedEntity &entity)
Writes size prefixed entity into output.
Definition: EntityIoUtils.h:31
catapult::model::SizePrefixedEntity::Size
uint32_t Size
Entity size.
Definition: SizePrefixedEntity.h:33