DCCL v4
Loading...
Searching...
No Matches
dccl::v3::PresenceBitCodec< WrappedType > Class Template Reference

Encodes empty optional fields with a single "presence" bit. More...

#include <dccl/codecs3/field_codec_presence.h>

Inheritance diagram for dccl::v3::PresenceBitCodec< WrappedType >:

Public Types

using Base = TypedFieldCodec< typename WrappedType::wire_type, typename WrappedType::field_type >
 
using wrapped_type = WrappedType
 The codec type of the "wrapped" codec.
 
using wire_type = typename Base::wire_type
 The wire_type of the "wrapped" codec.
 
using field_type = typename Base::field_type
 The field_type of the "wrapped" codec.
 
- Public Types inherited from dccl::TypedFieldCodec< WrappedType::wire_type, WrappedType::field_type >
using wire_type = WrappedType::wire_type
 
using field_type = WrappedType::field_type
 

Public Member Functions

wire_type pre_encode (const field_type &field_value) override
 Convert from the FieldType representation (used in the Google Protobuf message) to the WireType representation (used with encode() and decode(), i.e. "on the wire").
 
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 FieldType representation (used in the Google Protobuf message).
 
void validate () override
 Calls _inner_codec.validate()
 
Bitset encode () override
 Encodes an empty field as a single 0 bit.
 
Bitset encode (const wire_type &value) override
 Encodes a non-empty field, adding a 1 bit to the front for optional fields.
 
wire_type decode (Bitset *bits) override
 Decodes a field, first evaluating the presence bit if necessary.
 
unsigned size () override
 Size of an empty field (1 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.
 
unsigned max_size () override
 Calculate maximum size of the field in bits.
 
unsigned min_size () override
 Calculate minimum size of the field in bits.
 
void set_manager (FieldCodecManagerLocal *manager) override
 
- Public Member Functions inherited from dccl::TypedFieldCodec< WrappedType::wire_type, WrappedType::field_type >
virtual Bitset encode (const WrappedType::wire_type &wire_value)=0
 Encode a non-empty field.
 
virtual unsigned size (const WrappedType::wire_type &wire_value)=0
 Calculate the size (in bits) of a non-empty field.
 
- Public Member Functions inherited from dccl::FieldCodecBase
void base_encode (Bitset *bits, const google::protobuf::Message &msg, MessagePart part, bool strict)
 Encode this part (body or head) of the base message.
 
void base_size (unsigned *bit_size, const google::protobuf::Message &msg, MessagePart part)
 Calculate the size (in bits) of a part of the base message when it is encoded.
 
void base_decode (Bitset *bits, google::protobuf::Message *msg, MessagePart part)
 Decode part of a message.
 
void base_max_size (unsigned *bit_size, const google::protobuf::Descriptor *desc, MessagePart part)
 Calculate the maximum size of a message given its Descriptor alone (no data)
 
void base_min_size (unsigned *bit_size, const google::protobuf::Descriptor *desc, MessagePart part)
 Calculate the minimum size of a message given its Descriptor alone (no data)
 
void base_validate (const google::protobuf::Descriptor *desc, MessagePart part)
 Validate this part of the message to make sure all required extensions are set.
 
void base_info (std::ostream *os, const google::protobuf::Descriptor *desc, MessagePart part)
 Get human readable information (size of fields, etc.) about this part of the DCCL message.
 
void base_hash (std::size_t *hash, const google::protobuf::Descriptor *desc, MessagePart part)
 Provide a hash of the DCCL message definition to detect changes in the DCCL message.
 
void field_pre_encode (dccl::any *wire_value, const dccl::any &field_value)
 Pre-encodes a non-repeated (i.e. optional or required) field by converting the FieldType representation (the Google Protobuf representation) into the WireType representation (the type used in the encoded DCCL message). This allows for type-converting codecs.
 
void field_pre_encode_repeated (std::vector< dccl::any > *wire_values, const std::vector< dccl::any > &field_values)
 Pre-encodes a repeated field.
 
void field_encode (Bitset *bits, const dccl::any &field_value, const google::protobuf::FieldDescriptor *field)
 Encode a non-repeated field.
 
void field_encode_repeated (Bitset *bits, const std::vector< dccl::any > &field_values, const google::protobuf::FieldDescriptor *field)
 Encode a repeated field.
 
void field_size (unsigned *bit_size, const dccl::any &field_value, const google::protobuf::FieldDescriptor *field)
 Calculate the size of a field.
 
void field_size_repeated (unsigned *bit_size, const std::vector< dccl::any > &field_values, const google::protobuf::FieldDescriptor *field)
 Calculate the size of a repeated field.
 
void field_decode (Bitset *bits, dccl::any *field_value, const google::protobuf::FieldDescriptor *field)
 Decode a non-repeated field.
 
void field_decode_repeated (Bitset *bits, std::vector< dccl::any > *field_values, const google::protobuf::FieldDescriptor *field)
 Decode a repeated field.
 
void field_post_decode (const dccl::any &wire_value, dccl::any *field_value)
 Post-decodes a non-repeated (i.e. optional or required) field by converting the WireType (the type used in the encoded DCCL message) representation into the FieldType representation (the Google Protobuf representation). This allows for type-converting codecs.
 
void field_post_decode_repeated (const std::vector< dccl::any > &wire_values, std::vector< dccl::any > *field_values)
 Post-decodes a repeated field.
 
void field_max_size (unsigned *bit_size, const google::protobuf::FieldDescriptor *field)
 Calculate the upper bound on this field's size (in bits)
 
void field_min_size (unsigned *bit_size, const google::protobuf::FieldDescriptor *field)
 Calculate the lower bound on this field's size (in bits)
 
void field_validate (bool *b, const google::protobuf::FieldDescriptor *field)
 Validate this field, checking that all required option extensions are set (e.g. (dccl.field).max and (dccl.field).min for arithmetic codecs)
 
void field_info (std::ostream *os, const google::protobuf::FieldDescriptor *field)
 Write human readable information about the field and its bounds to the provided stream.
 
void field_hash (std::size_t *hash, const google::protobuf::FieldDescriptor *field)
 Provide a hash for this field definition.
 
dccl::DCCLFieldOptions dccl_field_options () const
 Get the DCCL field option extension value for the current field.
 
void require (bool b, const std::string &description)
 Essentially an assertion to be used in the validate() virtual method.
 
DynamicConditionsdynamic_conditions (const google::protobuf::FieldDescriptor *field)
 
FieldCodecManagerLocalmanager ()
 
const FieldCodecManagerLocalmanager () const
 
std::string name () const
 the name of the codec used to identifier it in the .proto custom option extension
 
google::protobuf::FieldDescriptor::Type field_type () const
 the type exposed to the user in the original and decoded Protobuf messages
 
google::protobuf::FieldDescriptor::CppType wire_type () const
 the C++ type used "on the wire". This is the type visible after pre_encode and before post_decode functions are called.
 
const google::protobuf::FieldDescriptor * this_field () const
 Returns the FieldDescriptor (field schema meta-data) for this field.
 
const google::protobuf::Descriptor * this_descriptor () const
 Returns the Descriptor (message schema meta-data) for the immediate parent Message.
 
const google::protobuf::Message * this_message ()
 
const google::protobuf::Message * root_message ()
 
const google::protobuf::Descriptor * root_descriptor () const
 
internal::MessageStackDatamessage_data ()
 
const internal::MessageStackDatamessage_data () const
 
bool has_codec_group ()
 
std::string codec_group ()
 
int codec_version ()
 
MessagePart part ()
 the part of the message currently being encoded (head or body)
 
bool strict ()
 
void set_force_use_required (bool force_required=true)
 Force the codec to always use the "required" field encoding, regardless of the FieldDescriptor setting. Useful when wrapping this codec in another that handles optional and repeated fields.
 

Additional Inherited Members

- Static Public Member Functions inherited from dccl::FieldCodecBase
static std::string codec_group (const google::protobuf::Descriptor *desc)
 
- Protected Member Functions inherited from dccl::FieldCodecBase
bool use_required ()
 Whether to use the required or optional encoding.
 
virtual std::string info ()
 Write field specific information (in addition to general information such as sizes that are automatically written by this class for all fields.
 
virtual std::size_t hash ()
 Generate a field specific hash to be combined with the descriptor hash.
 
virtual void any_encode_repeated (Bitset *bits, const std::vector< dccl::any > &wire_values)
 
virtual void any_decode_repeated (Bitset *repeated_bits, std::vector< dccl::any > *field_values)
 
virtual void any_pre_encode_repeated (std::vector< dccl::any > *wire_values, const std::vector< dccl::any > &field_values)
 
virtual void any_post_decode_repeated (const std::vector< dccl::any > &wire_values, std::vector< dccl::any > *field_values)
 
virtual unsigned any_size_repeated (const std::vector< dccl::any > &wire_values)
 
virtual unsigned max_size_repeated ()
 
virtual unsigned min_size_repeated ()
 
void check_repeat_settings () const
 

Detailed Description

template<typename WrappedType>
class dccl::v3::PresenceBitCodec< WrappedType >

Encodes empty optional fields with a single "presence" bit.

This class wraps an existing TypedFieldCodec, adding an extra "presence" bit to the LSB for optional fields. The field size is as follows:

  • Optional
    • Empty: 1 bit
    • Non-empty: size of WrappedType + 1
  • Required
    • Empty: size of WrappedType
    • Non-empty: size of WrappedType

Definition at line 44 of file field_codec_presence.h.

Member Typedef Documentation

◆ Base

template<typename WrappedType >
using dccl::v3::PresenceBitCodec< WrappedType >::Base = TypedFieldCodec<typename WrappedType::wire_type, typename WrappedType::field_type>

Definition at line 48 of file field_codec_presence.h.

◆ field_type

template<typename WrappedType >
using dccl::v3::PresenceBitCodec< WrappedType >::field_type = typename Base::field_type

The field_type of the "wrapped" codec.

Definition at line 57 of file field_codec_presence.h.

◆ wire_type

template<typename WrappedType >
using dccl::v3::PresenceBitCodec< WrappedType >::wire_type = typename Base::wire_type

The wire_type of the "wrapped" codec.

Definition at line 54 of file field_codec_presence.h.

◆ wrapped_type

template<typename WrappedType >
using dccl::v3::PresenceBitCodec< WrappedType >::wrapped_type = WrappedType

The codec type of the "wrapped" codec.

Definition at line 51 of file field_codec_presence.h.

Constructor & Destructor Documentation

◆ PresenceBitCodec()

template<typename WrappedType >
dccl::v3::PresenceBitCodec< WrappedType >::PresenceBitCodec ( )
inline

Definition at line 64 of file field_codec_presence.h.

Member Function Documentation

◆ decode()

template<typename WrappedType >
wire_type dccl::v3::PresenceBitCodec< WrappedType >::decode ( Bitset bits)
inlineoverridevirtual

Decodes a field, first evaluating the presence bit if necessary.

Implements dccl::TypedFieldCodec< WrappedType::wire_type, WrappedType::field_type >.

Definition at line 100 of file field_codec_presence.h.

◆ encode() [1/2]

template<typename WrappedType >
Bitset dccl::v3::PresenceBitCodec< WrappedType >::encode ( )
inlineoverridevirtual

Encodes an empty field as a single 0 bit.

Implements dccl::TypedFieldCodec< WrappedType::wire_type, WrappedType::field_type >.

Definition at line 82 of file field_codec_presence.h.

◆ encode() [2/2]

template<typename WrappedType >
Bitset dccl::v3::PresenceBitCodec< WrappedType >::encode ( const wire_type value)
inlineoverride

Encodes a non-empty field, adding a 1 bit to the front for optional fields.

Definition at line 88 of file field_codec_presence.h.

◆ max_size()

template<typename WrappedType >
unsigned dccl::v3::PresenceBitCodec< WrappedType >::max_size ( )
inlineoverridevirtual

Calculate maximum size of the field in bits.

Returns
Maximum size of this field (in bits).

Implements dccl::FieldCodecBase.

Definition at line 132 of file field_codec_presence.h.

◆ min_size()

template<typename WrappedType >
unsigned dccl::v3::PresenceBitCodec< WrappedType >::min_size ( )
inlineoverridevirtual

Calculate minimum size of the field in bits.

Returns
Minimum size of this field (in bits).

Implements dccl::FieldCodecBase.

Definition at line 146 of file field_codec_presence.h.

◆ post_decode()

template<typename WrappedType >
field_type dccl::v3::PresenceBitCodec< WrappedType >::post_decode ( const wire_type wire_value)
inlineoverridevirtual

Convert from the WireType representation (used with encode() and decode(), i.e. "on the wire") to the FieldType representation (used in the Google Protobuf message).

Parameters
wire_valueValue to convert
Returns
Converted value

Implements dccl::FieldCodecSelector< WireType, FieldType, Enable >.

Definition at line 73 of file field_codec_presence.h.

◆ pre_encode()

template<typename WrappedType >
wire_type dccl::v3::PresenceBitCodec< WrappedType >::pre_encode ( const field_type field_value)
inlineoverridevirtual

Convert from the FieldType representation (used in the Google Protobuf message) to the WireType representation (used with encode() and decode(), i.e. "on the wire").

Parameters
field_valueValue to convert
Returns
Converted value

Implements dccl::FieldCodecSelector< WireType, FieldType, Enable >.

Definition at line 67 of file field_codec_presence.h.

◆ set_manager()

template<typename WrappedType >
void dccl::v3::PresenceBitCodec< WrappedType >::set_manager ( FieldCodecManagerLocal manager)
inlineoverridevirtual

Reimplemented from dccl::FieldCodecBase.

Definition at line 160 of file field_codec_presence.h.

◆ size() [1/2]

template<typename WrappedType >
unsigned dccl::v3::PresenceBitCodec< WrappedType >::size ( )
inlineoverridevirtual

Size of an empty field (1 bit)

Implements dccl::TypedFieldCodec< WrappedType::wire_type, WrappedType::field_type >.

Definition at line 119 of file field_codec_presence.h.

◆ size() [2/2]

template<typename WrappedType >
unsigned dccl::v3::PresenceBitCodec< WrappedType >::size ( const wire_type wire_value)
inlineoverride

Size of a non-empty field; gets size from "wrapped" codec, adds 1 for optional fields.

Definition at line 126 of file field_codec_presence.h.

◆ validate()

template<typename WrappedType >
void dccl::v3::PresenceBitCodec< WrappedType >::validate ( )
inlineoverridevirtual

Calls _inner_codec.validate()

Reimplemented from dccl::FieldCodecBase.

Definition at line 79 of file field_codec_presence.h.


The documentation for this class was generated from the following file: