CatapultServer  v0.5.0.1 (Elephant)
StateVersion.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/io/PodIoUtils.h"
23 #include "catapult/io/Stream.h"
24 #include "catapult/exceptions.h"
25 
26 namespace catapult { namespace cache {
27 
29  template<typename TSerializerTraits>
30  struct StateVersion {
32  static void Write(io::OutputStream& output) {
33  io::Write16(output, TSerializerTraits::State_Version);
34  }
35 
37  static void ReadAndCheck(io::InputStream& input) {
38  auto version = io::Read16(input);
39  if (TSerializerTraits::State_Version != version)
40  CATAPULT_THROW_RUNTIME_ERROR_1("serialized state has invalid version", version);
41  }
42  };
43 }}
exceptions.h
catapult::io::Write16
void Write16(TIo &output, uint16_t value)
Writes value into output.
Definition: PodIoUtils.h:48
catapult::cache::StateVersion::ReadAndCheck
static void ReadAndCheck(io::InputStream &input)
Reads state version from input and verifies it.
Definition: StateVersion.h:37
CATAPULT_THROW_RUNTIME_ERROR_1
#define CATAPULT_THROW_RUNTIME_ERROR_1(MESSAGE, PARAM1)
Macro used to throw a catapult runtime error with a single parameter.
Definition: exceptions.h:171
catapult::io::InputStream
Reader interface.
Definition: Stream.h:27
catapult::cache::StateVersion::Write
static void Write(io::OutputStream &output)
Writes state version to output.
Definition: StateVersion.h:32
catapult::io::Read16
auto Read16(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:82
catapult::cache::StateVersion
State version serialization helpers.
Definition: StateVersion.h:30
catapult
Definition: AddressExtractionExtension.cpp:28
PodIoUtils.h
Stream.h
catapult::io::OutputStream
Writer interface.
Definition: Stream.h:41