24#ifndef FIELD_CODEC_PRESENCE_20190722H
25#define FIELD_CODEC_PRESENCE_20190722H
27#include "../field_codec_typed.h"
43template <
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);
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
void get_more_bits(size_type num_bits)
Retrieve more bits from the parent Bitset.
void set_force_use_required(bool force_required=true)
Force the codec to always use the "required" field encoding, regardless of the FieldDescriptor settin...
bool use_required()
Whether to use the required or optional encoding.
A class for managing the various field codecs. Here you can add and remove field codecs....
Exception used to signal null (non-existent) value within field codecs during decode.
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.
void validate() override
Calls _inner_codec.validate()
unsigned size(const wire_type &wire_value) override
Size of a non-empty field; gets size from "wrapped" codec, adds 1 for optional fields.
unsigned size() override
Size of an empty field (1 bit)
wire_type pre_encode(const field_type &field_value) override
Convert from the FieldType representation (used in the Google Protobuf message) to the WireType repre...
unsigned min_size() override
Calculate minimum size of the field in bits.
Bitset encode() override
Encodes an empty field as a single 0 bit.
WrappedType wrapped_type
The codec type of the "wrapped" codec.
typename Base::wire_type wire_type
The wire_type of the "wrapped" codec.
unsigned max_size() override
Calculate maximum size of the field in bits.
typename Base::field_type field_type
The field_type of the "wrapped" codec.
wire_type decode(Bitset *bits) override
Decodes a field, first evaluating the presence bit if necessary.
Bitset encode(const wire_type &value) override
Encodes a non-empty field, adding a 1 bit to the front for optional fields.
field_type post_decode(const wire_type &wire_value) override
Convert from the WireType representation (used with encode() and decode(), i.e. "on the wire") to the...
Dynamic Compact Control Language namespace.