Kagome
Polkadot Runtime Engine in C++17
ptr_size.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_PTR_SIZE_HPP
7 #define KAGOME_CORE_RUNTIME_PTR_SIZE_HPP
8 
9 #include "runtime/types.hpp"
10 
11 #include <tuple>
12 
13 namespace kagome::runtime {
18  struct PtrSize {
19  constexpr PtrSize() : ptr{0}, size{0} {}
20 
21  explicit PtrSize(WasmSpan v) {
22  std::tie(ptr, size) = splitSpan(v);
23  }
24 
25  constexpr PtrSize(WasmPointer ptr, WasmSize size) : ptr{ptr}, size{size} {}
26 
31  constexpr WasmSpan combine() const {
32  return static_cast<WasmSpan>(ptr)
33  | (static_cast<WasmSpan>(size) << 32ull);
34  }
35 
36  bool operator==(const PtrSize &rhs) const {
37  return ptr == rhs.ptr and size == rhs.size;
38  }
39 
41  WasmSize size = 0u;
42  };
43 
44 } // namespace kagome::runtime
45 
46 #endif // KAGOME_CORE_RUNTIME_PTR_SIZE_HPP
static constexpr std::pair< WasmPointer, WasmSize > splitSpan(WasmSpan span)
Definition: types.hpp:52
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:35
WasmPointer ptr
address of buffer
Definition: ptr_size.hpp:40
constexpr PtrSize(WasmPointer ptr, WasmSize size)
Definition: ptr_size.hpp:25
bool operator==(const PtrSize &rhs) const
Definition: ptr_size.hpp:36
constexpr WasmSpan combine() const
makes combined pointer-size result from address
Definition: ptr_size.hpp:31
uint64_t WasmSpan
combination of pointer and size, where less significant part represents wasm pointer, and most significant represents size
Definition: types.hpp:31
uint32_t WasmPointer
type of wasm memory is 32 bit integer
Definition: types.hpp:26
WasmSize size
length of buffer
Definition: ptr_size.hpp:41