Botcraft 1.21.4
Loading...
Searching...
No Matches
CustomType.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace ProtocolCraft
9{
10 namespace Internal
11 {
12 template <typename T, auto ReadFunc = nullptr, auto WriteFunc = nullptr, auto SerializeFunc = nullptr>
14 {
17
18 template <typename C>
20 const C* c,
21 std::vector<unsigned char>::const_iterator& iter,
22 size_t& length
23#ifdef PROTOCOLCRAFT_DETAILED_PARSING
24 ,
25 typename OffsetType<storage_type>::type* start_offset = nullptr,
26 typename OffsetType<storage_type>::type* end_offset = nullptr
27#endif
28 )
29 {
30 if constexpr (ReadFunc == nullptr)
31 {
32 return ReadData<storage_type, serialization_type>(iter, length
33#ifdef PROTOCOLCRAFT_DETAILED_PARSING
34 ,
35 start_offset,
36 end_offset
37#endif
38 );
39 }
40 else
41 {
42 return (c->*ReadFunc)(iter, length);
43 }
44 }
45
46 template <typename C>
47 static void Write(const C* c, const storage_type& val, std::vector<unsigned char>& container)
48 {
49 if constexpr (WriteFunc == nullptr)
50 {
51 WriteData<storage_type, serialization_type>(val, container);
52 }
53 else
54 {
55 (c->*WriteFunc)(val, container);
56 }
57 }
58
59 template <typename C>
60 static std::optional<Json::Value> Serialize(
61 const C* c,
62 const storage_type& val
63#ifdef PROTOCOLCRAFT_DETAILED_PARSING
64 ,
65 const typename OffsetType<storage_type>::type* start_offset = nullptr,
66 const typename OffsetType<storage_type>::type* end_offset = nullptr
67#endif
68 )
69 {
70 if constexpr (SerializeFunc == nullptr)
71 {
72 return SerializeType<storage_type>(val
73#ifdef PROTOCOLCRAFT_DETAILED_PARSING
74 ,
75 start_offset,
76 end_offset
77#endif
78 );
79 }
80 else
81 {
82 return (c->*SerializeFunc)(val);
83 }
84 }
85 };
86 }
87}
typename SerializedType< T >::storage_type storage_type
static void Write(const C *c, const storage_type &val, std::vector< unsigned char > &container)
static std::optional< Json::Value > Serialize(const C *c, const storage_type &val)
static storage_type Read(const C *c, std::vector< unsigned char >::const_iterator &iter, size_t &length)
typename SerializedType< T >::serialization_type serialization_type