Type definition for multiple array dimensions and data types

5 posts / 0 new
Last post
Offline
Last seen: 5 years 6 months ago
Joined: 03/13/2019
Posts: 6
Type definition for multiple array dimensions and data types

Hi 

I have a question on how to define multiple types in XML format for a complicated (nested) json data, which has multiple array dimensions and data types. The json sample is attacted for your reference.

Tried to define the types like the XML code below, but when publishing it by web integration service to a certain database, blank arrays are created without any values, which makes the read data larger than the written one. So,

  • In the original data, 'Value' has multiple data types like: string, integer, float, long, etc. How shall its type definition be?
  • 'Parameter' has arrays in 2, 3, 4 dimensions, if set as arrayDimensions="4", after publishing to the data reader, all arrays will be in 4 demensions with several vacant 'name', 'unit' and 'value'. Is there any way to set the exact dimensions for this 'Parameter'?

<types>

<struct name="Type1">

<member id="0" name="Name" type="string" />

<member id="1" name="Unit" type="string" />

<member id="2" name="Value" type="string" />

</struct>

<struct name="Type2">

<member id="0" name="Name" stringMaxLength="255" type="string" />

<member id="1" name="Parameter" arrayDimensions="4" type="nonBasic" nonBasicTypeName="Type1" /> 

</struct>

<struct name="Type3">

<member id="0" name="Name" type="string" />

<member id="1" name="ParameterGroup" arrayDimensions="3" type="nonBasic" nonBasicTypeName="Type2" /> 

</struct>

</types>

 

Thanks,
Yanyang.
AttachmentSize
Plain text icon json_sample.txt993 bytes
Offline
Last seen: 3 months 3 weeks ago
Joined: 05/29/2019
Posts: 1

Yanyang,

My name is Christopher Carson and I am the RTI Field Applications Engineer that works with GE Healthcare globally.  Can you reach out to me directly so I can help you with your inquiry?  You may contact me at chris@rti.com or phone me at +1 (773) 332-0402.  I am located in USA Central Standard Time should you chose to phone.

Gerardo Pardo's picture
Offline
Last seen: 1 week 5 days ago
Joined: 06/02/2010
Posts: 602

Hi Yanyang,

I will try to answer your questions in reverse order:

'Parameter' has arrays in 2, 3, 4 dimensions, if set as arrayDimensions="4", after publishing to the data reader, all arrays will be in 4 demensions with several vacant 'name', 'unit' and 'value'. Is there any way to set the exact dimensions for this 'Parameter'

This is because you are defining the type as an "array" which by definition always has the same number of elements. If you want to have a variable size (i.e. sometimes 2 sometimes 3, etc.) then you need to use a "sequence" instead of an array. So instead of:

<member id="1" name="Parameter" arrayDimensions="4" type="nonBasic" nonBasicTypeName="Type1" />

Do this:

<member id="1" name="Parameter" sequenceMaxLength="4" type="nonBasic" nonBasicTypeName="Type1" /> 

Regarding. 

In the original data, 'Value' has multiple data types like: string, integer, float, long, etc. How shall its type definition be?

The normal way to support members that can be of different data types is to use a union type. For example:

<union name="VariantType" extensibility="appendable" nested="true">
    <discriminator type="long"/>
    <case>
      <caseDiscriminator value="0"/>
      <member name="boolean_value" type="boolean"/>
    </case>
    <case>
      <caseDiscriminator value="1"/>
      <member name="integer_value" type="int32"/>
    </case>
    <case>
      <caseDiscriminator value="2"/>
      <member name="float_value" type="float32"/>
    </case>
    <case>
      <caseDiscriminator value="3"/>
      <member name="string_value" type="string" stringMaxLength="VARIANT_STRING_LENGTH"/>
    </case>
  </union>
  

Looking a the JSON file you provided, I would define the types in XML along the lines shown in the attached file.

File Attachments: 
Offline
Last seen: 5 years 6 months ago
Joined: 03/13/2019
Posts: 6

Hi Gerardo,

Thank you very much for your solution.

For the variable size, replacing 'arrayDimensions' with 'sequenceMaxLength' does solve the problem. It makes data stored subsribed by database is identical with the data published by web integration service.

However, for the 'Value' with multiple data type issue, I tried with your union type, but it did not work as expected:

{"code": "INVALID_INPUT", "message": "rti::webdds::dds::DataWriter::set_dynamic_data_member:Error setting dynamic data member Value
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
DDS_DynamicData_finalize:WARNING: destructing object bound to a member, automatically unbinding now
"}422 1.003

FYI, the two DDS service version in our system is:

/opt/rti_connext_dds-5.3.0/bin/../resource/app/bin/x64Linux2.6gcc4.1.1/rtiwebintegrationservice

/opt/rti_connext_dds-5.3.1/bin/../resource/app/bin/x64Linux2.6gcc4.1.1/rtirtc_postgresql

Do you happen to know how to solve this set_dynamic_data_member:Error ?

Thanks a lot.

 

Fernando Garcia's picture
Offline
Last seen: 5 months 2 weeks ago
Joined: 05/18/2011
Posts: 200

Hi Yanyang,

Could you share with us the POST request that is triggering that error?

Gerardo's example uses a Union to represent all the possible types the value property can hold. In that case, when you POST a new value of a certain type, you need to specify the specific union member you are selecting; that is, boolean_value, integer_value, float_value, or string_value.

Following the syntax to represent DDS Unions in JSON, you would need to write your integer value as follows:

{
    "value": {
        "integer_value": 32
    }
}

Likewise, to write a float value you would need to do:

{
    "value": {
        "float_value": 32.4
    }
}

From your description, I understand you want to be able to POST a sample where the value property of a JSON object can be boolean integer, a string, or a float. That is, something you would represent in JSON Schema as:

"ValueObject": {
    "type": [ "boolean", "integer", "string", ... ]
}

With that syntax, all the following examples would be valid syntax:

{
    "value": 3
}

{
    "value": 4.3
}

{
    "value": true
}

That is something that cannot be directly represented with the JSON syntax Web Integration Service generates. As Gerardo mentioned Unions would provide you with something similar in principle, a type that can hold samples of different types, but still need you to specify which member you are using in each corresponding case.

Let me know if this helps.

Thanks!
Fernando