Skip to main content

Browse Automatic Pagination (High-Level Encapsulation)

C# provides automatic BrowseNext iteration with the +BrowseWithPaging operator; there is no C SDK built-in function for this API, so you need toEncapsulate the business logic yourself. This page provides a recommended template.

Prerequisite Reading
  • Single-layer Browse Please see Browse.
  • Continue to the next page API Please see BrowseNext.

Wrap Browse + 循环 BrowseNext into a helper function so that the business logic can directly access a complete (NodeId, BrowseName, NodeClass) list:

/* browse_all.h */
#include <opcua/opcua.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
char node_id[128];
char browse_name[128];
int32_t node_class;
} BrowsedRef;

typedef struct {
BrowsedRef* items;
uint32_t count;
uint32_t capacity;
} BrowsedList;

void BrowsedList_Init(BrowsedList* l) {
l->items = NULL; l->count = 0; l->capacity = 0;
}

void BrowsedList_Free(BrowsedList* l) {
free(l->items); l->items = NULL; l->count = 0; l->capacity = 0;
}

static int append_one(BrowsedList* l, const DarraUa_ReferenceDescription* rd)
{
if (l->count == l->capacity) {
uint32_t cap = l->capacity ? l->capacity * 2 : 16;
BrowsedRef* p = (BrowsedRef*)realloc(l->items, cap * sizeof(BrowsedRef));
if (!p) return 0;
l->items = p; l->capacity = cap;
}
BrowsedRef* item = &l->items[l->count++];
DarraUa_Ref_GetNodeIdString(rd, item->node_id, (int32_t)sizeof(item->node_id));
const char* bn = DarraUa_Ref_GetBrowseName(rd);
snprintf(item->browse_name, sizeof(item->browse_name), "%s", bn ? bn : "");
item->node_class = DarraUa_Ref_GetNodeClass(rd);
return 1;
}

DarraUa_Status BrowseAll(DarraUa_SessionHandle h,
const char* node_id,
DarraUa_NodeClass filter,
BrowsedList* out)
{
BrowsedList_Init(out);

DarraUa_BrowseResult* page = NULL;
DarraUa_Status st = DarraUa_Session_BrowseNode(h, node_id, filter, &page);
if (!UA_STATUS_IS_GOOD(st) || !page) return st;

while (page) {
uint32_t n = DarraUa_BrowseResult_GetCount(page);
for (uint32_t i = 0; i < n; ++i) {
append_one(out, DarraUa_BrowseResult_GetReference(page, i));
}

int32_t cp_len = 0;
const uint8_t* cp = DarraUa_BrowseResult_GetContinuationPoint(page, &cp_len);
if (!cp || cp_len <= 0) {
DarraUa_BrowseResult_Delete(page);
break;
}
uint8_t cp_copy[256];
if (cp_len > (int32_t)sizeof(cp_copy)) {
DarraUa_BrowseResult_Delete(page);
break;
}
memcpy(cp_copy, cp, (size_t)cp_len);
DarraUa_BrowseResult_Delete(page);
page = NULL;
DarraUa_Session_BrowseNext(h, 0, cp_copy, cp_len, &page);
}

return UA_STATUS_GOOD;
}

Usage​

BrowsedList list;
DarraUa_Status st = BrowseAll(h, "ns=2;s=BigFolder",
UA_NODE_CLASS_VARIABLE, &list);

if (UA_STATUS_IS_GOOD(st)) {
printf("Got %u children\n", list.count);
for (uint32_t i = 0; i < list.count; ++i) {
printf(" %s -> %s\n", list.items[i].browse_name,
list.items[i].node_id);
}
}
BrowsedList_Free(&list);

When to Use BrowseNode Directly vs. Wrapped BrowseAll​

ScenarioAPI
It is known that the number of sub-entries does not exceed the single-page limit (1000 citations).Use DarraUa_Session_BrowseNode directly
I'm not sure how many children there are, so just to be safe...BrowseAll Packaging
The number of entries may exceed the single-page limitBrowseAll Required
Browse Multiple Nodes at OnceDarraUa_Session_BrowseNodes (Each slot returns the same result ContinuationPoint; you must browse through them one by one)

ContinuationPoint Will it expire?​

The timing for recycling pagination tokens is determined by the server; the client cannot query this information. In practice, complete the entire pagination cycle in one go without performing other tasks in between; if the cycle is interrupted and pagination cannot continue, start over by retrieving a new page and continuing Browse from there.

Next Step​