CTR Pia  4.11.3
Game Communication Engine
clone_StraightSerializePolicy.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_StraightSerializePolicy.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/clone/clone_definitions.h>
18 #include <memory>
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29 @brief Serializes the source data structure without changes.
30 
31 @tparam Type_ Specifies the type of the data to be serialized.
32 
33 @date 2013-07-18 Initial version.
34 */
35 template <typename Type_>
37 {
38 public:
39 /*!
40 @brief Defines the type of the data to be serialized.
41 */
42  typedef Type_ Type;
43 
44 
45 /*!
46 @cond PRIVATE
47 @brief Serializes data.
48 @param[out] pBuffer Specifies the output buffer.
49 @param[in] value Specifies the data to serialize.
50 */
51  static void Serialize(void* pBuffer, const Type& value)
52  {
53 #if NN_PIA_CAFE
54  if (reinterpret_cast<u32>(pBuffer) % __alignof(Type) != 0)
55  {
56  OSBlockMove(pBuffer, &value, sizeof(Type), FALSE);
57  }
58  else
59  {
60  *reinterpret_cast<Type*>(pBuffer) = value;
61  }
62 #elif NN_PIA_CTR
63  nn::nstd::MemCpy(pBuffer, &value, sizeof(Type));
64 #else
65  *reinterpret_cast<Type*>(pBuffer) = value;
66 #endif
67  }
68  //! @endcond
69 
70 
71 /*!
72 @cond PRIVATE
73 @brief Deserializes data.
74 @param[out] pValue Specifies the place to save the deserialized data.
75 @param[in] cpData Specifies the byte array to deserialize.
76 */
77  static void Deserialize(Type* pValue, const void* cpData)
78  {
79 #if NN_PIA_CAFE
80  if (reinterpret_cast<u32>(cpData) % __alignof(Type) != 0)
81  {
82  OSBlockMove(pValue, cpData, sizeof(Type), FALSE);
83  }
84  else
85  {
86  *pValue = *reinterpret_cast<const Type*>(cpData);
87  }
88 #elif NN_PIA_CTR
89  nn::nstd::MemCpy(pValue, cpData, sizeof(Type));
90 #else
91  *pValue = *reinterpret_cast<const Type*>(cpData);
92 #endif
93  }
94  //! @endcond
95 
96 
97 /*!
98 @cond PRIVATE
99 @brief Gets the size of the serialized data.
100 @details Cannot use a value larger than <tt>@ref nn::pia::clone::CloneProtocol::GetElementSizeMax() "CloneProtocol::GetElementSizeMax"</tt>.
101 @return Returns the size of the serialized data.
102 */
103  static size_t GetSize()
104  {
105  return sizeof(Type);
106  }
107  //! @endcond
108 
109 
110 /*!
111 @cond PRIVATE
112 @brief Returns the size of the serialized data.
113 @details This value, and not the value of <tt>@ref GetSize</tt>, is used when using <tt>@ref nn::pia::clone::ReliableLargeCloneElement</tt>.
114 */
115  static const size_t SIZE = sizeof(Type);
116  //! @endcond
117 
118 };
119 }
120 }
121 } // end of namespace nn::pia::clone
Definition: assert.h:115
Serializes the source data structure without changes.
Definition: clone_StraightSerializePolicy.h:36
Type_ Type
Defines the type of the data to be serialized.
Definition: clone_StraightSerializePolicy.h:42