-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Add support for retrieving CLP IR stream-level metadata from IR stream readers (resolves #77). #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ed IR stream readers.
Warning Rate limit exceeded@junhaoliao has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 3 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
""" WalkthroughThe changes remove redundant rewind and encoding validation in the IR stream reader creation, centralize metadata deserialization into a dedicated function, and add metadata storage and access support in both structured and unstructured IR stream readers. Emscripten bindings are extended to expose metadata to JavaScript. Utility functions for JSON serialization with invalid UTF-8 replacement are introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant JS as JavaScript
participant Emscripten
participant StreamReader
participant ReaderInterface
JS->>Emscripten: Create StreamReader from data array
Emscripten->>StreamReader: create(data_array, reader_options)
StreamReader->>ReaderInterface: deserialize_metadata()
ReaderInterface-->>StreamReader: metadata JSON
StreamReader->>StreamReader: rewind decompressor to start
StreamReader->>StreamReader: validate version and create appropriate IR stream reader
StreamReader-->>Emscripten: StreamReader instance with metadata
Emscripten-->>JS: StreamReader object (with get_metadata method)
JS->>StreamReader: get_metadata()
StreamReader-->>JS: MetadataTsType (JS object)
Possibly related issues
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
… as a JavaScript object
…type as JavaScript object
); | ||
|
||
// JS types used as outputs | ||
emscripten::register_type<clp_ffi_js::ir::MetadataTsType>("Record<string, any>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was added
&clp_ffi_js::ir::StreamReader::create, | ||
emscripten::return_value_policy::take_ownership() | ||
) | ||
.function("getMetadata", &clp_ffi_js::ir::StreamReader::get_metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was added
auto get_version(clp::ReaderInterface& reader) -> std::string { | ||
std::string version; | ||
try { | ||
auto const metadata_json = clp_ffi_js::ir::deserialize_metadata(reader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata deserialization logic was extracted as deserialize_metadata
.
constexpr std::string_view cMergedKvPairsAutoGeneratedKey{"auto-generated"}; | ||
constexpr std::string_view cMergedKvPairsUserGeneratedKey{"user-generated"}; | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to json_utils.hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed offline:
- These utils for rewinding readers are needed because the our deserializer interface doesn't support deserializing IRv1 yet. Hopefully we can get rid of this complicated procedure soon once we have a more complete implementation of the deserializer (this would also avoid deserializing metadata manually. Technically the deserializer API should handle it automatically)
- We should use result-style error handling instead of relying on exceptions, at least for the factory functions. It's meaningless to use a factory function if it just throw on errors, since a constructor can be designed in a same way. The result-style error handling allows us to forward the error code from the core-ffi.
src/clp_ffi_js/json_utils.hpp
Outdated
* @param json | ||
* @return Serialized JSON. | ||
*/ | ||
[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json) -> std::string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we use inline instead of putting the implementation into a source file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe it was because we intended to just wrap the json_obj.dump()
call with specific config arguments. i understand that the inline
keyword is just a suggestion to the compiler, and function calling overhead may not always be reduced
given those, shall we split the implementation into a source file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's put it into a source file.
src/clp_ffi_js/json_utils.hpp
Outdated
* @param json | ||
* @return Serialized JSON. | ||
*/ | ||
[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json) -> std::string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to use json_obj
instead of json
since we usually use json
to refer to the format itself, or a namespace.
); | ||
|
||
// Variables | ||
nlohmann::json m_metadata_json; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
explicit UnstructuredIrStreamReader( | ||
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context | ||
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context, | ||
nlohmann::json&& metadata_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nlohmann::json&& metadata_json | |
nlohmann::json metadata_json |
Do we need an rvalue reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have to. i added the &&
as i considered this as a private constructor for internal use so no flexibility is required
(and also that we have added &&
on stream_reader_data_context
; would it be better to be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to not adding &&
since it's not necessary. We should send a PR to fix stream_reader_data_context
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai create an issue for removing &&
from private constructors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@junhaoliao I've created an issue to track the removal of unnecessary rvalue references from private constructors. The issue includes the context from your discussion with LinZhihao-723 and references this PR and comment thread.
🏁 Script executed:
#!/bin/bash
# Create GitHub issue for removing unnecessary rvalue references from private constructors
gh issue create \
--title "Remove unnecessary rvalue references from private constructors" \
--body "## Description
Remove unnecessary rvalue reference parameters (\`&&\`) from private constructors as they don't provide meaningful benefits for internal-only APIs.
## Context
During PR review, it was noted that private constructors don't need the flexibility of rvalue references since they are only used internally. This applies to parameters like \`stream_reader_data_context\` and \`metadata_json\` in private constructors.
## Examples
- \`UnstructuredIrStreamReader\` private constructor
- \`StructuredIrStreamReader\` private constructor (if applicable)
- Other similar cases in the codebase
## References
- Discussion in PR #80: https://github.com/y-scope/clp-ffi-js/pull/80#discussion_r2107956653
- Related comment: https://github.com/y-scope/clp-ffi-js/pull/80#discussion_r2107956653
## Acceptance Criteria
- [ ] Identify all private constructors using rvalue references unnecessarily
- [ ] Remove \`&&\` from private constructor parameters where not needed
- [ ] Ensure all call sites still compile and work correctly
- [ ] Update any related documentation if necessary
Requested by: @junhaoliao" \
--assignee "junhaoliao"
Length of output: 1277
@junhaoliao Perfect! I've successfully created issue #90 for removing unnecessary rvalue references from private constructors: #90
The issue captures the context from your discussion with LinZhihao-723, includes references to this PR and comment thread, and provides clear acceptance criteria for the cleanup work. It's been assigned to you as requested.
/\_/\
( o.o )
> ^ < *thoughtful*
🧬 Code Graph Analysis Results
Relevant snippets from src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
(lines 176-185):
UnstructuredIrStreamReader::UnstructuredIrStreamReader(
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context,
nlohmann::json&& metadata
)
: m_metadata(std::move(metadata)),
m_stream_reader_data_context{
std::make_unique<StreamReaderDataContext<UnstructuredIrDeserializer>>(
std::move(stream_reader_data_context)
)
} {}
- This snippet shows the definition of the private constructor of
UnstructuredIrStreamReader
which takes rvalue references (&&
) for its parameters. It moves the parameters into member variables. This is directly related to the user comment about removing&&
from private constructors.
Relevant snippets from src/clp_ffi_js/ir/StreamReaderDataContext.hpp
(lines 42-44):
[[nodiscard]] auto get_deserializer() -> Deserializer& { return m_deserializer; }
[[nodiscard]] auto get_reader() -> clp::ReaderInterface& { return *m_reader; }
- These methods provide access to the deserializer and reader inside
StreamReaderDataContext
, which is the type used in the constructor ofUnstructuredIrStreamReader
. Understanding this context may be useful for understanding the constructor parameters.
Relevant snippets from src/clp_ffi_js/ir/StreamReader.hpp
(lines 69-70, 107, 133-134, 155):
create(DataArrayTsType const& data_array, ReaderOptions const& reader_options)
-> std::unique_ptr<StreamReader>
filter_log_events(LogLevelFilterTsType const& log_level_filter)
decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType
find_nearest_log_event_by_timestamp(clp::ir::epoch_time_ms_t target_ts) -> NullableLogEventIdx
- These declarations show the interface of
StreamReader
, whichUnstructuredIrStreamReader
inherits from and overrides. They provide context on the class design and method signatures related to stream reading and filtering.
Relevant snippets from src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
(lines 38-42):
create(
std::unique_ptr<ZstdDecompressor>&& zstd_decompressor,
clp::Array<char> data_array,
ReaderOptions const& reader_options
) -> StructuredIrStreamReader
- This snippet shows a
create
method with a similar signature to thecreate
method inUnstructuredIrStreamReader
. It uses rvalue references (&&
) for the decompressor parameter, which is relevant for comparison regarding the use of&&
in constructors or factory methods.
These snippets provide relevant context on the use of rvalue references (&&
) in constructors and factory methods, especially the private constructor of UnstructuredIrStreamReader
and related classes.
🧠 Learnings used
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
// Constructor | ||
explicit UnstructuredIrStreamReader( | ||
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context | ||
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of this PR's scope: I don't think we need &&
for stream_reader_data_context
either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(sorry i didn't see this earlier)
right, if the same principle applies to metadata_json
. let's continue the discussion at #80 (comment)
As discussed offline, i agree the Rust-like Result-style error is better. i can't quickly figure out how such results can be mapped to Emscripten's Embind system though. Shall we create an issue to address this as a separate effort? I believe this can be better done once we sync the latest clp code into clp-ffi-js (and could be done even better after you are done with the proposed error handling refactoring in clp code) |
Co-authored-by: Lin Zhihao <[email protected]>
Co-authored-by: Lin Zhihao <[email protected]>
…code review Co-authored-by: Lin Zhihao <[email protected]>
Co-authored-by: Lin Zhihao <[email protected]>
Co-authored-by: Lin Zhihao <[email protected]>
# Conflicts: # src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/clp_ffi_js/json_utils.hpp
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/clp_ffi_js/json_utils.hpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint (ubuntu-latest)
🔇 Additional comments (3)
src/clp_ffi_js/json_utils.hpp (3)
20-21
: Include guard closing matches definition.
The#endif
comment correctly referencesCLP_FFI_JS_JSON_UTILS_HPP
. No changes needed.
4-7
:✅ Verification successful
Verify consistency of the nlohmann JSON include path.
Ensure that<json/single_include/nlohmann/json.hpp>
matches the project’s include conventions. Run this to check other instances:
🏁 Script executed:
rg '#include\s*<.*json.hpp>' -n
Length of output: 688
Include path consistency verified
The nlohmann JSON header is uniformly included as<json/single_include/nlohmann/json.hpp>
across all occurrences (e.g.,json_utils.hpp
,UnstructuredIrStreamReader.*
,StructuredIrStreamReader.*
,StreamReader.*
). This matches the project’s existing include conventions—no changes required.
17-19
: 🧹 Nitpick (assertive)Add
noexcept
specifier for stronger exception guarantees.
Sinceerror_handler_t::replace
prevents UTF-8 errors from throwing, consider marking the wrapper asnoexcept
:-[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json_obj) -> std::string { +[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json_obj) noexcept -> std::string {Likely an incorrect or invalid review comment.
src/clp_ffi_js/json_utils.hpp
Outdated
#ifndef CLP_FFI_JS_JSON_UTILS_HPP | ||
#define CLP_FFI_JS_JSON_UTILS_HPP | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider using #pragma once
for include guard simplification.
To reduce boilerplate and avoid macro name collisions, you can replace the traditional guards with:
-#ifndef CLP_FFI_JS_JSON_UTILS_HPP
-#define CLP_FFI_JS_JSON_UTILS_HPP
+#pragma once
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/clp_ffi_js/json_utils.hpp at the beginning of the file (lines 1 to 3),
replace the traditional include guard macros (#ifndef, #define, #endif) with a
single #pragma once directive to simplify the include guard and prevent macro
name collisions.
/** | ||
* @see nlohmann::basic_json::dump | ||
* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than throwing | ||
* an exception. | ||
* @param json_obj | ||
* @return The JSON object serialized as a string. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Enhance Doxygen comment with parameter and brief description.
The @param
tag lacks a description and there’s no brief summary line before @see
. Consider:
- * @see nlohmann::basic_json::dump
+ * Serializes a JSON value into a string, replacing invalid UTF-8 sequences.
+ *
+ * @see nlohmann::basic_json::dump
@param json_obj The JSON object to serialize.
@return The serialized JSON string.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
/** | |
* @see nlohmann::basic_json::dump | |
* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than throwing | |
* an exception. | |
* @param json_obj | |
* @return The JSON object serialized as a string. | |
*/ | |
/** | |
* Serializes a JSON value into a string, replacing invalid UTF-8 sequences. | |
* | |
* @see nlohmann::basic_json::dump | |
* @param json_obj The JSON object to serialize. | |
* @return The serialized JSON string. | |
*/ |
🤖 Prompt for AI Agents
In src/clp_ffi_js/json_utils.hpp around lines 9 to 16, the Doxygen comment is
missing a brief summary line and a description for the @param tag. Add a concise
brief description at the start of the comment summarizing the function's
purpose, and provide a clear explanation for the @param json_obj describing what
it represents or expects.
…s_object for clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
52-76
: Well-documented metadata handling functions.The function declarations are clear and properly documented. Note that a past reviewer suggested creating a separate utility file for these non-member helper methods to avoid cluttering the header.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
src/clp_ffi_js/ir/StreamReader.cpp
(6 hunks)src/clp_ffi_js/ir/StreamReader.hpp
(4 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
(3 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
(4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
src/clp_ffi_js/ir/StreamReader.hpp
src/clp_ffi_js/ir/StreamReader.cpp
🧠 Learnings (3)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
src/clp_ffi_js/ir/StreamReader.cpp (3)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StreamReader.cpp:179-179
Timestamp: 2024-11-07T08:38:39.882Z
Learning: The function `clp::ffi::ir_stream::validate_protocol_version` used in `src/clp_ffi_js/ir/StreamReader.cpp` is imported from the CLP upstream library and may not be present in the local codebase.
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/decoding_methods.cpp:45-80
Timestamp: 2024-11-04T21:06:24.453Z
Learning: In `src/clp_ffi_js/ir/decoding_methods.cpp`, within the `get_version(clp::ReaderInterface&)` function, avoid returning `std::string_view` when referencing local data that goes out of scope. Instead, return `std::string` to ensure data validity.
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
🧬 Code Graph Analysis (2)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (4)
src/clp_ffi_js/ir/StreamReader.cpp (6)
rewind_reader_and_validate_encoding_type
(105-130)rewind_reader_and_validate_encoding_type
(105-105)deserialize_metadata
(132-165)deserialize_metadata
(132-132)convert_metadata_to_js_object
(167-173)convert_metadata_to_js_object
(167-167)src/clp_ffi_js/ir/StreamReader.hpp (3)
rewind_reader_and_validate_encoding_type
(58-58)deserialize_metadata
(67-67)convert_metadata_to_js_object
(75-76)src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
zstd_decompressor
(47-48)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (2)
get_metadata
(120-122)get_metadata
(120-120)
src/clp_ffi_js/ir/StreamReader.hpp (3)
src/clp_ffi_js/json_utils.hpp (1)
nodiscard
(17-19)src/clp_ffi_js/ir/StreamReaderDataContext.hpp (2)
nodiscard
(42-42)nodiscard
(44-44)src/clp_ffi_js/ClpFfiJsException.hpp (1)
nodiscard
(24-24)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint (ubuntu-latest)
🔇 Additional comments (14)
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (3)
28-28
: Good refactoring to centralize JSON utilities.Moving
dump_json_with_replace
to a shared header improves code reusability.
120-122
: Correct implementation of the metadata getter.The method properly implements the virtual function from the base class and correctly converts the stored metadata to a JavaScript object.
220-221
: Metadata extraction looks correct.The metadata is properly extracted from the deserializer during construction. Consider adding validation to ensure the metadata extraction succeeded.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (3)
37-42
: Correct metadata extraction with proper state preservation.The implementation correctly saves and restores the reader position to avoid side effects on subsequent deserialization operations.
62-62
: Efficient parameter passing with move semantics.Good use of
std::move
to avoid unnecessary copies of the metadata JSON object.
65-67
: Consistent metadata getter implementation.The implementation correctly matches the pattern used in
StructuredIrStreamReader
.src/clp_ffi_js/ir/StreamReader.hpp (2)
15-15
: Necessary includes and type declaration for metadata support.The additions properly support the new metadata functionality and follow established patterns.
Also applies to: 20-20, 35-35
111-114
: Clean interface for metadata retrieval.Adding the pure virtual method to the base class ensures consistent metadata access across all stream reader implementations.
src/clp_ffi_js/ir/StreamReader.cpp (6)
27-27
: LGTM: Required include for JSON utilities.The new include is needed for the
dump_json_with_replace
function used inconvert_metadata_to_js_object
.
42-58
: Well-structured refactoring with proper error handling.The rewritten
get_version
function properly delegates todeserialize_metadata
and maintains consistent error handling patterns. The extraction of metadata deserialization logic improves code modularity.
60-101
: Comprehensive Emscripten bindings with good organization.The bindings have been properly moved to the anonymous namespace and significantly expanded to support the new metadata functionality. The separation between input and output types is clear, and all necessary methods are bound for JavaScript interoperability.
156-156
: Simplified return statement improves readability.The direct return of the parsed JSON eliminates unnecessary intermediate variables while maintaining the same functionality.
167-173
: Well-implemented JavaScript interop helper.The
convert_metadata_to_js_object
function properly converts JSON metadata to JavaScript-compatible objects using Emscripten's JSON parsing capabilities and the robustdump_json_with_replace
utility.
194-194
:✅ Verification successful
Verify decompressor position management is correct.
The simplified approach with a single rewind after
get_version
should work correctly sinceget_version
now callsdeserialize_metadata
which handles the metadata reading internally. However, please ensure this doesn't affect the subsequent version validation or stream reader creation.
🏁 Script executed:
#!/bin/bash # Description: Verify that get_version and deserialize_metadata handle reader positioning correctly # Expected: Both functions should rewind the reader to the beginning before processing echo "Searching for reader positioning calls in get_version and deserialize_metadata..." ast-grep --pattern 'auto get_version($reader) -> std::string { $$$ }' echo "Searching for seek operations in deserialize_metadata..." ast-grep --pattern 'auto deserialize_metadata($reader) -> nlohmann::json { $$$ }' echo "Checking if deserialize_preamble affects reader position..." rg -A 10 -B 5 "deserialize_preamble" --type cppLength of output: 1857
#!/bin/bash
Locate the get_version implementation to inspect reader positioning
rg -n "auto get_version" -A 10 -B 5 src/clp_ffi_js/ir/StreamReader.cpp
#!/bin/bash
Locate get_version implementation to inspect reader positioning
echo "=== get_version implementation ==="
rg -n "get_version" -C 5 src/clp_ffi_js/ir/StreamReader.cppLocate deserialize_metadata implementation to inspect reader positioning
echo "=== deserialize_metadata implementation ==="
rg -n "deserialize_metadata" -C 5 src/clp_ffi_js/ir/StreamReader.cppFind any seek/rewind calls in StreamReader.cpp
echo "=== seek operations in StreamReader.cpp ==="
rg -n "seek_from_begin" -C 3 src/clp_ffi_js/ir/StreamReader.cppLocate deserialize_preamble definition to see if it rewinds the reader
echo "=== deserialize_preamble definition ==="
rg -n "deserialize_preamble" -C 5 .
🏁 Script executed:
#!/bin/bash # Search for get_version implementation to inspect reader positioning echo "=== get_version implementation ===" rg -n "auto get_version" -C5 src/clp_ffi_js/ir/StreamReader.cpp # Inspect deserialize_metadata for seek operations echo "=== deserialize_metadata implementation ===" rg -n "auto deserialize_metadata" -C5 src/clp_ffi_js/ir/StreamReader.cpp # Find all seek_from_begin calls in StreamReader.cpp echo "=== seek_from_begin calls in StreamReader.cpp ===" rg -n "seek_from_begin" -C3 src/clp_ffi_js/ir/StreamReader.cppLength of output: 2148
StreamReader.cpp: Decompressor position management verified
A single
zstd_decompressor->seek_from_begin(0)
at line 194 correctly resets the stream after metadata is read inget_version
. Neitherget_version
(lines 42–47) nordeserialize_metadata
perform any implicit seeks, so version validation and the subsequent stream‐reader creation operate on a fresh reader position.No changes required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (9)
CMakeLists.txt
(1 hunks)src/clp_ffi_js/ir/StreamReader.cpp
(5 hunks)src/clp_ffi_js/ir/StreamReader.hpp
(3 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
(3 hunks)src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
(4 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
(4 hunks)src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
(4 hunks)src/clp_ffi_js/ir/decoding_methods.cpp
(1 hunks)src/clp_ffi_js/ir/decoding_methods.hpp
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
src/clp_ffi_js/ir/StreamReader.hpp
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
src/clp_ffi_js/ir/StreamReader.cpp
src/clp_ffi_js/ir/decoding_methods.hpp
src/clp_ffi_js/ir/decoding_methods.cpp
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
🧠 Learnings (5)
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (2)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/IrStreamReader.cpp:58-59
Timestamp: 2024-11-04T19:35:32.602Z
Learning: In the `IrStreamReader::filter_log_events` method in `src/clp_ffi_js/ir/IrStreamReader.cpp`, the wrapper code is typed with TypeScript, ensuring that non-array inputs for `log_level_filter` would fail static checks, so additional runtime error handling is unnecessary.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
src/clp_ffi_js/ir/StreamReader.cpp (3)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/IrStreamReader.cpp:162-168
Timestamp: 2024-11-04T19:55:27.398Z
Learning: In the `IrStreamReader::decode_range` method in `src/clp_ffi_js/ir/IrStreamReader.cpp`, message decoding failures are not expected unless the file is corrupted or the deserializer in CLP core does not handle edge cases, so it's appropriate to throw an exception upon message decoding failure.
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/decoding_methods.cpp:45-80
Timestamp: 2024-11-04T21:06:24.453Z
Learning: In `src/clp_ffi_js/ir/decoding_methods.cpp`, within the `get_version(clp::ReaderInterface&)` function, avoid returning `std::string_view` when referencing local data that goes out of scope. Instead, return `std::string` to ensure data validity.
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
src/clp_ffi_js/ir/decoding_methods.cpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/IrStreamReader.cpp:162-168
Timestamp: 2024-11-04T19:55:27.398Z
Learning: In the `IrStreamReader::decode_range` method in `src/clp_ffi_js/ir/IrStreamReader.cpp`, message decoding failures are not expected unless the file is corrupted or the deserializer in CLP core does not handle edge cases, so it's appropriate to throw an exception upon message decoding failure.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#30
File: src/clp_ffi_js/ir/StructuredIrStreamReader.hpp:187-190
Timestamp: 2024-11-07T08:35:20.376Z
Learning: In the `StructuredIrStreamReader` constructor of `src/clp_ffi_js/ir/StructuredIrStreamReader.hpp`, the `stream_reader_data_context` parameter is already wrapped in a `std::make_unique`, ensuring it matches the member variable `m_stream_reader_data_context` of type `std::unique_ptr<StreamReaderDataContext<StructuredIrDeserializer>>`.
🧬 Code Graph Analysis (5)
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (5)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
nodiscard
(52-54)src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp (1)
nodiscard
(66-66)src/clp_ffi_js/json_utils.hpp (1)
nodiscard
(17-19)src/clp_ffi_js/ir/StreamReaderDataContext.hpp (2)
nodiscard
(42-42)nodiscard
(44-44)src/clp_ffi_js/ir/LogEventWithFilterData.hpp (3)
nodiscard
(50-50)nodiscard
(52-52)nodiscard
(54-54)
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (3)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (2)
get_metadata
(66-68)get_metadata
(66-66)src/clp_ffi_js/ir/decoding_methods.cpp (2)
convert_metadata_to_js_object
(90-96)convert_metadata_to_js_object
(90-90)src/clp_ffi_js/ir/decoding_methods.hpp (1)
convert_metadata_to_js_object
(33-33)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (4)
src/clp_ffi_js/ir/decoding_methods.cpp (6)
rewind_reader_and_validate_encoding_type
(28-53)rewind_reader_and_validate_encoding_type
(28-28)deserialize_metadata
(55-88)deserialize_metadata
(55-55)convert_metadata_to_js_object
(90-96)convert_metadata_to_js_object
(90-90)src/clp_ffi_js/ir/decoding_methods.hpp (3)
rewind_reader_and_validate_encoding_type
(16-16)deserialize_metadata
(25-25)convert_metadata_to_js_object
(33-33)src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
zstd_decompressor
(47-48)src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (2)
get_metadata
(121-123)get_metadata
(121-121)
src/clp_ffi_js/ir/decoding_methods.cpp (1)
src/clp_ffi_js/json_utils.hpp (1)
dump_json_with_replace
(17-17)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (3)
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (1)
nodiscard
(58-60)src/clp_ffi_js/json_utils.hpp (1)
nodiscard
(17-19)src/clp_ffi_js/ir/StreamReaderDataContext.hpp (2)
nodiscard
(42-42)nodiscard
(44-44)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint (ubuntu-latest)
🔇 Additional comments (24)
CMakeLists.txt (1)
114-114
: LGTM!The addition of the new source file to the build configuration is correct and necessary for the metadata extraction functionality.
src/clp_ffi_js/ir/StreamReader.hpp (3)
15-15
: LGTM!The new includes for
ReaderInterface
andnlohmann/json
are necessary for the metadata functionality being added.Also applies to: 20-20
35-35
: LGTM!The declaration of
MetadataTsType
for JavaScript bindings is correctly placed with other output type declarations.
85-88
: LGTM!The pure virtual
get_metadata()
method properly establishes the interface contract for derived classes to provide metadata access.src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (3)
13-13
: LGTM!The JSON include is necessary for the new
m_metadata
member.
56-56
: LGTM!The
get_metadata()
override declaration correctly implements the interface from the base class.
91-91
: LGTM!The
m_metadata
member follows the naming convention suggested in past reviews and uses the appropriatenlohmann::json
type.src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (3)
24-24
: LGTM!The new includes for
decoding_methods.hpp
andjson_utils.hpp
are correctly added to support the metadata functionality.Also applies to: 29-29
121-123
: LGTM!The
get_metadata()
implementation correctly usesconvert_metadata_to_js_object
to convert the stored JSON metadata to a JavaScript-compatible object, following the same pattern asUnstructuredIrStreamReader
.
221-221
: LGTM!The constructor properly initialises
m_metadata
by extracting metadata from the deserializer, ensuring the metadata is available whenget_metadata()
is called.src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (1)
38-43
: LGTM! Well-structured metadata extraction.The approach of saving and restoring the stream position ensures the existing deserialization logic remains unaffected while extracting metadata.
src/clp_ffi_js/ir/decoding_methods.hpp (1)
1-36
: Well-designed header with clear function declarations.The header properly encapsulates decoding functionality with appropriate documentation and return type annotations.
src/clp_ffi_js/ir/decoding_methods.cpp (3)
28-53
: Robust implementation with proper error handling.The function correctly validates the encoding type and follows the coding guidelines for boolean comparisons.
55-88
: Well-implemented metadata deserialization with comprehensive error handling.The function properly handles both IR deserialization errors and JSON parsing exceptions with informative error messages.
90-96
: Clean conversion to JavaScript object.The function appropriately uses
dump_json_with_replace
for safe serialization and Emscripten's API for JavaScript interoperability.src/clp_ffi_js/ir/StreamReader.cpp (7)
25-25
: LGTM: Include statement properly added.The inclusion of
decoding_methods.hpp
aligns with the refactoring to extract metadata deserialization logic.
44-45
: LGTM: Metadata deserialization properly refactored.The extraction of metadata deserialization logic into
deserialize_metadata
improves code modularity and reusability. The function returns a JSON object that can be safely accessed for version extraction.
51-51
: Improved error message specificity.The updated error message "Failed to get stream's version" is more specific and accurately reflects the operation that failed compared to the previous generic metadata parsing message.
69-69
: LGTM: MetadataTsType registration enables metadata access in JavaScript.The registration of
MetadataTsType
as"Record<string, any>"
properly exposes metadata functionality to JavaScript consumers.
83-83
: LGTM: getMetadata method binding supports the new functionality.Adding the
getMetadata
method to the Emscripten class binding correctly exposes the metadata retrieval capability to JavaScript, fulfilling the PR objectives.
123-123
: LGTM: Simplified stream positioning.Making the seek position parameter explicit with
seek_from_begin(0)
improves code clarity and maintains the expected behaviour of rewinding to the beginning before creating the specific stream reader type.
119-119
:✅ Verification successful
Verify that rewind_reader_and_validate_encoding_type function is properly accessible.
According to the AI summary, the
rewind_reader_and_validate_encoding_type
function was moved to thedecoding_methods
module, but this call appears unchanged. Please ensure the function is properly imported or the call is updated to use the new location.
🏁 Script executed:
#!/bin/bash # Description: Verify the rewind_reader_and_validate_encoding_type function is properly defined and accessible # Expected: Function should be declared in decoding_methods.hpp or still available in current scope # Check if the function is declared in the decoding_methods header echo "Checking for function declaration in decoding_methods.hpp:" fd -t f -n "decoding_methods.hpp" -x cat {} \; | rg -A 3 "rewind_reader_and_validate_encoding_type" # Check for any other declarations of this function in the codebase echo "Checking for other declarations in the codebase:" rg -A 3 "rewind_reader_and_validate_encoding_type.*\(" --type cpp --type hpp # Check if there are any compilation errors related to this function echo "Checking for potential namespace or include issues:" rg "rewind_reader_and_validate_encoding_type" src/clp_ffi_js/ir/Length of output: 1315
#!/bin/bash echo "Includes in StreamReader.cpp:" rg "#include" src/clp_ffi_js/ir/StreamReader.cpp -n
🏁 Script executed:
#!/bin/bash echo "Checking includes in StreamReader.cpp for decoding_methods.hpp:" rg "#include.*decoding_methods.hpp" -n src/clp_ffi_js/ir/StreamReader.cpp echo "Snippet around call site in StreamReader.cpp:" rg -n -B2 -A2 "rewind_reader_and_validate_encoding_type" src/clp_ffi_js/ir/StreamReader.cppLength of output: 742
Function accessibility verified – no changes needed
The call torewind_reader_and_validate_encoding_type
at line 119 ofStreamReader.cpp
is valid: the function is declared insrc/clp_ffi_js/ir/decoding_methods.hpp
and that header is included.src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (2)
50-50
: Expose Metadata Retrieval
Theget_metadata()
override cleanly exposes stored metadata to JavaScript consumers.
85-85
: Metadata Member Ownership
Holdingnlohmann::json m_metadata
by value ensures safe ownership and avoids dangling references.
#include <clp/ir/LogEventDeserializer.hpp> | ||
#include <clp/ir/types.hpp> | ||
#include <emscripten/val.h> | ||
#include <json/single_include/nlohmann/json.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Include Path Verification
Ensure the JSON include path (json/single_include/nlohmann/json.hpp
) aligns with the repository’s conventions and matches other modules (e.g. nlohmann/json.hpp
).
🤖 Prompt for AI Agents
In src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp at line 11, verify that the
JSON include path matches the repository's standard convention. If other modules
use `nlohmann/json.hpp`, update the include directive to `#include
<nlohmann/json.hpp>` to maintain consistency across the codebase.
Sure. Let's create an issue and defer these changes to future PRs. |
@coderabbitai please help create an issue |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@junhaoliao I've created a GitHub issue to track the result-style error handling enhancement as discussed. The issue captures the context from your discussion with @LinZhihao-723 and includes the appropriate timing considerations you mentioned.
curious rabbit taking notes for future improvements 🏁 Script executed:
Length of output: 1246 @junhaoliao Perfect! I've successfully created the GitHub issue for adopting result-style error handling. You can find it here: Issue #89: Adopt result-style error handling for factory functions instead of exceptions The issue captures all the context from your discussion with @LinZhihao-723, including the benefits, challenges with Emscripten's Embind system, and the suggested timing for implementation. It's been assigned to you and includes backlinks to this PR and the relevant comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last few comments. Otherwise lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just utils.{cpp, hpp}
?
/** | ||
* @param zstd_decompressor A decompressor for an IR stream, where the read head of the stream | ||
* is just after the stream's encoding type. | ||
* @param zstd_decompressor A decompressor for an IR stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out of this PR's scope:
Similarly, I think we don't need rvalue reference for zstd_decompressor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai please also track this in #90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Let me check the current state of issue #90 and add this suggestion to track it properly.
@junhaoliao I've added the suggestion about removing the unnecessary rvalue reference for zstd_decompressor
to issue #90. The suggestion from @LinZhihao-723 is now tracked along with the other code improvements for future implementation.
🏁 Script executed:
#!/bin/bash
# Check the details of issue #90
gh issue view 90 --json title,body,comments
Length of output: 1251
🏁 Script executed:
#!/bin/bash
# Add a comment to issue #90 to track the rvalue reference suggestion
gh issue comment 90 --body "## Additional suggestion from PR #80
**Context**: In PR #80, @LinZhihao-723 noted that rvalue reference for \`zstd_decompressor\` parameter is not needed in \`StructuredIrStreamReader::create\`.
**Suggestion**: Remove unnecessary rvalue reference for \`zstd_decompressor\` parameter.
**Reference**: https://github.com/y-scope/clp-ffi-js/pull/80#discussion_r2134832676"
Length of output: 467
@junhaoliao I've successfully added the suggestion about removing the unnecessary rvalue reference for zstd_decompressor
to issue #90. The suggestion from @LinZhihao-723 is now tracked along with the other rvalue reference improvements for future implementation.
The comment was added here: #90 (comment)
🧬 Code Graph Analysis Results
Relevant snippets for src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
From src/clp_ffi_js/ir/StreamReaderDataContext.hpp
(lines 42-44)
[[nodiscard]] auto get_deserializer() -> Deserializer& { return m_deserializer; }
[[nodiscard]] auto get_reader() -> clp::ReaderInterface& { return *m_reader; }
These methods provide access to the deserializer and the underlying reader, which are likely used internally by StructuredIrStreamReader
to manage stream reading and deserialization.
From src/clp_ffi_js/ir/LogEventWithFilterData.hpp
(lines 50-54)
[[nodiscard]] auto get_log_event() const -> LogEvent const& { return m_log_event; }
[[nodiscard]] auto get_log_level() const -> LogLevel { return m_log_level; }
[[nodiscard]] auto get_timestamp() const -> clp::ir::epoch_time_ms_t { return m_timestamp; }
These accessors provide details about individual log events, including the event data, log level, and timestamp, which are relevant for filtering and decoding log events in StructuredIrStreamReader
.
From src/clp_ffi_js/ir/StreamReader.hpp
(lines 69-70, 107, 133-134, 155)
create(DataArrayTsType const& data_array, ReaderOptions const& reader_options)
-> std::unique_ptr<StreamReader>
filter_log_events(LogLevelFilterTsType const& log_level_filter)
decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType
find_nearest_log_event_by_timestamp(clp::ir::epoch_time_ms_t target_ts) -> NullableLogEventIdx
These declarations correspond to virtual or interface methods that StructuredIrStreamReader
overrides, defining the contract for creating readers, filtering log events, decoding ranges of events, and finding events by timestamp.
From src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
(lines 217-227)
StructuredIrStreamReader::StructuredIrStreamReader(
StreamReaderDataContext<StructuredIrDeserializer>&& stream_reader_data_context,
std::shared_ptr<StructuredLogEvents> deserialized_log_events
)
: m_metadata(stream_reader_data_context.get_deserializer().get_metadata()),
m_deserialized_log_events{std::move(deserialized_log_events)},
m_stream_reader_data_context{
std::make_unique<StreamReaderDataContext<StructuredIrDeserializer>>(
std::move(stream_reader_data_context)
)
} {}
This constructor implementation shows how the StructuredIrStreamReader
initializes its metadata, deserialized log events, and stream reader data context from the provided parameters.
From src/clp_ffi_js/ir/StructuredIrUnitHandler.hpp
(line 66)
[[nodiscard]] auto is_auto_generated() const -> bool { return m_is_auto_generated; }
This method indicates whether a unit handler instance is auto-generated, potentially relevant for handling or filtering structured IR units during deserialization.
From src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
(lines 47-48, 52-54, 60, 71-75)
create(std::unique_ptr<ZstdDecompressor>&& zstd_decompressor, clp::Array<char> data_array)
-> UnstructuredIrStreamReader
[[nodiscard]] auto get_ir_stream_type() const -> StreamType override {
return StreamType::Unstructured;
}
filter_log_events(LogLevelFilterTsType const& log_level_filter) override
decode_range(size_t begin_idx, size_t end_idx, bool use_filter) const
-> DecodedResultsTsType override
find_nearest_log_event_by_timestamp(clp::ir::epoch_time_ms_t target_ts)
-> NullableLogEventIdx override
These methods from the unstructured IR stream reader provide a useful comparison and context for the similarly named methods in StructuredIrStreamReader
, showing the interface and typical implementation patterns for stream readers.
These snippets collectively provide context on the interfaces, internal data handling, and related classes that are relevant to understanding and working with StructuredIrStreamReader.hpp
.
…e review Co-authored-by: Lin Zhihao <[email protected]>
Co-authored-by: Lin Zhihao <[email protected]>
…gestions from code review Co-authored-by: Lin Zhihao <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the PR title, how about:
feat: Add support for retrieving CLP IR stream-level metadata from IR stream readers (resolves #77).
Description
Support retrieving CLP IR metadata in Structured and Unstructured IR stream readers
Checklist
breaking change.
Validation performed
Test files: test-files.zip
test.mjs
test-irv1.clp.zst
and observed output:test-irv2.clp.zst
and observed output:Summary by CodeRabbit
Summary by CodeRabbit
New Features
Refactor
Chores