1+ /* *
2+ * @file
3+ * @author Pavel Siska <[email protected] > 4+ * @brief Provides the FieldDescriptor class for accessing field metadata and value getters.
5+ *
6+ * This class encapsulates information about a field in a FlowRecord, including its
7+ * name, group, bit index, and a generic value accessor. It allows checking if the
8+ * field is present in a specific FlowRecord. Construction is restricted to FieldManager.
9+ *
10+ * @copyright Copyright (c) 2025 CESNET, z.s.p.o.
11+ */
12+
13+ #pragma once
14+
15+ #include " fieldGenericValueGetter.hpp"
16+ #include " fieldInfo.hpp"
17+ #include " flowRecord.hpp"
18+
19+ #include < cstdint>
20+ #include < string>
21+ #include < string_view>
22+
23+ namespace ipxp {
24+
25+ /* *
26+ * @class FieldDescriptor
27+ * @brief Read-only access to field metadata and value getters.
28+ *
29+ * FieldDescriptor represents a single field within a FlowRecord. It provides
30+ * information about the field's name, logical group, bit index, and a generic
31+ * value accessor. It allows checking if the field is present in a specific
32+ * FlowRecord using the `isInRecord()` method.
33+ *
34+ * Instances are immutable and can only be created by FieldManager, ensuring
35+ * controlled registration and consistent state of fields.
36+ */
37+ class FieldDescriptor {
38+ public:
39+ /* *
40+ * @brief Returns the name of the field.
41+ * @return Field name as string_view.
42+ */
43+ [[nodiscard]]
44+ std::string_view getName () const noexcept
45+ {
46+ return m_fieldInfo.name ;
47+ }
48+
49+ /* *
50+ * @brief Returns the logical group name of the field.
51+ * @return Group name (e.g., "tcp", "http").
52+ */
53+ [[nodiscard]]
54+ std::string_view getGroup () const noexcept
55+ {
56+ return m_fieldInfo.group ;
57+ }
58+
59+ /* *
60+ * @brief Returns the generic value accessor for the field.
61+ * @return Reference to GenericValueGetter variant.
62+ */
63+ [[nodiscard]]
64+ const GenericValueGetter& getValueGetter () const noexcept
65+ {
66+ return m_fieldInfo.getter ;
67+ }
68+
69+ /* *
70+ * @brief Returns the bit index used to check field presence in FlowRecord.
71+ * @return Bit index as size_t.
72+ */
73+ [[nodiscard]]
74+ std::size_t getBitIndex () const noexcept
75+ {
76+ return m_fieldInfo.bitIndex ;
77+ }
78+
79+ /* *
80+ * @brief Checks whether this field is present in a given FlowRecord.
81+ * @param record Flow record to query.
82+ * @return True if the field is available in the record.
83+ */
84+ [[nodiscard]]
85+ bool isInRecord (const FlowRecord& record) const
86+ {
87+ return record.fieldsAvailable .test (m_fieldInfo.bitIndex );
88+ }
89+
90+ private:
91+ // FieldDescriptor can only be constructed by FieldManager
92+ friend class FieldManager ;
93+
94+ explicit FieldDescriptor (FieldInfo fieldInfo)
95+ : m_fieldInfo(std::move(fieldInfo))
96+ {
97+ }
98+
99+ const FieldInfo m_fieldInfo;
100+ };
101+
102+ } // namespace ipxp
0 commit comments