DCCL v5
Loading...
Searching...
No Matches
field_codec_data.h
1// Copyright 2023:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Dynamic Compact Control Language Library
9// ("DCCL").
10//
11// DCCL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// DCCL is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23#ifndef DCCLFIELDCODECDATAH
24#define DCCLFIELDCODECDATAH
25
26#include "../dynamic_conditions.h"
27
28#include "field_codec_message_stack.h"
29
30#include <typeindex>
31
32namespace google
33{
34namespace protobuf
35{
36class Message;
37class Descriptor;
38} // namespace protobuf
39} // namespace google
40
41namespace dccl
42{
43namespace internal
44{
45// Data shared amongst all the FieldCodecs for a single message
47{
48 MessagePart part_{dccl::UNKNOWN};
49 bool strict_{false};
50 const google::protobuf::Message* root_message_{nullptr};
51 const google::protobuf::Descriptor* root_descriptor_{nullptr};
52 MessageStackData message_data_;
53 DynamicConditions dynamic_conditions_;
54
55 // Pointer to the root Bitset for the current encode or decode operation.
56 //
57 // During encoding: updated by field_encode() to point to the accumulation Bitset for each
58 // field. When any_encode() is called for a field, root_bits_ holds all bits encoded by
59 // previous sibling fields in the same message.
60 //
61 // During decoding: points to decoded_bits_, which accumulates bits for fields already
62 // decoded in the current message. When post_decode() is called for a field, root_bits_
63 // holds all bits decoded by previous sibling fields.
64 //
65 // Returns nullptr outside of an encode/decode context (e.g., during validate/info).
66 Bitset* root_bits_{nullptr};
67 Bitset root_bits_copy_; // unused - kept for ABI stability
68 Bitset decoded_bits_; // accumulates decoded bits during base_decode()
69
70 template <typename FieldCodecType>
71 void set_codec_specific_data(std::shared_ptr<dccl::any> data)
72 {
73 codec_specific_[std::type_index(typeid(FieldCodecType))] = data;
74 }
75
76 template <typename FieldCodecType> std::shared_ptr<dccl::any> codec_specific_data()
77 {
78 return codec_specific_.at(std::type_index(typeid(FieldCodecType)));
79 }
80
81 template <typename FieldCodecType> bool has_codec_specific_data()
82 {
83 return codec_specific_.count(std::type_index(typeid(FieldCodecType)));
84 }
85
86 private:
87 std::map<std::type_index, std::shared_ptr<dccl::any>> codec_specific_;
88};
89} // namespace internal
90} // namespace dccl
91
92#endif
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
Definition bitset.h:43
Dynamic Compact Control Language namespace.
Definition any.h:28