DCCL v4
field_codec_default.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 // implements FieldCodecBase for all the basic DCCL types for version 3
23 
24 #ifndef DCCLV3FIELDCODECDEFAULT20140403H
25 #define DCCLV3FIELDCODECDEFAULT20140403H
26 
27 #include "dccl/codecs2/field_codec_default.h"
28 
29 namespace dccl
30 {
32  namespace v3
33  {
34  // all these are the same as version 2
35  template<typename WireType, typename FieldType = WireType>
36  class DefaultNumericFieldCodec : public v2::DefaultNumericFieldCodec<WireType, FieldType> { };
37 
40  // Enum Codec is identical to v2, except when packed_enum is set to false.
41 
49  : public DefaultNumericFieldCodec<int32, const google::protobuf::EnumValueDescriptor*>
50  {
51  public:
52  int32 pre_encode(const google::protobuf::EnumValueDescriptor* const& field_value);
53  const google::protobuf::EnumValueDescriptor* post_decode(const int32& wire_value);
54  void validate() { }
55 
56  private:
57 
58  double max();
59  double min();
60  };
61 
62  template<typename TimeType>
63  class TimeCodec : public v2::TimeCodecBase<TimeType, 0>
64  { BOOST_STATIC_ASSERT(sizeof(TimeCodec) == 0); };
65 
66  template<> class TimeCodec<uint64> : public v2::TimeCodecBase<uint64, 1000000> { };
67  template<> class TimeCodec<int64> : public v2::TimeCodecBase<int64, 1000000> { };
68  template<> class TimeCodec<double> : public v2::TimeCodecBase<double, 1> { };
69 
70  template<typename T>
71  class StaticCodec : public v2::StaticCodec<T>
72  { };
73 
74 
78  class DefaultStringCodec : public TypedFieldCodec<std::string>
79  {
80  private:
81  Bitset encode();
82  Bitset encode(const std::string& wire_value);
83  std::string decode(Bitset* bits);
84  unsigned size();
85  unsigned size(const std::string& wire_value);
86  unsigned max_size();
87  unsigned min_size();
88  void validate();
89  };
90 
91  }
92 }
93 
94 #endif
dccl::int32
google::protobuf::int32 int32
a signed 32 bit integer
Definition: common.h:57
dccl::v2::StaticCodec
Placeholder codec that takes no space on the wire (0 bits).
Definition: field_codec_default.h:380
dccl::v3::DefaultEnumCodec::post_decode
const google::protobuf::EnumValueDescriptor * post_decode(const int32 &wire_value)
Convert from the WireType representation (used with encode() and decode(), i.e. "on the wire") to the...
Definition: field_codec_default.cpp:170
dccl
Dynamic Compact Control Language namespace.
Definition: gen_units_class_plugin.h:49
dccl::uint64
google::protobuf::uint64 uint64
an unsigned 64 bit integer
Definition: common.h:59
dccl::v2::TimeCodecBase
Encodes time of day (default: second precision, but can be set with (dccl.field).precision extension)
Definition: field_codec_default.h:314
dccl::v3::DefaultStringCodec
Provides an variable length ASCII string encoder.
Definition: field_codec_default.h:78
dccl::v3::DefaultNumericFieldCodec
Definition: field_codec_default.h:36
dccl::Bitset
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
Definition: bitset.h:38
dccl::v2::DefaultBoolCodec
Provides a bool encoder. Uses 1 bit if field is required, 2 bits if optional
Definition: field_codec_default.h:244
dccl::int64
google::protobuf::int64 int64
a signed 64 bit integer
Definition: common.h:61
dccl::v3::DefaultEnumCodec::validate
void validate()
Validate a field. Use require() inside your overloaded validate() to assert requirements or throw Exc...
Definition: field_codec_default.h:54
dccl::v3::DefaultEnumCodec::pre_encode
int32 pre_encode(const google::protobuf::EnumValueDescriptor *const &field_value)
Convert from the FieldType representation (used in the Google Protobuf message) to the WireType repre...
Definition: field_codec_default.cpp:162
dccl::v3::TimeCodec
Definition: field_codec_default.h:63
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::v3::DefaultEnumCodec
Provides an enum encoder. This converts the enumeration to an integer and uses DefaultNumericFieldCod...
Definition: field_codec_default.h:48
dccl::v2::DefaultBytesCodec
Provides an fixed length byte string encoder.
Definition: field_codec_default.h:275
dccl::v2::DefaultNumericFieldCodec
Provides a basic bounded arbitrary length numeric (double, float, uint32, uint64, int32,...
Definition: field_codec_default.h:54
dccl::v3::StaticCodec
Definition: field_codec_default.h:71