TLVParserBase.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Packets_80221Bundle_TLVParserBase_
18 #define HH_SENF_Packets_80221Bundle_TLVParserBase_ 1
19 
20 // Custom includes
21 #include <senf/Packets/Packets.hh>
22 
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 namespace senf {
26 
28  : public detail::packet::IntParserOps<MIHLengthParser, boost::uint32_t>,
29  public PacketParserBase
30  {
31  public:
33 
34  typedef boost::uint32_t value_type;
35  static const size_type init_bytes = 1;
36  static value_type const min_value = 0;
37  static value_type const max_value = 4294967295u;
38 
39  value_type value() const;
40  void value(value_type v);
41 
42  MIHLengthParser const & operator= (value_type other);
43  size_type bytes() const;
44  void init() const;
45 
47  return parse<UInt8Parser>( i());
48  }
50  return parse<FlagParser<0> >( i());
51  }
53  return parse<FlagParser<1> >( i());
54  }
56  return parse<UIntFieldParser<2,8> >( i());
57  }
58 
59  void finalize();
60  void capacity(value_type v);
61  value_type capacity() const;
62 
63  private:
64  void resize_(size_type size);
65  };
66 
67 
95  {
96  public:
97 # include SENF_PARSER()
101 
107  void finalize();
108 
110 
111  protected:
117  void maxLength(MIHLengthParser::value_type maxl) const;
118 
119  void validateType(boost::uint8_t type) const;
120  void validateTypeLength(boost::uint8_t type, MIHLengthParser::value_type length) const;
121  };
122 
123 
127  : public MIHBaseTLVParser
128  {
129  # include SENF_PARSER()
133 
134  void maxListSize(MIHLengthParser::value_type maxl = MIHLengthParser::max_value) const;
135  };
136 
137  template <class Self>
139  {
140  void finalize();
141  };
142 
143 }
144 
145 
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 #include "TLVParserBase.cci"
148 #include "TLVParserBase.ct"
149 //#include "TLVParserBase.cti"
150 #endif
151 
152 
153 // Local Variables:
154 // mode: c++
155 // fill-column: 100
156 // c-file-style: "senf"
157 // indent-tabs-mode: nil
158 // ispell-local-dictionary: "american"
159 // compile-command: "scons -u test"
160 // comment-column: 40
161 // End:
#define SENF_PARSER_INHERIT(base)
Define parser inheritance.
Parse unsigned bitfield with up to 32bit&#39;s.
Definition: IntParser.hh:515
size_type bytes() const
value_type value() const
Parse 8bit unsigned byte aligned integer.
Definition: IntParser.hh:91
TLV parser registration facility.
Definition: GenericTLV.hh:227
Packets public header.
Return number of bytes to allocate to new object of given type.
FlagParser< 0 > extended_length_flag() const
UInt8Parser length_field() const
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
boost::uint32_t value_type
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
GenericTLVParserRegistry< MIHBaseTLVParser > Registry
static value_type const min_value
Packet data STL-sequence view.
Definition: PacketData.hh:61
#define SENF_PARSER_FIELD_RO(name, type)
Define parser field (read-only)
data_iterator i() const
Return beginning of data to parse.
static value_type const max_value
MIHLengthParser const & operator=(value_type other)
detail::packet::size_type size_type
Unsigned integral type.
UIntFieldParser< 2, 8 > fixed_length_field() const
Parser Base class.
Parse single-bit flag.
Definition: IntParser.hh:560
MIHLengthParser(data_iterator i, state_type s)
Base class for list TLV parser.
FlagParser< 1 > underflow_flag() const
value_type capacity() const
Base class for MIH TLV parsers.
detail::packet::iterator data_iterator
Raw data iterator type.