DCCL v4
Loading...
Searching...
No Matches
field_codec_default.h
1// Copyright 2014-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// Kyle Guilbert <kguilbert@aphysci.com>
8// Chris Murphy <cmurphy@aphysci.com>
9//
10//
11// This file is part of the Dynamic Compact Control Language Library
12// ("DCCL").
13//
14// DCCL is free software: you can redistribute it and/or modify
15// it under the terms of the GNU Lesser General Public License as published by
16// the Free Software Foundation, either version 2.1 of the License, or
17// (at your option) any later version.
18//
19// DCCL is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU Lesser General Public License for more details.
23//
24// You should have received a copy of the GNU Lesser General Public License
25// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
26// implements FieldCodecBase for all the basic DCCL types for version 3
27
28#ifndef DCCLV3FIELDCODECDEFAULT20140403H
29#define DCCLV3FIELDCODECDEFAULT20140403H
30
31#include "../codecs2/field_codec_default.h"
32
33namespace dccl
34{
36namespace v3
37{
38// all these are the same as version 2
39template <typename WireType, typename FieldType = WireType>
41
42template <typename TimeType> using TimeCodec = v2::TimeCodec<TimeType>;
43template <typename T> using StaticCodec = v2::StaticCodec<T>;
44
47// Enum Codec is identical to v2, except when packed_enum is set to false.
48
56 : public DefaultNumericFieldCodec<int32, const google::protobuf::EnumValueDescriptor*>
57{
58 public:
59 int32 pre_encode(const google::protobuf::EnumValueDescriptor* const& field_value) override;
60 const google::protobuf::EnumValueDescriptor* post_decode(const int32& wire_value) override;
61 void validate() override {}
62 std::size_t hash() override
63 {
64 return std::hash<std::string>{}(this_field()->enum_type()->DebugString());
65 }
66
67 private:
68 double max() override;
69 double min() override;
70};
71
75class DefaultStringCodec : public TypedFieldCodec<std::string>
76{
77 public:
78 void validate() override;
79 Bitset encode() override;
80 Bitset encode(const std::string& wire_value) override;
81 std::string decode(Bitset* bits) override;
82 unsigned size() override;
83 unsigned size(const std::string& wire_value) override;
84 unsigned max_size() override;
85 unsigned min_size() override;
86};
87
88} // namespace v3
89} // namespace dccl
90
91#endif
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
Definition bitset.h:43
const google::protobuf::FieldDescriptor * this_field() const
Returns the FieldDescriptor (field schema meta-data) for this field.
Base class for static-typed (no dccl::any) field encoders/decoders. Most single-valued user defined v...
Provides a bool encoder. Uses 1 bit if field is required, 2 bits if optional
Provides an fixed length byte string encoder.
Provides a basic bounded arbitrary length numeric (double, float, uint32, uint64, int32,...
Placeholder codec that takes no space on the wire (0 bits).
Provides an enum encoder. This converts the enumeration to an integer and uses DefaultNumericFieldCod...
std::size_t hash() override
Generate a field specific hash to be combined with the descriptor hash.
void validate() override
Validate a field. Use require() inside your overloaded validate() to assert requirements or throw Exc...
Provides an variable length ASCII string encoder.
unsigned max_size() override
Calculate maximum size of the field in bits.
unsigned min_size() override
Calculate minimum size of the field in bits.
std::string decode(Bitset *bits) override
Decode a field. If the field is empty (i.e. was encoded using the zero-argument encode()),...
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...
Dynamic Compact Control Language namespace.
Definition any.h:47
google::protobuf::int32 int32
a signed 32 bit integer
Definition common.h:58