Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
unpack_nested.h
Go to the documentation of this file.
1 /// @file detail/unpack_nested.h
2 ///
3 /// Unpacks the bytes from a raw memory buffer into a nested message field.
4 ///
5 /// The MIT License(MIT)
6 /// @copyright 2014 Paul M Watt
7 // ****************************************************************************
8 #ifndef UNPACK_NESTED_H_INCLUDED
9 #define UNPACK_NESTED_H_INCLUDED
10 // Private Usage Include Guard ************************************************
11 // Only allow this header file to be included through unpack_message.h
12 #ifndef UNPACK_MESSAGE_H_INCLUDED
13 # error Do not include this file directly. Use <detail/unpack_message.h> instead
14 #endif
15 
16 namespace Hg
17 {
18 
19 namespace detail
20 {
21 
22 // ****************************************************************************
23 // A specialized functor to read nested types.
24 //
25 // @tparam IdxT [size_t] The index of the field to read.
26 // @tparam MsgT [typename] The message defintition used to parse the
27 // buffer.
28 // @tparam BufferT [typename] The buffer type that provides the data
29 // to read into the message.
30 //
31 template< size_t IdxT,
32  typename MsgT,
33  typename BufferT
34  >
35 struct UnpackDatum<IdxT, MsgT, BufferT, nested_trait>
36 {
37  // **************************************************************************
38  // Reads a nested field to the specified buffer.
39  //
40  // @param msg The message object to receive the data to be read.
41  // @param buffer The buffer object to read from.
42  // @param dynamic_offset An additional offset for messages with dynamically
43  // sized fields. If this nested value contains additional
44  // dynamically-sized fields, this length will be added
45  // to this input value to report how much larger the
46  // message has become.
47  //
48  void operator()( MsgT &msg,
49  const BufferT &buffer,
50  size_t &dynamic_offset)
51  {
52  typedef typename
54  typename MsgT::format_type
55  >::type proxy_type;
56  typedef typename
57  proxy_type::value_type value_type;
58 
60  + dynamic_offset;
61  value_type& value = msg.template FieldAt<IdxT>().get();
62  unpack_message< value_type,
63  BufferT,
64  typename message_size_trait<typename value_type::format_type>::type
65  >(value, buffer, offset);
66  }
67 };
68 
69 } // namespace detail
70 
71 } // namespace Hg
72 
73 #endif