forked from qdrvm/kagome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptr_size.hpp
44 lines (34 loc) · 1.07 KB
/
ptr_size.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "runtime/types.hpp"
#include <tuple>
namespace kagome::runtime {
/**
* Result of a call to a Runtime API wasm function is an i64 where first 32
* bits are the address and next 32 bits are the size of the returned buffer.
*/
struct PtrSize {
constexpr PtrSize() : ptr{0}, size{0} {}
explicit PtrSize(WasmSpan v) {
std::tie(ptr, size) = splitSpan(v);
}
constexpr PtrSize(WasmPointer ptr, WasmSize size) : ptr{ptr}, size{size} {}
/**
* @brief makes combined pointer-size result from address
* @return pointer-size uint64_t value
*/
constexpr WasmSpan combine() const {
return static_cast<uint64_t>(ptr)
| (static_cast<uint64_t>(size) << 32ull);
}
bool operator==(const PtrSize &rhs) const {
return ptr == rhs.ptr and size == rhs.size;
}
WasmPointer ptr = 0u; ///< address of buffer
WasmSize size = 0u; ///< length of buffer
};
} // namespace kagome::runtime