OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.89k stars 926 forks source link

Serialization of floating point values to XML: Remove superfluous handling of special values #2588

Closed mtx500 closed 2 months ago

mtx500 commented 2 months ago

Proposed changes

In OPC UA the serialization of floating point values to XML just follows the XML Schema specification (see https://www.w3.org/TR/xmlschema-2/#float). It is sufficient to use the correct .NET XML classes (XmlReader, XmlWriter, XmlConvert). There is no need to treat the special values Infinity, negative Infinity and Not-a-number in special way.

XmlWriter uses XmlConvert internally (see https://referencesource.microsoft.com/#System.Xml/System/Xml/Core/XmlWriter.cs and https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriter.cs), and XmlConvert (see https://referencesource.microsoft.com/#System.Xml/System/Xml/XmlConvert.cs and https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs) first takes care of "INF" and "-INF" and then uses the Single / Double routines with the appropriate flags and culture set so that "NaN" is also taken care of.

BTW, the removed code parts were inconsistent:

Types of changes

What types of changes does your code introduce? Put an x in the boxes that apply. You can also fill these out after creating the PR.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

romanett commented 2 months ago

Thanks for the additions. Can you add some simple Unit Tests proving the edge cases are handled correctly on all platforms / build targets?

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 75.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 54.62%. Comparing base (414a0d5) to head (8dcbbde).

Files Patch % Lines
Stack/Opc.Ua.Core/Types/Encoders/XmlDecoder.cs 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2588 +/- ## ======================================= Coverage 54.62% 54.62% ======================================= Files 342 342 Lines 65082 65056 -26 Branches 13350 13335 -15 ======================================= - Hits 35548 35539 -9 + Misses 25663 25649 -14 + Partials 3871 3868 -3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mtx500 commented 2 months ago

I will create unit testing. As I am doing this the first time, it takes a little bit ...

mtx500 commented 2 months ago

Should be finished and OK now. The still failing tests seem to me not being effected by my changes.

mregen commented 2 months ago

@opcfoundation-org as this change may affect nodeset generation please code review this change to Xml encoder and decoder.