OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
DesignStreamWalker.h
Go to the documentation of this file.
1#pragma once
2
3// DesignStreamWalker — emits the ordered DesignChunk sequence of a design
4// (M6.2, getdesign-streaming-oom-plan.md) WITHOUT ever materializing the
5// monolithic protobuf Design tree.
6//
7// The emission order follows the settled M6.1 chunk design:
8// 1. DesignHeader (Design scalars + bounded FileArchive fields, no steps)
9// 2. one StepSkeleton per step (full StepDirectory minus layer features)
10// 3. FeatureBatch chunks per (step, layer) in FeaturesFile order
11// 4. NetBatch / PackageBatch / ComponentBatch / PartBatch (only when
12// include_normalized_lists — mirroring the monolithic flavour)
13// 5. ConnectivityBatch chunks (nets, packages, netMembers, components — the
14// same sections, entries, and order as Design::FillConnectivityMessage)
15// 6. NormalizedMapBatch chunks (the four ByName maps; normalized flavour)
16//
17// Each chunk's submessage is constructed fresh, handed to the sink, and
18// released; peak walker memory is one batch. Byte-identity with the
19// monolithic Design::to_protobuf output is by construction: every section is
20// produced by the same lib-side serialization code (FileArchive/
21// StepDirectory skeletons, per-element to_protobuf, Design::AddConnectivity*
22// single-entry emitters), and map entries are emitted in the same sorted
23// std::map iteration order the monolithic build inserts them in.
24//
25// DesignStreamAssembler re-applies the chunks to a Design message (the wire-
26// equivalence gate and the reference client reassembly recipe).
27
28#include <cstdint>
29#include <functional>
30#include <set>
31#include <string>
32
33// The lib's generated pb headers use ODBDESIGN_EXPORT without including
34// odbdesign_export.h (OdbDesignLib/CMakeLists.txt defines it empty on
35// non-Windows only). Any TU whose first pb include is this header must
36// have the macro defined first — on Windows it is __declspec(dllimport)
37// — exactly the OdbDesignServiceImpl.h pattern.
38#include "odbdesign_export.h"
39
40#include <design.pb.h>
41#include <service.pb.h>
42
43#include "ProductModel/Design.h"
44
45namespace OdbDesignServer
46{
47 namespace Services
48 {
49 // Batch sizes bound peak per-chunk memory; they do NOT affect the
50 // reassembled bytes (only chunk granularity).
52 {
53 std::size_t featureBatchSize = 1000; // FeatureRecords per FeatureBatch
54 std::size_t entryBatchSize = 1000; // nets/packages/components/parts + connectivity entries per batch
55 std::size_t mapBatchSize = 500; // ByName map entries per NormalizedMapBatch
56 };
57
59 {
60 public:
61 // Receives each emitted chunk; returns false to abort the walk
62 // (e.g. gRPC client disconnected).
63 using ChunkSink = std::function<bool(const Odb::Grpc::DesignChunk&)>;
64
65 struct Stats
66 {
67 std::uint64_t chunks = 0;
68 std::uint64_t wireBytes = 0; // sum of serialized chunk sizes
69 };
70
71 // Walks the product model and emits the ordered chunk sequence.
72 // Returns true when the walk completed; false when the sink
73 // aborted it partway. `stats` (optional) receives counters.
74 static bool Walk(const Odb::Lib::ProductModel::Design& design,
75 bool includeNormalizedLists,
76 const DesignStreamOptions& options,
77 const ChunkSink& sink,
78 Stats* stats = nullptr);
79 };
80
81 // Reference reassembly: applies one chunk to the Design message being
82 // rebuilt. Chunks must arrive in walk order. Returns false on a
83 // malformed sequence (e.g. a FeatureBatch addressing a step/layer no
84 // StepSkeleton delivered, or a chunk arriving before the header).
85 bool ApplyDesignChunk(Odb::Lib::Protobuf::ProductModel::Design& design,
86 const Odb::Grpc::DesignChunk& chunk);
87 }
88}
static bool Walk(const Odb::Lib::ProductModel::Design &design, bool includeNormalizedLists, const DesignStreamOptions &options, const ChunkSink &sink, Stats *stats=nullptr)
std::function< bool(const Odb::Grpc::DesignChunk &)> ChunkSink
bool ApplyDesignChunk(Odb::Lib::Protobuf::ProductModel::Design &design, const Odb::Grpc::DesignChunk &chunk)