24 #ifndef FIELD_CODEC_PRESENCE_20190722H
25 #define FIELD_CODEC_PRESENCE_20190722H
27 #include "../field_codec_typed.h"
43 template <
typename WrappedType>
45 :
public TypedFieldCodec<typename WrappedType::wire_type, typename WrappedType::field_type>
61 WrappedType _inner_codec;
69 return _inner_codec.pre_encode(field_value);
75 return _inner_codec.post_decode(wire_value);
79 void validate()
override { _inner_codec.validate(); }
90 Bitset encoded = _inner_codec.encode(value);
94 encoded.push_front(
true);
105 bool present = bits->front();
115 return _inner_codec.decode(bits);
129 return presence_bits + _inner_codec.size(wire_value);
137 return _inner_codec.max_size();
142 return _inner_codec.max_size() + 1;
151 return _inner_codec.min_size();
162 _inner_codec.set_manager(manager);
163 FieldCodecBase::set_manager(manager);
Bitset encode(const wire_type &value) override
Encodes a non-empty field, adding a 1 bit to the front for optional fields.
A class for managing the various field codecs. Here you can add and remove field codecs....
void get_more_bits(size_type num_bits)
Retrieve more bits from the parent Bitset.
Dynamic Compact Control Language namespace.
typename Base::field_type field_type
The field_type of the "wrapped" codec.
WrappedType wrapped_type
The codec type of the "wrapped" codec.
void validate() override
Calls _inner_codec.validate()
void set_force_use_required(bool force_required=true)
Force the codec to always use the "required" field encoding, regardless of the FieldDescriptor settin...
unsigned max_size() override
Calculate maximum size of the field in bits.
wire_type decode(Bitset *bits) override
Decodes a field, first evaluating the presence bit if necessary.
Bitset encode() override
Encodes an empty field as a single 0 bit.
unsigned size(const wire_type &wire_value) override
Size of a non-empty field; gets size from "wrapped" codec, adds 1 for optional fields.
Exception used to signal null (non-existent) value within field codecs during decode.
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
typename Base::wire_type wire_type
The wire_type of the "wrapped" codec.
Base class for static-typed (no dccl::any) field encoders/decoders. Most single-valued user defined v...
Encodes empty optional fields with a single "presence" bit.
bool use_required()
Whether to use the required or optional encoding.
unsigned min_size() override
Calculate minimum size of the field in bits.
unsigned size() override
Size of an empty field (1 bit)