wut  v1.7.0
Wii U Toolchain
ISerializer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <coreinit/time.h>
4 #include <nn/result.h>
7 #include <nn/sl/sl_cpp.h>
8 #include <wut.h>
9 
10 #ifdef __cplusplus
11 
12 namespace nn::sl {
13  template<typename T>
15 
16  public:
18  InitInternalVtable();
19  }
20 
22  InitInternalVtable();
23  }
24 
26  InitInternalVtable();
27  return *this;
28  }
29 
30  ISerializer &operator=(ISerializer &&src) noexcept {
31  InitInternalVtable();
32  return *this;
33  }
34 
35  nn::Result Serialize(T *buffer, uint32_t num) {
36  return details::ISerializerBase<T>::Serialize(buffer, num * sizeof(buffer));
37  }
38 
39  nn::Result Deserialize(T *buffer, uint32_t num) {
40  return details::ISerializerBase<T>::Deserialize(buffer, num * sizeof(buffer));
41  }
42 
43  ~ISerializer() override = default;
44 
45  private:
46  static nn::Result SerializeWrapper(details::ISerializerInternal *instance, void *buffer, uint32_t size) {
47  return details::ISerializerBase<T>::instance->vtable->instance->Serialize(buffer, size);
48  }
49 
50  static nn::Result DeserializeWrapper(details::ISerializerInternal *instance, void *buffer, uint32_t size) {
51  return details::ISerializerBase<T>::instance->vtable->instance->Deserialize(buffer, size);
52  }
53 
54  static nn::Result GetCountWrapper(details::ISerializerInternal *instance, uint32_t *outCount) {
55  return details::ISerializerBase<T>::instance->vtable->instance->GetCount(outCount);
56  }
57 
58  details::ISerializerInternal *GetInternal() override {
59  return &mInstance;
60  }
61 
62  void InitInternalVtable() {
63  mVTable = {.instance = this,
64  .SerializeFn = &SerializeWrapper,
65  .DeserializeFn = &DeserializeWrapper,
66  .GetCountFn = &GetCountWrapper};
67  mInstance.vtable = &mVTable;
68  }
69 
70  details::ISerializerInternal mInstance{};
71  details::ISerializerInternalVTable mVTable{};
72  };
73 
75 
77 
79 
81 
83 } // namespace nn::sl
84 
85 #endif
Result value type used by nn libraries.
Definition: result.h:68
ISerializer(ISerializer &src)
Definition: ISerializer.h:21
nn::Result Deserialize(T *buffer, uint32_t num)
Definition: ISerializer.h:39
ISerializer & operator=(const ISerializer &other)
Definition: ISerializer.h:25
ISerializer & operator=(ISerializer &&src) noexcept
Definition: ISerializer.h:30
nn::Result Serialize(T *buffer, uint32_t num)
Definition: ISerializer.h:35
~ISerializer() override=default
virtual nn::Result Serialize(void *buffer, uint32_t size) const =0
virtual nn::Result Deserialize(void *buffer, uint32_t size) const =0
struct nn::sl::details::ISerializerInternal ISerializerInternal
ISerializerInternalVTable * vtable
details::ISerializerBase< nn::sl::KillerNotification > & GetDefaultKillerNotificationSerializer()
details::ISerializerBase< OSTime > & GetDefaultPreviousSendingTimeSerializer()
details::ISerializerBase< nn::sl::TitleInfo > & GetDefaultJumpTitleInfoSerializer()
details::ISerializerBase< nn::sl::TitleInfo > & GetDefaultQuickStartTitleInfoSerializer()
details::ISerializerBase< nn::sl::IconInfo > & GetDefaultIconInfoSerializer()