DCCL v4
Loading...
Searching...
No Matches
field_codec_id.h
1// Copyright 2009-2023:
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
26namespace 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
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
Definition bitset.h:43
Provides the default 1 byte or 2 byte DCCL ID codec.
Bitset encode() override
Encode an empty field.
unsigned size() override
Calculate the size (in bits) of an empty field.
void validate() override
Validate a field. Use require() inside your overloaded validate() to assert requirements or throw Exc...
uint32 decode(Bitset *bits) override
Decode a field. If the field is empty (i.e. was encoded using the zero-argument encode()),...
unsigned min_size() override
Calculate minimum size of the field in bits.
unsigned max_size() override
Calculate maximum size of the field in bits.
Base class for static-typed (no dccl::any) field encoders/decoders. Most single-valued user defined v...
Dynamic Compact Control Language namespace.
Definition any.h:47
google::protobuf::uint32 uint32
an unsigned 32 bit integer
Definition common.h:56