DCCL v3
field_codec_id.h
1 // Copyright 2009-2017 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (for 2013-)
3 // Massachusetts Institute of Technology (for 2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Dynamic Compact Control Language Library
8 // ("DCCL").
9 //
10 // DCCL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // DCCL is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
22 #include "field_codec_fixed.h"
23 
24 namespace dccl
25 {
27  class DefaultIdentifierCodec : public TypedFieldCodec<uint32>
28  {
29  protected:
30  virtual Bitset encode();
31  virtual Bitset encode(const uint32& wire_value);
32  virtual uint32 decode(Bitset* bits);
33  virtual unsigned size();
34  virtual unsigned size(const uint32& wire_value);
35  virtual unsigned max_size();
36  virtual unsigned min_size();
37  virtual void validate() { }
38 
39  private:
40  unsigned this_size(const uint32& wire_value);
41  // maximum id we can fit in short or long header (MSB reserved to indicate
42  // short or long header)
43  enum { ONE_BYTE_MAX_ID = (1 << 7) - 1,
44  TWO_BYTE_MAX_ID = (1 << 15) - 1};
45 
46  enum { SHORT_FORM_ID_BYTES = 1,
47  LONG_FORM_ID_BYTES = 2 };
48  };
49 }
dccl
Dynamic Compact Control Language namespace.
Definition: gen_units_class_plugin.h:49
dccl::uint32
google::protobuf::uint32 uint32
an unsigned 32 bit integer
Definition: common.h:55
dccl::DefaultIdentifierCodec::size
virtual unsigned size()
Calculate the size (in bits) of an empty field.
Definition: field_codec_id.cpp:70
dccl::Bitset
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
Definition: bitset.h:38
dccl::DefaultIdentifierCodec::max_size
virtual unsigned max_size()
Calculate maximum size of the field in bits.
Definition: field_codec_id.cpp:91
dccl::DefaultIdentifierCodec
Provides the default 1 byte or 2 byte DCCL ID codec.
Definition: field_codec_id.h:27
dccl::DefaultIdentifierCodec::encode
virtual Bitset encode()
Encode an empty field.
Definition: field_codec_id.cpp:28
dccl::TypedFieldCodec
Base class for static-typed (no boost::any) field encoders/decoders. Most single-valued user defined ...
Definition: field_codec_typed.h:82
dccl::DefaultIdentifierCodec::decode
virtual uint32 decode(Bitset *bits)
Decode a field. If the field is empty (i.e. was encoded using the zero-argument encode()),...
Definition: field_codec_id.cpp:51
dccl::DefaultIdentifierCodec::min_size
virtual unsigned min_size()
Calculate minimum size of the field in bits.
Definition: field_codec_id.cpp:96
dccl::DefaultIdentifierCodec::validate
virtual void validate()
Validate a field. Use require() inside your overloaded validate() to assert requirements or throw Exc...
Definition: field_codec_id.h:37