diff --git a/articles/115_idl.md b/articles/115_idl.md index b93d73a8..b4ebe42f 100644 --- a/articles/115_idl.md +++ b/articles/115_idl.md @@ -264,7 +264,49 @@ If a cell is blank then the default mapping is used. #### 8.3.2.1 @key Annotation -While the key annotation doesn't affect the generated ROS data types directly it is being passed through to the (DDS) vendor specific code generators. +[ROS 2 nodes](ros_on_dds.html) exchange information of a certain real world object by means of topics. +Every message in a topic is known as *data sample* and represents an update to the status of the object. + +Topic instances are a way of multiplexing the transmission of updates of several objects of the same logical kind over the same resource, i.e. the topic. +In a *keyed topic*, every message is associated with a topic instance and each topic instance is identified by a unique key. +In this sense, keys can be thought as the *primary key* of a database. +This key allows nodes to update different states of the same kind. +In consequence, all data samples sharing the same key value refer to the same object. + +The `@key` annotation allows indicating that a data member is part of the key, which can have zero or more key fields and can be applied to structure fields of various types. +The following example shows how to define a keyed message using the IDL format: + +``` +# KeyedMsgName.idl +module package_name { + module msg { + struct KeyedMsgName { + @key long member1; + string member2; + }; + }; +}; +``` + +
+Currently, the message interface format that supports the `@key` annotation is `.idl`. +Hence, `.msg` and `.srv` do not support the `@key` annotation yet. +Please refer to [Conversion to IDL](legacy_interface_definition.html) for further information on the equivalence and conversion among them. +
+ +The general-purpose idl types including primitive types, sequences, strings and structs can be annotated as keys. +Following are some examples: + +| Type | Key Members | +|----------------------------------------|------------------------------| +| struct NoKey
{ boolean member1;
long member2;
long member3; } | None | +| struct SimpleKey
{ @key long member1;
long member2; } | member1 | +| struct ArrayKey
{ @key long member1[3]; } | member1[0]
member1[1]
member1[2] | +| struct StringKey
{ @key string member1;
long member2} | member1 | +| struct NestedNoKey
{ SimpleKey member1;
long member2; } | None | +| struct NestedKey
{ @key SimpleKey member1;
long member2; } | member1.member1 | +| struct NestedKey2
{ @key NoKey member1;
long member2; } | member1.member1
member1.member2
member1.member3 | +| struct ComplexNestedKey
{ @key NestedNoKey member1;
long member2; } | member1.member1.member1
member1.member2 | #### 8.3.3.1 @default Annotation