barretenberg
Loading...
Searching...
No Matches
src
barretenberg
serialize
raw_pointer.hpp
1
#pragma once
2
#include "msgpack_impl/schema_name.hpp"
3
#include <cstdint>
4
5
// Holds a raw pointer to an object of type T.
6
// It provides methods for packing and unpacking the pointer using MessagePack,
7
// a binary serialization format.
8
template
<
typename
T>
struct
RawPointer
{
9
// Raw pointer to an object of type T
10
T* ptr =
nullptr
;
11
12
// Pack the raw pointer into a MessagePack packer.
13
// The pointer is first cast to an integer type (uintptr_t) which can hold a pointer,
14
// and then packed into the packer.
15
void
msgpack_pack(
auto
& packer)
const
{ packer.pack(
reinterpret_cast<
uintptr_t
>
(ptr)); }
16
17
// Unpack the raw pointer from a MessagePack object.
18
// The object is first cast to an integer type (uintptr_t), and then to a pointer of type T.
19
void
msgpack_unpack(
auto
object
) { ptr =
reinterpret_cast<
T*
>
((uintptr_t)
object
); }
20
21
// help our msgpack schema compiler with this struct
22
void
msgpack_schema(
auto
& packer)
const
23
{
24
// Manually make an ['alias', [type, 'int']] structure (without calling pack_alias as it is too restricting)
25
packer.pack_array(2);
// 2 elements in our outer tuple
26
packer.pack(
"alias"
);
27
packer.pack_array(2);
// 2 elements in our inner tuple
28
packer.template pack_template_type<T>(
"RawPointer"
);
29
packer.pack(
"int"
);
30
}
31
32
// Overload the arrow operator to return the raw pointer.
33
// This allows users to directly access the object pointed to by the raw pointer.
34
T* operator->() {
return
ptr; }
35
};
RawPointer
Definition:
raw_pointer.hpp:8
Generated by
1.9.6