Skip to content

feat: Support retrieving CLP IR metadata in Structured and Unstructured 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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented May 26, 2025

Description

Support retrieving CLP IR metadata in Structured and Unstructured IR stream readers

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Test files: test-files.zip

  1. Created below test driver code test.mjs
    import ModuleInit from "./cmake-build-debug/ClpFfiJs-node.js"
    import fs from "node:fs"
    
    const main = async () => {
        const file = fs.readFileSync("./test-irv1.clp.zst")
        // const file = fs.readFileSync("./test-irv2.clp.zst")
        // const file = fs.readFileSync("./test.clp.zst")
    
        console.time("perf")
        const Module = await ModuleInit()
        console.log(Module.MERGED_KV_PAIRS_AUTO_GENERATED_KEY);
        console.log(Module.MERGED_KV_PAIRS_USER_GENERATED_KEY);
        try {
            const decoder = new Module.ClpStreamReader(
                new Uint8Array(file),
                {timestampKey: {isAutoGenerated: true, parts: ["timestamp", "unix_millisecs"]},
                    logLevelKey: {parts: ["level", "name"], isAutoGenerated: true}})
            console.log(decoder.getMetadata())
            console.log("type:", decoder.getIrStreamType() === Module.IrStreamType.STRUCTURED,
                decoder.getIrStreamType() === Module.IrStreamType.UNSTRUCTURED)
            const numEvents = decoder.deserializeStream()
            console.log(numEvents)
            const results = decoder.decodeRange(0, numEvents, false)
            console.log(results)
        } catch (e) {
            console.error("Exception caught:", e.stack)
        }
        console.timeEnd("perf")
    }
    
    void main()
    
  2. Ran for test-irv1.clp.zst and observed output:
    ...
    [2025-05-25 22:41:24.230] [info] [StreamReader.cpp:56] IR version is v0.0.0
    [
      {
        REFERENCE_TIMESTAMP: '1427088366258',
        TIMESTAMP_PATTERN: 'yyyy-MM-dd HH:mm:ss,SSS',
        TZ_ID: 'America/Toronto',
        VERSION: 'v0.0.0'
      }
    ]
    ...
    
  3. Ran for test-irv2.clp.zst and observed output:
    ...
    [2025-05-25 22:41:59.112] [info] [StreamReader.cpp:56] IR version is 0.1.0
    {
      VARIABLES_SCHEMA_ID: 'com.yscope.clp.VariablesSchemaV2',
      VARIABLE_ENCODING_METHODS_ID: 'com.yscope.clp.VariableEncodingMethodsV1',
      VERSION: '0.1.0'
    }
    ...
    
  4. No decoding error was observed in (2.) and (3.).

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added the ability to extract and access metadata from IR streams, now available through a new getter method in both structured and unstructured stream readers.
  • Refactor

    • Improved and modularized the handling of metadata deserialization and version retrieval for IR streams.
    • Enhanced integration with JavaScript by expanding type support and bindings.
    • Simplified decompressor position management during stream reader creation.
  • Chores

    • Introduced utility for safe JSON serialization, replacing invalid UTF-8 sequences automatically.

@junhaoliao junhaoliao requested a review from a team as a code owner May 26, 2025 02:38
Copy link

coderabbitai bot commented May 26, 2025

"""

Walkthrough

The changes refactor and modularize IR stream metadata handling in the CLP FFI JS bindings. Metadata deserialization is extracted into standalone functions, and Emscripten bindings are expanded to expose metadata to JavaScript. Both structured and unstructured IR stream readers are updated to store and provide parsed metadata, with new methods and type conversions for JavaScript interoperability.

Changes

File(s) Change Summary
src/clp_ffi_js/ir/StreamReader.cpp, src/clp_ffi_js/ir/StreamReader.hpp Refactored metadata deserialization into new functions, rewrote version retrieval, updated Emscripten bindings, added get_metadata().
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp, src/clp_ffi_js/ir/StructuredIrStreamReader.hpp Added storage for metadata JSON, implemented get_metadata() to expose metadata, removed local JSON helper.
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp, src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp Updated to extract, store, and expose metadata JSON; modified constructor and added get_metadata().
src/clp_ffi_js/json_utils.hpp Introduced new header with dump_json_with_replace() utility for safe JSON serialization.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant Emscripten
    participant StreamReader
    participant ReaderInterface

    JS->>Emscripten: Create StreamReader from data
    Emscripten->>StreamReader: create(data_array, options)
    StreamReader->>ReaderInterface: deserialize_metadata()
    ReaderInterface-->>StreamReader: metadata JSON
    StreamReader->>StreamReader: parse_metadata_to_ts_type(metadata JSON)
    StreamReader-->>Emscripten: StreamReader instance with metadata
    Emscripten-->>JS: StreamReader object (with get_metadata())
    JS->>StreamReader: get_metadata()
    StreamReader-->>JS: MetadataTsType
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • davemarco
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc0326c and 980ff35.

📒 Files selected for processing (6)
  • 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/StructuredIrStreamReader.hpp (4 hunks)
  • src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (4 hunks)
  • src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (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}: - Prefer false == <expression> rather than !<expression>.

  • src/clp_ffi_js/ir/StructuredIrStreamReader.hpp
  • src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp
  • src/clp_ffi_js/ir/StructuredIrStreamReader.cpp
  • src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp
  • src/clp_ffi_js/ir/StreamReader.hpp
  • src/clp_ffi_js/ir/StreamReader.cpp
🧠 Learnings (4)
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/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>>`.
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 (3)
src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (3)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (1)
  • nodiscard (53-55)
src/clp_ffi_js/json_utils.hpp (1)
  • nodiscard (16-18)
src/clp_ffi_js/ir/StreamReaderDataContext.hpp (2)
  • nodiscard (42-42)
  • nodiscard (44-44)
src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (3)
src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (2)
  • get_metadata (65-67)
  • get_metadata (65-65)
src/clp_ffi_js/ir/StreamReader.cpp (2)
  • parse_metadata_to_js_object (166-172)
  • parse_metadata_to_js_object (166-166)
src/clp_ffi_js/ir/StreamReader.hpp (1)
  • parse_metadata_to_js_object (75-75)
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 (16-18)
src/clp_ffi_js/ir/StreamReaderDataContext.hpp (2)
  • nodiscard (42-42)
  • nodiscard (44-44)
🔇 Additional comments (27)
src/clp_ffi_js/ir/StreamReader.hpp (4)

15-15: LGTM: Appropriate includes for metadata functionality.

The added includes for clp/ReaderInterface.hpp and nlohmann/json.hpp are necessary for the new metadata handling functionality.

Also applies to: 20-20


35-35: LGTM: JavaScript type declaration for metadata.

The MetadataTsType declaration properly exposes metadata to the JavaScript interface through Emscripten bindings.


52-75: LGTM: Well-designed metadata handling functions.

The three free functions provide a clean separation of concerns:

  • rewind_reader_and_validate_encoding_type: Stream preparation
  • deserialize_metadata: Core metadata extraction
  • parse_metadata_to_js_object: JavaScript interoperability

The documentation is clear and exception specifications are appropriate.


111-114: LGTM: Pure virtual interface for metadata access.

Adding get_metadata() as a pure virtual method ensures consistent metadata access across all IR stream reader implementations while maintaining polymorphic behaviour.

src/clp_ffi_js/ir/StructuredIrStreamReader.hpp (4)

13-13: LGTM: Required include for JSON metadata storage.

The nlohmann/json.hpp include is necessary for the new m_metadata_json member variable.


32-32: LGTM: Simplified constructor documentation.

Removing the specific detail about read head position from the constructor comment is appropriate as it's an implementation detail.


56-56: LGTM: Proper override of base class method.

The get_metadata() method correctly overrides the pure virtual method from StreamReader with the appropriate return type and override specifier.


91-91: LGTM: Appropriate metadata storage.

The m_metadata_json member variable properly stores the deserialized metadata as a nlohmann::json object for later conversion to JavaScript.

src/clp_ffi_js/ir/StructuredIrStreamReader.cpp (3)

28-28: LGTM: Centralized JSON utility usage.

Including json_utils.hpp instead of using a local dump_json_with_replace function promotes code reuse and maintains consistency across the codebase.


120-122: LGTM: Correct metadata method implementation.

The get_metadata() implementation correctly uses parse_metadata_to_js_object to convert the stored JSON metadata to a JavaScript-compatible object, following the established pattern.


220-220: LGTM: Proper metadata initialization.

The constructor correctly initializes m_metadata_json by extracting metadata from the deserializer via get_metadata(), ensuring the metadata is captured at construction time.

src/clp_ffi_js/ir/UnstructuredIrStreamReader.cpp (5)

20-20: LGTM: Required include for metadata handling.

The nlohmann/json.hpp include is necessary for the metadata JSON parameter and member variable.


37-42: LGTM: Correct metadata extraction with position management.

The metadata extraction logic properly:

  1. Rewinds and validates the stream encoding
  2. Captures the current position before metadata deserialization
  3. Deserializes metadata using the new free function
  4. Resets the decompressor position to allow normal deserializer creation

This ensures metadata is extracted without affecting the main deserialization process.


62-62: LGTM: Updated constructor call with metadata.

The constructor call correctly passes the extracted metadata JSON using move semantics for efficient transfer.


65-67: LGTM: Consistent metadata method implementation.

The get_metadata() implementation follows the same pattern as the structured reader, using parse_metadata_to_js_object to convert stored JSON to JavaScript format.


174-182: LGTM: Proper constructor parameter and initialization.

The constructor correctly:

  1. Accepts metadata JSON by rvalue reference for efficient move
  2. Initializes both the stream reader data context and metadata JSON members
  3. Uses move semantics appropriately for performance

The member initialization order is appropriate.

src/clp_ffi_js/ir/UnstructuredIrStreamReader.hpp (5)

11-11: LGTM!

The inclusion of the JSON library is appropriate for handling metadata.


41-41: Documentation looks good.

The simplified parameter documentation is clear and concise.


51-52: Method declaration is well-structured.

The get_metadata() method properly overrides the base class interface with appropriate const-correctness and [[nodiscard]] attribute.


81-82: Constructor parameters properly support move semantics.

The addition of nlohmann::json&& metadata_json parameter correctly uses rvalue reference for efficient ownership transfer.


86-86: Member variable addition is appropriate.

The m_metadata_json member properly stores the metadata for later retrieval through get_metadata().

src/clp_ffi_js/ir/StreamReader.cpp (6)

27-27: Include statement is appropriate.

The json_utils.hpp header is needed for the dump_json_with_replace function used in metadata parsing.


42-58: Well-structured refactor of version retrieval.

The function properly:

  • Uses the centralized deserialize_metadata function
  • Handles JSON exceptions appropriately
  • Returns std::string instead of std::string_view to ensure data validity
  • Provides informative error messages

60-102: Comprehensive Emscripten bindings implementation.

The bindings properly:

  • Register all necessary TypeScript types for inputs and outputs
  • Expose the new getMetadata method alongside existing functionality
  • Use appropriate return value policies
  • Map enum values correctly for JavaScript interop

132-164: Robust metadata deserialization implementation.

The function properly:

  • Handles IR stream deserialization errors with specific error codes
  • Safely converts metadata bytes using size_checked_pointer_cast
  • Catches JSON parsing exceptions with informative error messages
  • Returns the parsed metadata as a JSON object for further processing

166-172: Effective JSON to JavaScript object conversion.

The function properly converts C++ JSON to JavaScript object using Emscripten's interop capabilities and the dump_json_with_replace utility for safe serialization.


193-193: Simplified decompressor position management.

The single rewind approach is cleaner than the previous save/restore logic while achieving the same result.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

);

// JS types used as outputs
emscripten::register_type<clp_ffi_js::ir::MetadataTsType>("Record<string, any>");
Copy link
Member Author

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)
Copy link
Member Author

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);
Copy link
Member Author

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.

@@ -36,15 +37,6 @@ constexpr std::string_view cReaderOptionsTimestampKey{"timestampKey"};
constexpr std::string_view cMergedKvPairsAutoGeneratedKey{"auto-generated"};
constexpr std::string_view cMergedKvPairsUserGeneratedKey{"user-generated"};

/**
Copy link
Member Author

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

@junhaoliao junhaoliao requested a review from LinZhihao-723 May 26, 2025 03:23
Copy link
Member

@LinZhihao-723 LinZhihao-723 left a 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.


namespace clp_ffi_js {
/**
* @see nlohmann::basic_json::dump
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @see nlohmann::basic_json::dump
* @see nlohmann::basic_json::dump

Need an empty line to break the description and @see section, otherwise they will be rendered as a whole.

* @param json
* @return Serialized JSON.
*/
[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json) -> std::string {
Copy link
Member

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?

* @param json
* @return Serialized JSON.
*/
[[nodiscard]] inline auto dump_json_with_replace(nlohmann::json const& json) -> std::string {
Copy link
Member

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.

Comment on lines +11 to +12
* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than
* throwing an exception.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than
* throwing an exception.
* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than throwing
* an exception.

* @throws ClpFfiJsException if the preamble couldn't be deserialized.
* @return The IR stream's metadata as a JSON object.
*/
auto deserialize_metadata(clp::ReaderInterface& reader) -> nlohmann::json;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto deserialize_metadata(clp::ReaderInterface& reader) -> nlohmann::json;
[[nodiscard]] auto deserialize_metadata(clp::ReaderInterface& reader) -> nlohmann::json;

* Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than
* throwing an exception.
* @param json
* @return Serialized JSON.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return Serialized JSON.
* @return The JSON object serialized as a string.

);

// Variables
nlohmann::json m_metadata_json;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -76,10 +78,12 @@ class UnstructuredIrStreamReader : public StreamReader {
private:
// Constructor
explicit UnstructuredIrStreamReader(
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context,
nlohmann::json&& metadata_json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nlohmann::json&& metadata_json
nlohmann::json metadata_json

Do we need an rvalue reference?

@@ -53,7 +59,11 @@ auto UnstructuredIrStreamReader::create(
std::move(zstd_decompressor),
std::move(result.value())
);
return UnstructuredIrStreamReader(std::move(data_context));
return UnstructuredIrStreamReader(std::move(data_context), std::move(metadata_json));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return UnstructuredIrStreamReader(std::move(data_context), std::move(metadata_json));
return UnstructuredIrStreamReader{std::move(data_context), std::move(metadata_json)};

Nit

@@ -76,10 +78,12 @@ class UnstructuredIrStreamReader : public StreamReader {
private:
// Constructor
explicit UnstructuredIrStreamReader(
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context
StreamReaderDataContext<UnstructuredIrDeserializer>&& stream_reader_data_context,
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants