OSVR-Core
SerializationTraitExample_Complicated.h
Go to the documentation of this file.
1 
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 #ifndef INCLUDED_SerializationTraitExample_Complicated_h_GUID_FDF4E42A_9B56_4A86_7FDF_3C6425E6F9FB
27 #define INCLUDED_SerializationTraitExample_Complicated_h_GUID_FDF4E42A_9B56_4A86_7FDF_3C6425E6F9FB
28 
29 // Internal Includes
31 #include <osvr/Util/StdInt.h>
32 
33 // Library/third-party includes
34 // - none
35 
36 // Standard includes
37 // - none
38 
39 namespace osvr {
40 namespace common {
41 
47  double A;
48  uint32_t B;
49  int16_t C;
50  };
51  namespace serialization {
59  template <>
61  void>
62  : BaseSerializationTraits<YourComplicatedType> {
63 
66 
67  template <typename BufferType>
68  static void serialize(BufferType &buf,
69  typename Base::param_type val,
70  tag_type const &) {
71  serializeRaw(buf, val.A);
72  serializeRaw(buf, val.B);
73  serializeRaw(buf, val.C);
74  }
75 
76  template <typename BufferReaderType>
77  static void deserialize(BufferReaderType &buf,
78  typename Base::reference_type val,
79  tag_type const &) {
80  deserializeRaw(buf, val.A);
81  deserializeRaw(buf, val.B);
82  deserializeRaw(buf, val.C);
83  }
84 
85  static size_t spaceRequired(size_t existingBytes,
86  Base::param_type val,
87  tag_type const &) {
88  size_t bytes = existingBytes;
89  bytes += getBufferSpaceRequiredRaw(bytes, val.A);
90  bytes += getBufferSpaceRequiredRaw(bytes, val.B);
91  bytes += getBufferSpaceRequiredRaw(bytes, val.C);
92  return bytes - existingBytes;
93  }
94  };
95 
96  } // namespace serialization
97 
98 } // namespace common
99 } // namespace osvr
100 #endif // INCLUDED_SerializationTraitExample_Complicated_h_GUID_FDF4E42A_9B56_4A86_7FDF_3C6425E6F9FB
Base of serialization traits, containing useful typedefs.
Definition: SerializationTraits.h:134
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
void deserialize(BufferReaderType &reader, MessageClass &msg)
Deserializes a message from a buffer, using a MessageClass
Definition: Serialization.h:169
Header wrapping the C99 standard stdint header.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
void serialize(BufferType &buf, MessageClass &msg)
Serializes a message into a buffer, using a MessageClass
Definition: Serialization.h:152
void deserializeRaw(BufferReaderType &reader, T &v, Tag const &tag=Tag())
Deserialize a value from a buffer, with optional tag to specify non-default traits.
Definition: SerializationTraits.h:118
The default "type tag" for specifying serialization behavior.
Definition: SerializationTags.h:48
size_t getBufferSpaceRequiredRaw(size_t existingBufferSize, T const &v, Tag const &tag=Tag())
Get the size a value from a buffer, with optional tag to specify non-default traits.
Definition: SerializationTraits.h:126
Dummy example for your type.
Definition: SerializationTraitExample_Complicated.h:46
Traits class indicating how to serialize a type with a given tag.
Definition: SerializationTraits.h:86
void serializeRaw(BufferType &buf, T const &v, Tag const &tag=Tag())
Serialize a value to a buffer, with optional tag to specify non-default traits.
Definition: SerializationTraits.h:109