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_packed_bits.h
Go to the documentation of this file.
1 /// @file detail/pack_packed_bits.h
2 ///
3 /// Packs a packed-bits message field into Hg Message buffer.
4 ///
5 /// The MIT License(MIT)
6 /// @copyright 2014 Paul M Watt
7 // ****************************************************************************
8 #ifndef PACK_PACKED_BITS_H_INCLUDED
9 #define PACK_PACKED_BITS_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 packed-bits.
24 //
25 // @tparam T [typename] The value_type for this specialization.
26 //
27 template< size_t IdxT,
28  typename MsgT,
29  typename BufferT
30  >
31 struct PackDatum<IdxT, MsgT, BufferT, packed_trait>
32 {
33  // **************************************************************************
34  // Writes a packed-bits field to the specified buffer.
35  //
36  // @param msg The message object to supply the data to be written.
37  // @param buffer The buffer object to write into.
38  // @param dynamic_offset An additional offset for messages with dynamically
39  // sized fields.
40  //
41  void operator()(MsgT &msg,
42  BufferT &buffer,
43  size_t &dynamic_offset)
44  {
45  typedef typename
47  < IdxT,
48  typename MsgT::format_type
49  >::type proxy_type;
50 
51  typedef typename
52  proxy_type::value_type packed_type;
53 
54  typedef typename
55  packed_type::value_type value_type;
56 
57  packed_type &packed_value = msg.template FieldAt<IdxT>().get();
59  + dynamic_offset;
60  buffer.set_data(static_cast<value_type>(packed_value), offset);
61  }
62 };
63 
64 } // namespace detail
65 
66 } // namespace Hg
67 
68 #endif