14.4. Annotations

DynamicTypeBuilder allows applying an annotation to both current type and inner members with the functions:

  • apply_annotation()

  • apply_annotation_to_member()

Both functions take the name, the key and the value of the annotation. apply_annotation_to_member() additionally receives the MemberId of the inner member.

For example, if we define an annotation like:

@annotation MyAnnotation
    long value;
    string name;

And then we apply it through IDL to a struct:

@MyAnnotation(5, "length")
struct MyStruct

The equivalent code using DynamicType will be:

// Apply the annotation
DynamicTypeBuilder_ptr builder = DynamicTypeBuilderFactory::get_instance()->create_struct_builder();
builder->apply_annotation("MyAnnotation", "value", "5");
builder->apply_annotation("MyAnnotation", "name", "length");

14.4.1. Builtin annotations

The following annotations modifies the behavior of DynamicTypes:

  • @position: When applied to Bitmask, sets the position of the flag,
    as expected in the IDL annotation.
    If applied to Bitset, sets the base position of the bitfield,
    useful to identify unassigned bits.
  • @bit_bound: Applies to Bitset. Sets the size in bits of the bitfield.
  • @key: Alias for @Key. See Data types with a key section for more details.
  • @default: Sets a default value for the member.
  • @non_serialized: Excludes a member from being serialized.