BrowseWithPaging
Browse 只返回 References 列表, 丢弃 ContinuationPoint, 适合"已知小节点"场景. 大节点 (子节点 100+) 用 BrowseWithPaging 显式拿到 BrowsePage.
前置阅读
- 续翻分页用 BrowseNext.
签名
BrowsePage BrowseWithPaging(
std::string const& node_id,
NodeClass filter = NodeClass::Unspecified);
用法
auto page = s.BrowseWithPaging("ns=2;s=BigFolder");
std::cout << "Got " << page.references.size()
<< " children, more = " << !page.continuation_point.empty() << "\n";
if (!page.continuation_point.empty()) {
auto next = s.BrowseNext(page.continuation_point);
std::cout << "Next page: " << next.references.size() << " more children\n";
}
何时用 Browse vs BrowseWithPaging
| 场景 | API |
|---|---|
| 已知节点子数 ≤ 50, 不关心分页 | Browse(...) |
| 不确定子数, 安全起见 | BrowseWithPaging(...) + 循环 BrowseNext |
| 100+ 子节点的大节点 | BrowseWithPaging(...) 必选 |
| 一次 Browse 多个节点 | BrowseMany(...) (注意当前 BrowseMany 不返回 ContinuationPoint) |
完整模板
std::vector<Reference> BrowseAll(
Session& s,
std::string const& node_id,
NodeClass filter = NodeClass::Unspecified)
{
std::vector<Reference> all;
auto page = s.BrowseWithPaging(node_id, filter);
all.insert(all.end(), page.references.begin(), page.references.end());
while (!page.continuation_point.empty()) {
page = s.BrowseNext(page.continuation_point);
all.insert(all.end(), page.references.begin(), page.references.end());
}
return all;
}