LeviLamina
Loading...
Searching...
No Matches
EventRefObjSerializer.h
1#pragma once
2
3#include "ll/api/reflection/TypeName.h"
4#include "mc/nbt/CompoundTag.h"
5
6namespace ll::event {
7template <class T>
8[[nodiscard]] inline ::CompoundTag serializeRefObj(T& obj) {
9 return ::CompoundTag{
10 {"_nullable_", false},
11 { "_pointer_", (uintptr_t)std::addressof(obj)},
12 { "_type_", reflection::type_unprefix_name_v<std::remove_cvref_t<T>>},
13 { "_isconst_", std::is_const_v<T>},
14 };
15}
16template <class T>
17[[nodiscard]] inline ::CompoundTag serializePtrObj(T* ptr) {
18 return ::CompoundTag{
19 {"_nullable_", true},
20 { "_pointer_", (uintptr_t)ptr},
21 { "_type_", reflection::type_unprefix_name_v<std::remove_cvref_t<T>>},
22 { "_isconst_", std::is_const_v<T>},
23 };
24}
25[[nodiscard]] inline bool isEventSerializedObj(::CompoundTag const& tag) {
26 return tag.contains("_type_") && tag.contains("_pointer_");
27}
28[[nodiscard]] inline bool isEventSerializedObj(::CompoundTagVariant const& tag) {
29 return tag.is_object() ? isEventSerializedObj(tag.get<::CompoundTag>()) : false;
30}
31} // namespace ll::event
Definition CompoundTagVariant.h:38
Definition CompoundTag.h:13