wut  v1.7.0
Wii U Toolchain
ISerializerDetails.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <nn/result.h>
4 #include <wut.h>
5 
6 #ifdef __cplusplus
7 
8 namespace nn::sl {
9  template<typename T>
11 
12  class TitleIconCache;
13  class DataCreator;
14  class CacheManager;
15  class Condition;
17  class TitleListCache;
18 
19  namespace details {
20  struct ISerializerInternal;
21 
22  typedef nn::Result (*ISerializer_SerializeFn)(ISerializerInternal *, void *, uint32_t);
23  typedef nn::Result (*ISerializer_DeserializeFn)(ISerializerInternal *, void *, uint32_t);
25 
26  struct WUT_PACKED ISerializerInternalVTable {
27  ISerializerBase<uint8_t> *instance; // Is normally padding
28  uint32_t info;
29  WUT_PADDING_BYTES(4);
30  uint32_t destructor;
31  WUT_PADDING_BYTES(4);
33  WUT_PADDING_BYTES(4);
35  WUT_PADDING_BYTES(4);
37  };
38  WUT_CHECK_SIZE(ISerializerInternalVTable, 0x28);
39  WUT_CHECK_OFFSET(ISerializerInternalVTable, 0x00, instance);
40  WUT_CHECK_OFFSET(ISerializerInternalVTable, 0x14, SerializeFn);
41  WUT_CHECK_OFFSET(ISerializerInternalVTable, 0x1C, DeserializeFn);
42  WUT_CHECK_OFFSET(ISerializerInternalVTable, 0x24, GetCountFn);
43 
44  typedef struct WUT_PACKED ISerializerInternal {
47  WUT_CHECK_SIZE(ISerializerInternal, 0x04);
48  WUT_CHECK_OFFSET(ISerializerInternal, 0x00, vtable);
49 
50  template<typename T>
52  friend class nn::sl::TitleIconCache;
53  friend class nn::sl::DataCreator;
54  friend class nn::sl::CacheManager;
55  friend class nn::sl::Condition;
57  friend class nn::sl::TitleListCache;
58 
59  public:
60  ISerializerBase() = default;
61 
62  virtual ~ISerializerBase() = default;
63 
64  virtual nn::Result Serialize(void *buffer, uint32_t size) const = 0;
65 
66  virtual nn::Result Deserialize(void *buffer, uint32_t size) const = 0;
67 
68  virtual nn::Result GetCount(uint32_t *outCount) const = 0;
69 
70  private:
71  virtual details::ISerializerInternal *GetInternal() = 0;
72  };
73 
74 
75  template<typename T>
76  class SerializerFromPtr : public ISerializerBase<T> {
77  public:
78  explicit SerializerFromPtr(details::ISerializerInternal *ptr) : mInstancePtr(ptr) {
79  }
80 
81  nn::Result Serialize(void *buffer, uint32_t size) const override {
82  if (!mInstancePtr) {
84  }
85  return mInstancePtr->vtable->SerializeFn(mInstancePtr, buffer, size);
86  }
87 
88  nn::Result Deserialize(void *buffer, uint32_t size) const override {
89  if (!mInstancePtr) {
91  }
92  return mInstancePtr->vtable->DeserializeFn(mInstancePtr, buffer, size);
93  }
94 
95  nn::Result GetCount(uint32_t *outCount) const override {
96  if (!mInstancePtr) {
98  }
99  return mInstancePtr->vtable->GetCountFn(mInstancePtr, outCount);
100  }
101 
102  private:
103  details::ISerializerInternal *GetInternal() override {
104  return mInstancePtr;
105  }
106 
107  details::ISerializerInternal *mInstancePtr;
108  };
109  } // namespace details
110 
111 } // namespace nn::sl
112 
113 #endif
Result value type used by nn libraries.
Definition: result.h:68
@ LEVEL_FATAL
Definition: result.h:73
@ RESULT_MODULE_NN_SL
Definition: result.h:114
virtual nn::Result Serialize(void *buffer, uint32_t size) const =0
virtual nn::Result GetCount(uint32_t *outCount) const =0
virtual ~ISerializerBase()=default
virtual nn::Result Deserialize(void *buffer, uint32_t size) const =0
nn::Result Deserialize(void *buffer, uint32_t size) const override
nn::Result GetCount(uint32_t *outCount) const override
nn::Result Serialize(void *buffer, uint32_t size) const override
SerializerFromPtr(details::ISerializerInternal *ptr)
nn::Result(* ISerializer_SerializeFn)(ISerializerInternal *, void *, uint32_t)
nn::Result(* ISerializer_DeserializeFn)(ISerializerInternal *, void *, uint32_t)
nn::Result(* ISerializer_GetCountFn)(ISerializerInternal *, uint32_t *)
struct nn::sl::details::ISerializerInternal ISerializerInternal
ISerializerInternalVTable * vtable