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