libassetmap  1.0.0
Hash-table based archive format containing compressed data
MemOps.h
1 #ifndef LIBASSETMAP_MEMOPS_H
2 #define LIBASSETMAP_MEMOPS_H
3 
4 #include <cstdint>
5 #include <type_traits>
6 
7 namespace AssetMap {
8  using lam_size_t = LIBARCHIVEMAP_SIZE_TYPE;
9 
20  template <typename T>
21  constexpr inline void PutValue(uint8_t* buf, T value) noexcept {
22  static_assert(std::is_same_v<uint8_t, unsigned char>);
23  static_assert(std::is_integral_v<T>, "Only integral values permitted");
24  for (auto i = 0; i < sizeof(T); ++i)
25  buf[i] = (value >> (8 * i)) & 0xFF;
26  }
27 
33  template <typename T>
34  constexpr inline T GetValue(const uint8_t* buf) noexcept {
35  static_assert(std::is_integral_v<T>, "Only integral values permitted");
36  T ret = 0;
37  for (auto i = 0; i < sizeof(T); ++i)
38  ret |= buf[i] << (8 * i);
39  return ret;
40  }
41 
42  constexpr auto PutLamSizeT = PutValue<lam_size_t>;
43  constexpr auto GetLamSizeT = GetValue<lam_size_t>;
44 } // namespace AssetMap
45 
46 #endif // LIBASSETMAP_MEMOPS_H
AssetMap::PutValue
constexpr void PutValue(uint8_t *buf, T value) noexcept
Writes any integral value, byte-by-byte to a memory location.
Definition: MemOps.h:21
AssetMap::GetValue
constexpr T GetValue(const uint8_t *buf) noexcept
Reads any integral value byte-by-byte and return it.
Definition: MemOps.h:34
AssetMap
Definition: DirectoryMetadata.h:65