Skip to content

Commit fcbd496

Browse files
Apply suggestions from code review
Co-authored-by: kirkrodrigues <[email protected]>
1 parent 3981538 commit fcbd496

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

components/core/src/clp/ffi/ir_stream/Serializer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Serializer {
103103
/**
104104
* Serializes the given key ID into `m_key_group_buf`.
105105
* @param id
106-
* @return Forwards `encode_and_serialize_schema_tree_node_id`s return values.
106+
* @return Forwards `encode_and_serialize_schema_tree_node_id`'s return values.
107107
*/
108108
[[nodiscard]] auto serialize_key(SchemaTree::Node::id_t id) -> bool;
109109

components/core/src/clp/ffi/ir_stream/ir_unit_deserialization_methods.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ using Schema = std::vector<SchemaTree::Node::id_t>;
4444
/**
4545
* Deserializes the parent ID of a schema tree node.
4646
* @param reader
47-
* @return a result containing a pair of an auto-generated ID indicator and a decoded node ID, or an
48-
* error code indicating the failure:
49-
* - Forwards `deserialize_and_decode_schema_tree_node_id`'s return values.
50-
* - Forwards `deserialize_tag`'s return values.
47+
* @return A result containing a pair or an error code indicating the failure:
48+
* - The pair:
49+
* - Whether the node ID is for an auto-generated node.
50+
* - The decoded node ID.
51+
* - The possible error codes:
52+
* - Forwards `deserialize_tag`'s return values.
53+
* @return Forwards `deserialize_and_decode_schema_tree_node_id`'s return values.
5154
*/
5255
[[nodiscard]] auto deserialize_schema_tree_node_parent_id(ReaderInterface& reader
5356
) -> OUTCOME_V2_NAMESPACE::std_result<std::pair<bool, SchemaTree::Node::id_t>>;
@@ -99,6 +102,8 @@ deserialize_int_val(ReaderInterface& reader, encoded_tag_t tag, value_int_t& val
99102
* @param reader
100103
* @param tag Takes the current tag as input and returns the last tag read.
101104
* @return A result containing the deserialized schema or an error code indicating the failure:
105+
* - std::err::protocol_not_supported if the IR stream contains auto-generated keys (TODO: Remove
106+
* this once auto-generated keys are fully supported).
102107
* - Forwards `deserialize_tag`'s return values.
103108
* - Forwards `deserialize_and_decode_schema_tree_node_id`'s return values.
104109
*/
@@ -174,7 +179,7 @@ requires(std::is_same_v<ir::four_byte_encoded_variable_t, encoded_variable_t>
174179

175180
/**
176181
* @param tag
177-
* @return Whether the given tag represent a valid encoded key ID.
182+
* @return Whether the given tag represents a valid encoded key ID.
178183
*/
179184
[[nodiscard]] auto is_encoded_key_id_tag(encoded_tag_t tag) -> bool;
180185

@@ -292,6 +297,7 @@ auto deserialize_schema(ReaderInterface& reader, encoded_tag_t& tag)
292297
Schema schema;
293298
while (true) {
294299
if (false == is_encoded_key_id_tag(tag)) {
300+
// The log event must be an empty value.
295301
break;
296302
}
297303

@@ -304,7 +310,7 @@ auto deserialize_schema(ReaderInterface& reader, encoded_tag_t& tag)
304310
}
305311
auto const [is_auto_generated, node_id]{schema_tree_node_id_result.value()};
306312
if (is_auto_generated) {
307-
// currently, we don't support auto-generated keys
313+
// Currently, we don't support auto-generated keys.
308314
return std::errc::protocol_not_supported;
309315
}
310316
schema.push_back(node_id);
@@ -470,10 +476,11 @@ auto is_log_event_ir_unit_tag(encoded_tag_t tag) -> bool {
470476

471477
auto is_encoded_key_id_tag(encoded_tag_t tag) -> bool {
472478
// Ideally, we could check whether the tag is within the range of
473-
// [EncodedKeyIdByte, EncodedKeyIdInt]. There are two reasons why we don't do this:
474-
// - We optimize for streams that has few key IDs: we can short circuit in the first branch
475-
// - The range check assumes all length indicator to be defined continuously in order
476-
// We don't have static checks for this assumption.
479+
// [EncodedKeyIdByte, EncodedKeyIdInt], but we don't for two reasons:
480+
// - We optimize for streams that have few key IDs, meaning we can short circuit in the first
481+
// branch below.
482+
// - Using a range check assumes all length indicators are defined continuously, in order, but
483+
// we don't have static checks for this assumption.
477484
return cProtocol::Payload::EncodedKeyIdByte == tag
478485
|| cProtocol::Payload::EncodedKeyIdShort == tag
479486
|| cProtocol::Payload::EncodedKeyIdInt == tag;
@@ -517,7 +524,7 @@ auto deserialize_ir_unit_schema_tree_node_insertion(
517524
}
518525
auto const [is_auto_generated, parent_id]{parent_node_id_result.value()};
519526
if (is_auto_generated) {
520-
// currently, we don't support auto-generated keys
527+
// Currently, we don't support auto-generated keys.
521528
return std::errc::protocol_not_supported;
522529
}
523530

components/core/src/clp/ffi/ir_stream/ir_unit_deserialization_methods.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace clp::ffi::ir_stream {
3232
* indicating the failure:
3333
* - std::errc::result_out_of_range if the IR stream is truncated.
3434
* - std::errc::protocol_error if the deserialized node type isn't supported.
35-
* - std::errc::protocol_not_supported if the IR stream contains auto-generated keys.
36-
* TODO: remove this once auto-generated keys are fully supported.
35+
* - std::errc::protocol_not_supported if the IR stream contains auto-generated keys (TODO: Remove
36+
* this once auto-generated keys are fully supported).
3737
* - Forwards `deserialize_schema_tree_node_key_name`'s return values.
3838
* - Forwards `deserialize_schema_tree_node_parent_id`'s return values.
3939
*/

components/core/src/clp/ffi/ir_stream/utils.hpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ template <typename encoded_variable_t>
7777
/**
7878
* @tparam T
7979
* @param int_val
80-
* @return One's complement of `int_val` without implicit integer promotions.
80+
* @return One's complement of `int_val`.
8181
*/
8282
template <IntegerType T>
8383
[[nodiscard]] auto get_ones_complement(T int_val) -> T;
8484

8585
/**
8686
* Encodes and serializes a schema tree node ID using the given encoding type.
87-
* @tparam is_auto_generated Whether the schema tree node ID comes from the auto-generated or the
88-
* user-generated schema tree.
87+
* @tparam is_auto_generated Whether the node is from the auto-generated or the user-generated
88+
* schema tree.
8989
* @tparam length_indicator_tag
9090
* @tparam encoded_node_id_t
9191
* @param node_id
@@ -99,7 +99,7 @@ auto size_dependent_encode_and_serialize_schema_tree_node_id(
9999

100100
/**
101101
* Encodes and serializes a schema tree node ID.
102-
* @tparam is_auto_generated Whether the schema tree node ID comes from the auto-generated or the
102+
* @tparam is_auto_generated Whether the schema tree node ID is from the auto-generated or the
103103
* user-generated schema tree.
104104
* @tparam one_byte_length_indicator_tag Tag for one-byte node ID encoding.
105105
* @tparam two_byte_length_indicator_tag Tag for two-byte node ID encoding.
@@ -123,9 +123,12 @@ template <
123123
* Deserializes and decodes a schema tree node ID with the given encoding type.
124124
* @tparam encoded_node_id_t The integer type used to encode the node ID.
125125
* @param reader
126-
* @return a result containing a pair of an auto-generated ID indicator and a decoded node ID, or an
127-
* error code indicating the failure:
128-
* - std::errc::result_out_of_range if the IR stream is truncated.
126+
* @return A result containing a pair or an error code indicating the failure:
127+
* - The pair:
128+
* - Whether the node ID is for an auto-generated node.
129+
* - The decoded node ID.
130+
* - The possible error codes:
131+
* - std::errc::result_out_of_range if the IR stream is truncated.
129132
*/
130133
template <SignedIntegerType encoded_node_id_t>
131134
[[nodiscard]] auto size_dependent_deserialize_and_decode_schema_tree_node_id(ReaderInterface& reader
@@ -138,10 +141,13 @@ template <SignedIntegerType encoded_node_id_t>
138141
* @tparam four_byte_length_indicator_tag Tag for four-byte node ID encoding.
139142
* @param length_indicator_tag
140143
* @param reader
141-
* @return a result containing a pair of an auto-generated ID indicator and a decoded node ID, or an
142-
* error code indicating the failure:
143-
* - std::errc::protocol_error if the given length indicator is unknown.
144-
* - Forwards `size_dependent_deserialize_and_decode_schema_tree_node_id`'s return values.
144+
* @return A result containing a pair or an error code indicating the failure:
145+
* - The pair:
146+
* - Whether the node ID is for an auto-generated node.
147+
* - The decoded node ID.
148+
* - The possible error codes:
149+
* - std::errc::protocol_error if the given length indicator is unknown.
150+
* @return Forwards `size_dependent_deserialize_and_decode_schema_tree_node_id`'s return values.
145151
*/
146152
template <
147153
int8_t one_byte_length_indicator_tag,
@@ -219,6 +225,7 @@ template <typename encoded_variable_t>
219225

220226
template <IntegerType T>
221227
auto get_ones_complement(T int_val) -> T {
228+
// Explicit cast to undo the implicit integer promotion
222229
return static_cast<T>(~int_val);
223230
}
224231

0 commit comments

Comments
 (0)