Added functionality to import/export Graph from/to Binary File#554
Added functionality to import/export Graph from/to Binary File#554ZigRazor merged 1 commit intoZigRazor:masterfrom
Conversation
| try { | ||
| // Read and verify header | ||
| uint32_t magic; | ||
| in.read(reinterpret_cast<char *>(&magic), sizeof(magic)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| } | ||
|
|
||
| uint32_t version; | ||
| in.read(reinterpret_cast<char *>(&version), sizeof(version)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| } | ||
|
|
||
| uint64_t numNodes, numEdges, flags; | ||
| in.read(reinterpret_cast<char *>(&numNodes), sizeof(numNodes)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
|
|
||
| uint64_t numNodes, numEdges, flags; | ||
| in.read(reinterpret_cast<char *>(&numNodes), sizeof(numNodes)); | ||
| in.read(reinterpret_cast<char *>(&numEdges), sizeof(numEdges)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| uint64_t numNodes, numEdges, flags; | ||
| in.read(reinterpret_cast<char *>(&numNodes), sizeof(numNodes)); | ||
| in.read(reinterpret_cast<char *>(&numEdges), sizeof(numEdges)); | ||
| in.read(reinterpret_cast<char *>(&flags), sizeof(flags)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| } | ||
| } else { | ||
| uint32_t dataSize; | ||
| in.read(reinterpret_cast<char *>(&dataSize), sizeof(dataSize)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| std::string node2Id = readBinaryString(in); | ||
|
|
||
| uint8_t edgeFlags; | ||
| in.read(reinterpret_cast<char *>(&edgeFlags), sizeof(edgeFlags)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| double weight = 0.0; | ||
| if (hasEdgeWeights && isWeighted) { | ||
| if (readEdgeWeights) { | ||
| in.read(reinterpret_cast<char *>(&weight), sizeof(weight)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| template <typename T> | ||
| std::string Graph<T>::readBinaryString(std::ifstream &in) const { | ||
| uint32_t len; | ||
| in.read(reinterpret_cast<char *>(&len), sizeof(len)); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
| uint32_t len; | ||
| in.read(reinterpret_cast<char *>(&len), sizeof(len)); | ||
| std::string str(len, '\0'); | ||
| in.read(&str[0], len); |
Check failure
Code scanning / Eslint-9 (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Error
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #554 +/- ##
==========================================
- Coverage 97.06% 97.02% -0.04%
==========================================
Files 97 98 +1
Lines 11585 11968 +383
Branches 768 799 +31
==========================================
+ Hits 11245 11612 +367
- Misses 340 356 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR adds binary serialization and deserialization support for Graph objects (issue #5) to efficiently import/export large graphs to and from binary files, while maintaining structural and attribute consistency.
Changes made
Graph_decl.h– Added public writeToBinaryFile() and readFromBinaryFile() methods with private helpers. Defined binary format constants (magic number, version, flags) and is_binary_serializable type trait.InputOperation_impl.hpp– Implemented binary deserialization with header validation, node/edge reconstruction, and support for optional features and weights.OutputOperation_impl.hpp– Implemented binary serialization writing header metadata followed by node data and edge data with optional features/weights.BinaryIOTest.cpp– Added comprehensive test suite covering various graph types, node features, edge weights, empty graphs, large graphs, error cases, and round-trip serialization.Implementation details
Binary File Format:
Key Features: