I am using RTI Connector for javascript and trying to find a way to access just the key fields when reading in a message. I know this can be done in C++ and Java, but in the Javascript API Documentation, this is only mentioned for when the sample has been disposed https://community.rti.com/static/documentation/connector/current/api/javascript/data.html?highlight=dictionary#accessing-key-values-of-disposed-samples
Otherwise, the getJson() function gets ALL fields, not just the instance key fields. Is there an equivalent function for Javascript that performs the same operation as the key_value() function in the C++ API?
What is the function you are referring to in C++ and Java?
I don't think that the example in the documentation that you supplied for JavaScript (here) does what you think it does:
The call to getJson() there will still contain a JSON object with all of the key/value pairs (that is, JSON key/value pairs) contained in sample, but when the instance state is disposed, it comes with the disclaimer that only the key values (that is, IDL key values) should be accessed.
Thanks for the reply. The function I'm referring to is key_value(). https://community.rti.com/static/documentation/connext-dds/5.2.0/doc/api/connext_dds/api_cpp2/classdds_1_1sub_1_1DataReader.html#a44fca51d1564498fd383611e7f16a43f
Ok, I see what you mean about the getJson() function. You're correct that I misunderstood what the documentation was saying about that.
The key_value() method that you refer to takes an "instance_handle". This method is only useful when you don't have the actual value of data, but a handle to the instance...for which you want to know the key value.
(in many Listener callbacks, you may get a handle to the instance that's relevant to the callback)
In any case, key_value() will return a full data sample object with just the key fields filled out. NOTE: your code will still need to know which members of the data structure comprise the key of the data type. It's not that you only get the key values back. You get an entire data structure in which only the key members have any real value.
So, what you're asking for is not possible in C/C++ either...