03/16/2020
Dear all,
I am currently working on an encoder/decoder for structured custom data types and I have some questions about the JSON encoding.
The project is about allowing the encoding payload to be used towards the client via a proprietary interface. The Client has no opportunity to access subsequent informations (metadata, DataTypeDefinition attribute) directly. Thus, the main goal is to achieve reversible JSON encoding without metadata or accessing the DataTypeDefinition attribute. See the example below:
Suppose, there is a data type defined in C as follows:
typedef struct {
Int32 X;
Int32 Y;
} Coordinate;
If I want to encode the data of this type in JSON, the specification of Part 6 woudl suggest a solution like:
{ "X":47, "Y":11}
This looks very concise and fine, but the Information is very limited. The client has no Information about the data type name and the field types used. This would result in a request for reading the type DataTypeDefinition attribute, if the client has no prior knowledge of the type.
There is a more profound solution in the OPC UA PubSub Formatter:
{ "Coordinate":{"Value":{"Type":22,"Body":{"Body":{"X":47,"Y":11}}}}}
This solution at least contains the type name information and that it is a structure. Better, but still not all informations in one encoding. So now my question: Is there a defined and specified JSON encoding, where the value, the data type, the data type name and the type and name of each field? Thus, the metadata message aswell as the DataTypeDefinition attribute should not be read. I am looking for something like this:
{
"Coordinate":{
"Value":{
"Type":{ // The node id of the data type and not 22 (structure base data type node)
"IdType":0,
"Id":1986,
"Namespace":4,
}
"Body":{
"Body":{
"Type":6,
"X":47
},
"Body":{
"Type":6,
"Y":11
}
}
}
}
}
In short: What is the correct way, to encode data structured data of type "Coordinate" with JSON, such that a Client has knowledge about the structural appearance of the data and can directly decode the data (encoding must be reversible)? Preferrably, the metadata message aswell as the DataTypeDefinition attribute should not be read.
Thanks in advance and greetings,
Sebastian Schwinn
02/24/2014
Hello,
I am the author of the OPC UA PubSub Formatter.
Upon first look at this, I agree with Randy - the TypeId should be included as he suggested. I will check deeper, fix it if necessary, and then post an update and a notification here.
This is probably some regression, because I think I remember we used precisely this example for discussions regarding whether encoding Id or datatype Id should be used (and allowed for both).
Correction to OP: 22 does not stand for Structure datatype id. It stands for built-in type ExtensionObject.
Regards
02/24/2014
The UA PubSub Formatter is now fixed.
It may take ClickOnce a day or two before it updates itself for you automatically, unless you force the update somehow. Verification: Click "About" in the right part of the window caption bar, the version should be 5.71.0.15 or later.
Regards
1 Guest(s)