2.3 Type-Consistency Enforcement

The DataReader's TypeConsistencyEnforcementQosPolicy defines the rules that determine whether the type used to publish a given topic is consistent with that used to subscribe to it.

The QosPolicy structure includes the members in the following table.

Table 2.5 DDS_TypeConsistencyEnforcementQosPolicy

Type

Field Name

Description

DDS_TypeConsistencyKind

kind

Can be any of the following values:

  • AUTO_TYPE_COERCION (default)
  • ALLOW_TYPE_COERCION
  • DISALLOW_TYPE_COERCION

See below for details.

DDS_Boolean

ignore_sequence_bounds

Controls whether sequence bounds are taken into consideration for type assignability.

If false, a sequence with a larger maximum length may not be assigned to a sequence with a smaller maximum length.

If true, sequences and strings in a DataReader type can have a maximum length smaller than that of the DataWriter type. When the length of the sequence in a particular sample is larger than the maximum length, that sample is discarded.

Default: false

DDS_Boolean

ignore_string_bounds

Controls whether string bounds are taken into consideration for type assignability. If false, then a string with a larger maximum length may not be assigned to a string with a smaller maximum length.

Default: false.

DDS_Boolean

ignore_member_names

Controls whether member names are taken into consideration for type assignability.

If false, members with the same ID and different names are not assignable to each other.

If true, members of a type can change their name while keeping their member ID. For example, MyType and MyTypeSpanish are only assignable if ignore_member_names is true:

 
struct MyType {
    @id(10) int32 x;
    @id(20) int32 angle;
};
struct MyTypeSpanish {
    @id(10) int32 x;
    @id(20) int32 angulo;
};

Default: false

DDS_Boolean

prevent_type_widening

Controls whether type widening is allowed. A type T2 widens a type T1 when T2 contains required members that are not present in T1. If a DataReader of T2 sets prevent_type_widening to true, then the DataReader will not be matched with a DataWriter of T1 because T1 is not assignable to T2.

Default: false

DDS_Boolean

force_type_validation

Controls whether type information must be available in order to complete matching between a DataWriter and this DataReader.

If false, matching may occur as long as the type names match. Note that if the types have the same name but are not assignable, DataReaders may fail to deserialize incoming data samples.

Default: false

DDS_Boolean

ignore_enum_literal_names

Controls whether enumeration constant names are taken into consideration for type assignability. If the option is set to true, then enumeration constants may change their names, but not their values, and still maintain assignability. If the option is set to false, then in order for enumerations to be assignable, any constant that has the same value in both enumerations must also have the same name. For example, enum Color {RED = 0} and enum Color {ROJO = 0} are assignable if and only if ignore_enum_literal_names is true.

Default: false

This QoSPolicy defines a type consistency kind, which allows applications to choose to either allow or disallow data type matching:

This policy applies only to DataReaders; it does not have request-offer semantics. The value of the policy cannot be changed after the DataReader has been enabled.

The default enforcement kind is AUTO_TYPE_COERCION. This default kind translates to ALLOW_TYPE_COERCION, except in the following cases:

2.3.1 Rules For Type-Consistency Enforcement

The type-consistency enforcement rules consist of two steps applied on the DataWriter and DataReader side:

If either Step 1 or Step 2 fails, the Topics associated with the DataReader and DataWriter are considered to be inconsistent (see 2.5 Notification of Inconsistencies: INCONSISTENT_TOPIC Status).

2.3.2 Prevent Type Widening

The prevent_type_widening field determines whether type widening is allowed. In Figure 2.1: prevent_type_widening = false, VehicleData_v2 has three members and VehicleData_v1 two members. With type widening allowed, the narrower car (VehicleData_v1, with two members) can write to the wider car (VehicleData_v2), but notice that the DataReader assumes a value that might be misleading (in this case, a default speed of zero).

Figure 2.1: prevent_type_widening = false

If widening is not allowed (Figure 2.2: prevent_type_widening = true), VehicleData_v1 and VehicleData_v2 do not communicate with each other.

Figure 2.2: prevent_type_widening = true

2.3.3 Type Assignability Properties

The properties in Table 2.6 Type Assignability Properties relax some of the rules in the standard type-assignability algorithm. These properties can be set in the QoS of the DataReader, DataWriter, and DomainParticipant (in this case all DataReaders and DataWriters created by that DomainParticipant inherit the property). By default they are disabled.

Table 2.6 Type Assignability Properties

Property Name

Description

dds.sample_assignability.accept_unknown_union_discriminator

When set to 1, samples containing an unknown union discriminator can be successfully deserialized to the default discriminator value. For example, given the following two types:

Publisher Type:

@mutable
union MyUnion switch(int32) {
    case 0:
	int32 m1;
    case 1:
	int16 m2;
    case 2:
	double m3;
}; 

Subscriber Type:

@mutable
union MyUnion switch(int32) {
    case 0: 
	int32 m1;
    case 1:
	int16 m2;
}; 

By default, if the DataWriter sends a union with the discriminator set to 2, the DataReader cannot deserialize the sample. However if this property is set to 1, the Subscribing application will receive a sample with the discriminator set to 0 and member m1 set to the default value for an int32 (0). The default discriminator value is defined as the default element if one is specified, otherwise the lowest value associated with any discriminator value. The member identified by the default discriminator is also initialized to its default value.

You can set this property as part of the Property QoS for either the DomainParticipant or the DataReader. If it is set in both the DomainParticipant and DataReader, the value in the DataReader's QoS will be applied.

This functionality is supported both in generated code as well as when using the DynamicData API.

dds.sample_assignability.accept_unknown_enum_value

When set to 1 samples containing an unknown enumerator to be successfully deserialized to the default enumeration value. For example, given the following two types:

Publisher Type:

enum MyEnum {
    ONE = 1,
    TWO = 2,
    THREE = 3
};
struct MyType {
    MyEnum m1;
};

Subscriber Type:

enum MyEnum {
    ONE = 1,
    TWO = 2
};
struct MyType {
    MyEnum m1;
};

By default, if the DataWriter sends m1 = THREE, the DataReader cannot deserialize the sample. However if this property is set to 1 then the Subscribing application will receive a sample with m1 = ONE. The default enumeration value is defined as the first declared member of the enumeration.

You can set this property as part of the Property QoS for either the DomainParticipant or the DataReader. If it is set in both the DomainParticipant and DataReader, the value in the DataReader's QoS will be applied.

This functionality is supported both in generated code as well as when using the DynamicData API.

dds.type_consistency.ignore_member_names

This property has been replaced with ignore_member_names and ignore_enum_literal_names in the TypeConsistencyEnforcementQosPolicy (see 2.3 Type-Consistency Enforcement), but is still supported for compatibility with previous releases. If this property is set, its value supersedes the values in the QosPolicy.

dds.type_consistency.ignore_sequence_bounds

This property has been replaced with ignore_sequence_bounds and ignore_string_bounds in the TypeConsistencyEnforcementQosPolicy (see 2.3 Type-Consistency Enforcement), but is still supported for compatibility with previous releases. If this property is set, its value supersedes the values in the QosPolicy.

© 2020 RTI