CatapultServer  v0.5.0.1 (Elephant)
PodIoUtils.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include <stdint.h>
25 
26 namespace catapult { namespace io {
27 
29  template<typename TIo, typename TValue, typename TTag, typename TBaseValue>
30  void Write(TIo& output, const utils::BasicBaseValue<TValue, TTag, TBaseValue>& value) {
31  output.write({ reinterpret_cast<const uint8_t*>(&value), sizeof(TValue) });
32  }
33 
35  template<typename TIo>
36  void Write64(TIo& output, uint64_t value) {
37  output.write({ reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t) });
38  }
39 
41  template<typename TIo>
42  void Write32(TIo& output, uint32_t value) {
43  output.write({ reinterpret_cast<const uint8_t*>(&value), sizeof(uint32_t) });
44  }
45 
47  template<typename TIo>
48  void Write16(TIo& output, uint16_t value) {
49  output.write({ reinterpret_cast<const uint8_t*>(&value), sizeof(uint16_t) });
50  }
51 
53  template<typename TIo>
54  void Write8(TIo& output, uint8_t value) {
55  output.write({ reinterpret_cast<const uint8_t*>(&value), sizeof(uint8_t) });
56  }
57 
59  template<typename TIo, typename TValue, typename TTag, typename TBaseValue>
61  input.read({ reinterpret_cast<uint8_t*>(&value), sizeof(TValue) });
62  }
63 
65  template<typename TIo>
66  auto Read64(TIo& input) {
67  uint64_t result;
68  input.read({ reinterpret_cast<uint8_t*>(&result), sizeof(uint64_t) });
69  return result;
70  }
71 
73  template<typename TIo>
74  auto Read32(TIo& input) {
75  uint32_t result;
76  input.read({ reinterpret_cast<uint8_t*>(&result), sizeof(uint32_t) });
77  return result;
78  }
79 
81  template<typename TIo>
82  auto Read16(TIo& input) {
83  uint16_t result;
84  input.read({ reinterpret_cast<uint8_t*>(&result), sizeof(uint16_t) });
85  return result;
86  }
87 
89  template<typename TIo>
90  auto Read8(TIo& input) {
91  uint8_t result;
92  input.read({ reinterpret_cast<uint8_t*>(&result), sizeof(uint8_t) });
93  return result;
94  }
95 
97  template<
98  typename TValue,
99  typename TIo,
100  typename X = std::enable_if_t<utils::traits::is_pod_v<TValue>>
101  >
102  TValue Read(TIo& input) {
103  TValue result;
104  Read(input, result);
105  return result;
106  }
107 }}
catapult::io::Read
void Read(TIo &input, utils::BasicBaseValue< TValue, TTag, TBaseValue > &value)
Reads base value from input.
Definition: PodIoUtils.h:60
catapult::io::Write16
void Write16(TIo &output, uint16_t value)
Writes value into output.
Definition: PodIoUtils.h:48
catapult::io::Write8
void Write8(TIo &output, uint8_t value)
Writes value into output.
Definition: PodIoUtils.h:54
catapult::io::Read32
auto Read32(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:74
catapult::utils::BasicBaseValue
Base class for immutable wrappers of basic types, to provide some type-safety.
Definition: BaseValue.h:30
catapult::io::Read8
auto Read8(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:90
catapult::io::Write
void Write(TIo &output, const utils::BasicBaseValue< TValue, TTag, TBaseValue > &value)
Writes base value into output.
Definition: PodIoUtils.h:30
catapult::io::Write64
void Write64(TIo &output, uint64_t value)
Writes value into output.
Definition: PodIoUtils.h:36
catapult::io::Read16
auto Read16(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:82
Traits.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::io::Read64
auto Read64(TIo &input)
Reads value from input.
Definition: PodIoUtils.h:66
catapult::io::Write32
void Write32(TIo &output, uint32_t value)
Writes value into output.
Definition: PodIoUtils.h:42
BaseValue.h