Skip to content

Commit

Permalink
refactor(core): Use NamespaceMapping for the JSON decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Dec 7, 2024
1 parent 0d8dfca commit 194bf98
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
8 changes: 6 additions & 2 deletions include/open62541/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1420,12 +1420,16 @@ UA_encodeJson(const void *src, const UA_DataType *type, UA_ByteString *outBuf,
* Zero-out the entire structure initially to ensure code-compatibility when
* more fields are added in a later release. */
typedef struct {
const UA_String *namespaces;
size_t namespacesSize;
/* Mapping of namespace indices in NodeIds and of NamespaceUris in
* ExpandedNodeIds. */
UA_NamespaceMapping *namespaceMapping;

const UA_String *serverUris;
size_t serverUrisSize;

const UA_DataTypeArray *customTypes; /* Begin of a linked list with custom
* datatype definitions */

size_t *decodedLength; /* If non-NULL, the length of the decoded input is
* stored to the pointer. When this is set, decoding
* succeeds also if there is more content after the
Expand Down
3 changes: 1 addition & 2 deletions src/pubsub/ua_pubsub_networkmessage_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ UA_NetworkMessage_decodeJson(const UA_ByteString *src,
memset(&ctx, 0, sizeof(ParseCtx));
ctx.tokens = tokens;
if(options) {
ctx.namespacesSize = options->namespacesSize;
ctx.namespaces = options->namespaces;
ctx.namespaceMapping = options->namespaceMapping;
ctx.serverUrisSize = options->serverUrisSize;
ctx.serverUris = options->serverUris;
ctx.customTypes = options->customTypes;
Expand Down
13 changes: 6 additions & 7 deletions src/ua_types_encoding_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1934,12 +1934,12 @@ decodeExpandedNodeIdNamespace(ParseCtx *ctx, void *dst, const UA_DataType *type)
return ret;

/* Replace with the index if the URI is found. Otherwise keep the string. */
for(size_t i = 0; i < ctx->namespacesSize; i++) {
if(UA_String_equal(&en->namespaceUri, &ctx->namespaces[i])) {
if(ctx->namespaceMapping) {
UA_StatusCode mapRes =
UA_NamespaceMapping_uri2Index(ctx->namespaceMapping, en->namespaceUri,
&en->nodeId.namespaceIndex);
if(mapRes == UA_STATUSCODE_GOOD)
UA_String_clear(&en->namespaceUri);
en->nodeId.namespaceIndex = (UA_UInt16)i;
break;
}
}

return UA_STATUSCODE_GOOD;
Expand Down Expand Up @@ -2884,8 +2884,7 @@ UA_decodeJson(const UA_ByteString *src, void *dst, const UA_DataType *type,
ctx.tokens = tokens;

if(options) {
ctx.namespaces = options->namespaces;
ctx.namespacesSize = options->namespacesSize;
ctx.namespaceMapping = options->namespaceMapping;
ctx.serverUris = options->serverUris;
ctx.serverUrisSize = options->serverUrisSize;
ctx.customTypes = options->customTypes;
Expand Down
3 changes: 1 addition & 2 deletions src/ua_types_encoding_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ typedef struct {
size_t index;
UA_Byte depth;

size_t namespacesSize;
const UA_String *namespaces;
UA_NamespaceMapping *namespaceMapping;

size_t serverUrisSize;
const UA_String *serverUris;
Expand Down

0 comments on commit 194bf98

Please sign in to comment.