@@ -82,24 +82,6 @@ template <typename encoded_variable_t>
82
82
template <IntegerType T>
83
83
[[nodiscard]] auto get_ones_complement (T int_val) -> T;
84
84
85
- /* *
86
- * Encodes and serializes a schema tree node ID using the given encoding type.
87
- * @tparam is_auto_generated_node Whether the node is from the auto-generated or the user-generated
88
- * schema tree.
89
- * @tparam length_indicator_tag
90
- * @tparam encoded_node_id_t
91
- * @param node_id
92
- * @param output_buf
93
- */
94
- template <
95
- bool is_auto_generated_node,
96
- int8_t length_indicator_tag,
97
- SignedIntegerType encoded_node_id_t >
98
- auto size_dependent_encode_and_serialize_schema_tree_node_id (
99
- SchemaTree::Node::id_t node_id,
100
- std::vector<int8_t >& output_buf
101
- ) -> void;
102
-
103
85
/* *
104
86
* Encodes and serializes a schema tree node ID.
105
87
* @tparam is_auto_generated_node Whether the schema tree node ID is from the auto-generated or the
@@ -122,21 +104,6 @@ template <
122
104
std::vector<int8_t >& output_buf
123
105
) -> bool;
124
106
125
- /* *
126
- * Deserializes and decodes a schema tree node ID with the given encoding type.
127
- * @tparam encoded_node_id_t The integer type used to encode the node ID.
128
- * @param reader
129
- * @return A result containing a pair or an error code indicating the failure:
130
- * - The pair:
131
- * - Whether the node ID is for an auto-generated node.
132
- * - The decoded node ID.
133
- * - The possible error codes:
134
- * - std::errc::result_out_of_range if the IR stream is truncated.
135
- */
136
- template <SignedIntegerType encoded_node_id_t >
137
- [[nodiscard]] auto size_dependent_deserialize_and_decode_schema_tree_node_id (ReaderInterface& reader
138
- ) -> OUTCOME_V2_NAMESPACE::std_result<std::pair<bool, SchemaTree::Node::id_t>>;
139
-
140
107
/* *
141
108
* Deserializes and decodes a schema tree node ID.
142
109
* @tparam one_byte_length_indicator_tag Tag for one-byte node ID encoding.
@@ -232,22 +199,6 @@ auto get_ones_complement(T int_val) -> T {
232
199
return static_cast <T>(~int_val);
233
200
}
234
201
235
- template <
236
- bool is_auto_generated_node,
237
- int8_t length_indicator_tag,
238
- SignedIntegerType encoded_node_id_t >
239
- auto size_dependent_encode_and_serialize_schema_tree_node_id (
240
- SchemaTree::Node::id_t node_id,
241
- std::vector<int8_t >& output_buf
242
- ) -> void {
243
- output_buf.push_back (length_indicator_tag);
244
- if constexpr (is_auto_generated_node) {
245
- serialize_int (get_ones_complement (static_cast <encoded_node_id_t >(node_id)), output_buf);
246
- } else {
247
- serialize_int (static_cast <encoded_node_id_t >(node_id), output_buf);
248
- }
249
- }
250
-
251
202
template <
252
203
bool is_auto_generated_node,
253
204
int8_t one_byte_length_indicator_tag,
@@ -257,40 +208,37 @@ auto encode_and_serialize_schema_tree_node_id(
257
208
SchemaTree::Node::id_t node_id,
258
209
std::vector<int8_t >& output_buf
259
210
) -> bool {
211
+ auto size_dependent_encode_and_serialize_schema_tree_node_id
212
+ = [&output_buf]<SignedIntegerType encoded_node_id_t >(
213
+ int8_t length_indicator_tag,
214
+ SchemaTree::Node::id_t node_id
215
+ ) {
216
+ output_buf.push_back (length_indicator_tag);
217
+ if constexpr (is_auto_generated_node) {
218
+ serialize_int (
219
+ get_ones_complement (static_cast <encoded_node_id_t >(node_id)),
220
+ output_buf
221
+ );
222
+ } else {
223
+ serialize_int (static_cast <encoded_node_id_t >(node_id), output_buf);
224
+ }
225
+ };
226
+
260
227
if (node_id <= static_cast <SchemaTree::Node::id_t >(INT8_MAX)) {
261
- size_dependent_encode_and_serialize_schema_tree_node_id<
262
- is_auto_generated_node,
263
- one_byte_length_indicator_tag,
264
- int8_t >(node_id, output_buf);
228
+ size_dependent_encode_and_serialize_schema_tree_node_id.template operator (
229
+ )<int8_t >(one_byte_length_indicator_tag, node_id);
265
230
} else if (node_id <= static_cast <SchemaTree::Node::id_t >(INT16_MAX)) {
266
- size_dependent_encode_and_serialize_schema_tree_node_id<
267
- is_auto_generated_node,
268
- two_byte_length_indicator_tag,
269
- int16_t >(node_id, output_buf);
231
+ size_dependent_encode_and_serialize_schema_tree_node_id.template operator (
232
+ )<int16_t >(two_byte_length_indicator_tag, node_id);
270
233
} else if (node_id <= static_cast <SchemaTree::Node::id_t >(INT32_MAX)) {
271
- size_dependent_encode_and_serialize_schema_tree_node_id<
272
- is_auto_generated_node,
273
- four_byte_length_indicator_tag,
274
- int32_t >(node_id, output_buf);
234
+ size_dependent_encode_and_serialize_schema_tree_node_id.template operator (
235
+ )<int32_t >(four_byte_length_indicator_tag, node_id);
275
236
} else {
276
237
return false ;
277
238
}
278
239
return true ;
279
240
}
280
241
281
- template <SignedIntegerType encoded_node_id_t >
282
- auto size_dependent_deserialize_and_decode_schema_tree_node_id (ReaderInterface& reader
283
- ) -> OUTCOME_V2_NAMESPACE::std_result<std::pair<bool, SchemaTree::Node::id_t>> {
284
- encoded_node_id_t encoded_node_id{};
285
- if (false == deserialize_int (reader, encoded_node_id)) {
286
- return std::errc::result_out_of_range;
287
- }
288
- if (0 > encoded_node_id) {
289
- return {true , static_cast <SchemaTree::Node::id_t >(get_ones_complement (encoded_node_id))};
290
- }
291
- return {false , static_cast <SchemaTree::Node::id_t >(encoded_node_id)};
292
- }
293
-
294
242
template <
295
243
int8_t one_byte_length_indicator_tag,
296
244
int8_t two_byte_length_indicator_tag,
@@ -299,14 +247,31 @@ auto deserialize_and_decode_schema_tree_node_id(
299
247
encoded_tag_t length_indicator_tag,
300
248
ReaderInterface& reader
301
249
) -> OUTCOME_V2_NAMESPACE::std_result<std::pair<bool, SchemaTree::Node::id_t>> {
250
+ auto size_dependent_deserialize_and_decode_schema_tree_node_id
251
+ = [&reader]<SignedIntegerType encoded_node_id_t >(
252
+ ) -> OUTCOME_V2_NAMESPACE::std_result<std::pair<bool , SchemaTree::Node::id_t >> {
253
+ encoded_node_id_t encoded_node_id{};
254
+ if (false == deserialize_int (reader, encoded_node_id)) {
255
+ return std::errc::result_out_of_range;
256
+ }
257
+ if (0 > encoded_node_id) {
258
+ return {true , static_cast <SchemaTree::Node::id_t >(get_ones_complement (encoded_node_id))
259
+ };
260
+ }
261
+ return {false , static_cast <SchemaTree::Node::id_t >(encoded_node_id)};
262
+ };
263
+
302
264
if (one_byte_length_indicator_tag == length_indicator_tag) {
303
- return size_dependent_deserialize_and_decode_schema_tree_node_id<int8_t >(reader);
265
+ return size_dependent_deserialize_and_decode_schema_tree_node_id.template operator (
266
+ )<int8_t >();
304
267
}
305
268
if (two_byte_length_indicator_tag == length_indicator_tag) {
306
- return size_dependent_deserialize_and_decode_schema_tree_node_id<int16_t >(reader);
269
+ return size_dependent_deserialize_and_decode_schema_tree_node_id.template operator (
270
+ )<int16_t >();
307
271
}
308
272
if (four_byte_length_indicator_tag == length_indicator_tag) {
309
- return size_dependent_deserialize_and_decode_schema_tree_node_id<int32_t >(reader);
273
+ return size_dependent_deserialize_and_decode_schema_tree_node_id.template operator (
274
+ )<int32_t >();
310
275
}
311
276
return std::errc::protocol_error;
312
277
}
0 commit comments