-
Notifications
You must be signed in to change notification settings - Fork 190
Add load && save method to ImgFrame #1852
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
base: develop
Are you sure you want to change the base?
Changes from all commits
d40a037
6b1a524
e2470a7
f035e5e
e9e3b17
59b6b6f
8919b57
dac41e8
c2f5413
9760b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <filesystem> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -16,6 +17,20 @@ class ProtoSerializable { | |
| virtual ~ProtoSerializable(); | ||
|
|
||
| #ifdef DEPTHAI_ENABLE_PROTOBUF | ||
| /** | ||
| * @brief Serialize this object and write it to disk | ||
| * @param path Output path. If it has no extension, the final on-disk filename is resolved to `<path>.dai`. | ||
| * @param metadataOnly If true, serialize only metadata and omit payload data where supported by the concrete type. | ||
| */ | ||
| void save(const std::filesystem::path& path, bool metadataOnly = false) const; | ||
|
|
||
| /** | ||
| * @brief Load this object from a serialized protobuf file on disk | ||
| * @param path Input path. If it has no extension, the file is resolved as `<path>.dai`. | ||
| * @param metadataOnly If true, load only metadata and omit payload data where supported by the concrete type. | ||
| */ | ||
| void load(const std::filesystem::path& path, bool metadataOnly = false); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Locate the actual deserialization/message-loading helper referenced by deserializeProtoMessage overrides
fd -i 'ProtoFileIO'
rg -n -A15 'loadProtoMessageFromBytes' --type=cppRepository: luxonis/depthai-core Length of output: 158 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Map the relevant header and locate callers/overrides.
git ls-files 'include/depthai/utility/ProtoSerializable.hpp' 'src/**' 'include/**' | sed -n '1,200p'
echo
ast-grep outline include/depthai/utility/ProtoSerializable.hpp --view expanded || true
echo
rg -n --hidden --glob '!**/.git/**' 'deserializeProtoMessage|metadataOnly|load\(const std::filesystem::path& path, bool metadataOnly = false\)' include srcRepository: luxonis/depthai-core Length of output: 21097 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,120p' src/utility/ProtoSerializable.cpp
echo
sed -n '360,420p' src/pipeline/datatype/ImgFrame.cpp
echo
sed -n '150,190p' src/pipeline/datatype/EncodedFrame.cpp
echo
sed -n '240,270p' src/pipeline/datatype/PointCloudData.cpp
echo
sed -n '1,90p' src/pipeline/datatype/RGBDData.cpp
echo
sed -n '1,60p' src/pipeline/datatype/IMUData.cppRepository: luxonis/depthai-core Length of output: 8552 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1050,1365p' src/utility/ProtoSerialize.cppRepository: luxonis/depthai-core Length of output: 13503 Clear payload state on metadata-only reloads
🤖 Prompt for AI Agents |
||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /** | ||
| * @brief Serialize the protobuf message of this object | ||
| * @return serialized protobuf message | ||
|
|
@@ -28,6 +43,9 @@ class ProtoSerializable { | |
| */ | ||
| virtual SchemaPair serializeSchema() const = 0; | ||
|
|
||
| protected: | ||
| virtual void deserializeProtoMessage(const std::vector<std::uint8_t>& bytes, bool metadataOnly); | ||
|
|
||
| #else | ||
| // Helper struct for compile-time check | ||
| template <typename... T> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #include "depthai/pipeline/datatype/EncodedFrame.hpp" | ||
| #ifdef DEPTHAI_ENABLE_PROTOBUF | ||
| #include "depthai/schemas/EncodedFrame.pb.h" | ||
| #include "utility/ProtoFileIO.hpp" | ||
| #include "utility/ProtoSerialize.hpp" | ||
| #endif | ||
|
|
||
|
|
@@ -161,6 +162,10 @@ ImgFrame EncodedFrame::getImgFrameMeta() const { | |
| } | ||
|
|
||
| #ifdef DEPTHAI_ENABLE_PROTOBUF | ||
| void EncodedFrame::deserializeProtoMessage(const std::vector<std::uint8_t>& bytes, bool metadataOnly) { | ||
| utility::loadProtoMessageFromBytes(*this, bytes, metadataOnly); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| ProtoSerializable::SchemaPair EncodedFrame::serializeSchema() const { | ||
| return utility::serializeSchema(utility::getProtoMessage(this)); | ||
| } | ||
|
|
||
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.
Use a container-agnostic emptiness check for payload.
The assertion currently depends on a
.sizeattribute, which may not exist for allgetData()Python return shapes. Uselen(...) == 0to avoid false test failures.✅ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents