From 84028764676c90271c62418dc2e485e2db73646d Mon Sep 17 00:00:00 2001 From: Julius Pfrommer Date: Sun, 2 Mar 2025 22:10:54 +0100 Subject: [PATCH] refactor(core): Remove pretty-printing from XML encoding --- include/open62541/types.h | 2 -- src/ua_types_encoding_xml.c | 40 ++++++------------------------------- src/ua_types_encoding_xml.h | 4 ---- 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/include/open62541/types.h b/include/open62541/types.h index cdde04819..6ad3af675 100644 --- a/include/open62541/types.h +++ b/include/open62541/types.h @@ -1565,8 +1565,6 @@ typedef struct { UA_NamespaceMapping *namespaceMapping; const UA_String *serverUris; size_t serverUrisSize; - - UA_Boolean prettyPrint; /* Add newlines and spaces for legibility */ } UA_EncodeXmlOptions; /* Returns the number of bytes the value src takes in xml encoding. Returns diff --git a/src/ua_types_encoding_xml.c b/src/ua_types_encoding_xml.c index 23ce381c3..de92c5a20 100644 --- a/src/ua_types_encoding_xml.c +++ b/src/ua_types_encoding_xml.c @@ -215,16 +215,9 @@ writeXmlElemNameBegin(CtxXml *ctx, const char* name) { if(ctx->depth >= UA_XML_ENCODING_MAX_RECURSION - 1) return UA_STATUSCODE_BADENCODINGERROR; status ret = UA_STATUSCODE_GOOD; - if(!ctx->printValOnly) { - if(ctx->prettyPrint) { - ret |= xmlEncodeWriteChars(ctx, "\n", 1); - for(size_t i = 0; i < ctx->depth; ++i) - ret |= xmlEncodeWriteChars(ctx, "\t", 1); - } - ret |= xmlEncodeWriteChars(ctx, "<", 1); - ret |= xmlEncodeWriteChars(ctx, name, strlen(name)); - ret |= xmlEncodeWriteChars(ctx, ">", 1); - } + ret |= xmlEncodeWriteChars(ctx, "<", 1); + ret |= xmlEncodeWriteChars(ctx, name, strlen(name)); + ret |= xmlEncodeWriteChars(ctx, ">", 1); ctx->depth++; return ret; } @@ -236,16 +229,9 @@ writeXmlElemNameEnd(CtxXml *ctx, const char* name, return UA_STATUSCODE_BADENCODINGERROR; ctx->depth--; status ret = UA_STATUSCODE_GOOD; - if(!ctx->printValOnly) { - if(ctx->prettyPrint && !XML_TYPE_IS_PRIMITIVE) { - ret |= xmlEncodeWriteChars(ctx, "\n", 1); - for(size_t i = 0; i < ctx->depth; ++i) - ret |= xmlEncodeWriteChars(ctx, "\t", 1); - } - ret |= xmlEncodeWriteChars(ctx, "", 1); - } + ret |= xmlEncodeWriteChars(ctx, "", 1); return ret; } @@ -253,14 +239,9 @@ static status UA_FUNC_ATTR_WARN_UNUSED_RESULT writeXmlElement(CtxXml *ctx, const char *name, const void *value, const UA_DataType *type) { status ret = UA_STATUSCODE_GOOD; - UA_Boolean prevPrintVal = ctx->printValOnly; - ctx->printValOnly = false; ret |= writeXmlElemNameBegin(ctx, name); - ctx->printValOnly = XML_TYPE_IS_PRIMITIVE; ret |= encodeXmlJumpTable[type->typeKind](ctx, value, type); - ctx->printValOnly = false; ret |= writeXmlElemNameEnd(ctx, name, type); - ctx->printValOnly = prevPrintVal; return ret; } @@ -496,22 +477,17 @@ ENCODE_XML(ExtensionObject) { &src->content.encoded.typeId, &UA_TYPES[UA_TYPES_NODEID]); /* Write the body */ - UA_Boolean prevPrintVal = ctx->printValOnly; - ctx->printValOnly = false; ret |= writeXmlElemNameBegin(ctx, UA_XML_EXTENSIONOBJECT_BODY); if(src->encoding == UA_EXTENSIONOBJECT_ENCODED_BYTESTRING) ret |= writeXmlElemNameBegin(ctx, UA_XML_EXTENSIONOBJECT_BYTESTRING); - ctx->printValOnly = true; ret |= ENCODE_DIRECT_XML(&src->content.encoded.body, String); - ctx->printValOnly = false; if(src->encoding == UA_EXTENSIONOBJECT_ENCODED_BYTESTRING) ret |= writeXmlElemNameEnd(ctx, UA_XML_EXTENSIONOBJECT_BYTESTRING, &UA_TYPES[UA_TYPES_BYTESTRING]); ret |= writeXmlElemNameEnd(ctx, UA_XML_EXTENSIONOBJECT_BODY, &UA_TYPES[UA_TYPES_EXTENSIONOBJECT]); - ctx->printValOnly = prevPrintVal; return ret; } @@ -630,9 +606,7 @@ UA_encodeXml(const void *src, const UA_DataType *type, UA_ByteString *outBuf, ctx.end = &outBuf->data[outBuf->length]; ctx.depth = 0; ctx.calcOnly = false; - ctx.printValOnly = false; if(options) { - ctx.prettyPrint = options->prettyPrint; ctx.namespaceMapping = options->namespaceMapping; ctx.serverUris = options->serverUris; ctx.serverUrisSize = options->serverUrisSize; @@ -666,9 +640,7 @@ UA_calcSizeXml(const void *src, const UA_DataType *type, ctx.pos = NULL; ctx.end = (const UA_Byte*)(uintptr_t)SIZE_MAX; ctx.depth = 0; - ctx.printValOnly = false; if(options) { - ctx.prettyPrint = options->prettyPrint; ctx.namespaceMapping = options->namespaceMapping; ctx.serverUris = options->serverUris; ctx.serverUrisSize = options->serverUrisSize; diff --git a/src/ua_types_encoding_xml.h b/src/ua_types_encoding_xml.h index 24cecfdef..b8982d7e6 100644 --- a/src/ua_types_encoding_xml.h +++ b/src/ua_types_encoding_xml.h @@ -53,12 +53,8 @@ xml_tokenize(const char *xml, unsigned int len, typedef struct { uint8_t *pos; const uint8_t *end; - uint16_t depth; /* How often did we encoding recurse? */ UA_Boolean calcOnly; /* Only compute the length of the decoding */ - UA_Boolean prettyPrint; - UA_Boolean printValOnly; /* Encode only data value. */ - const UA_DataTypeArray *customTypes; UA_NamespaceMapping *namespaceMapping;