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