ihmc-pub-sub-group
ihmc-pub-sub-group copied to clipboard
IDLGenerator does not generate Java code for keyed topics.
When I use IDLGenerator to generate Java code for keyed topics. The generated code still use unkeyed topics. What am I missing? It can be verified by adding
publisherAttributes.getTopic().setTopicKind(TopicAttributes.TopicKind.WITH_KEY);
subscriberAttributes.getTopic().setTopicKind(TopicAttributes.TopicKind.WITH_KEY);
to
PublisherExample and SubscriberExample (here).
Then exception is thrown:
java.lang.IllegalArgumentException: Keyed topic needs getKey function
How can I properly use keyed topics?
Thank you.
Pavel
We have never tested keyed topics. I do not think the generator generates the correct code, and we have to add that functionality.
If it is for one or two classes, you can manually implement a getKey() function, but it's been a while since I looked at the format.
Ok. Thanks for the reply. I will try to implement it.
Hi. I am trying to manually implement a getKey() function but with no luck. What I did:
I created idl:
struct HelloWorld { @Key long id; string message; };
Generated HelloWorld.java and HelloWorldPubSubType.java by a generator.
I override getKey() function in HelloWroldPubSubType.java like this.
public void getKey(cz.urc.dds.idl.HelloWorld data, ByteBuffer target) { if (this.isGetKeyDefined()) { data.serializeKey(serializeCDR); //Throws java.lang.NullPointerException } try { MessageDigest dig = MessageDigest.getInstance("MD5"); byte[] md5 = dig.digest(); for (int i=0; i < md5.length; ++i) { target.put(i, md5[i]); } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
I implemented serializeKey() function like this.
public void serializeKey(us.ihmc.idl.CDR scdr){ try { scdr.write_type_2(this.id_); } catch (Exception e) { System.out.println("serializeKey exception: " + e); } }
But its throws Throws java.lang.NullPointerException, because serializeCDR is not initialized.
Could you please provide me with some help or insight on what should I do?
PS: When I do not implement the getKey method I get the [RTPS_WRITER Warning] Changes in KEYED Writers need a valid instanceHandle -> Function eprosima::fastrtps::rtps::RTPSWriter::new_change but the data are published and subscriber receives them.
Thank you. Pavel