48.6 TYPE_CONSISTENCY_ENFORCEMENT QosPolicy

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

Note: If the type information is not available for a topic (and force_type_validation is false), these rules do not apply.

The QosPolicy structure includes the members in the following table.

Table 48.8 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 DataWriter’s type containing a sequence with a larger maximum length will not be assigned to a DataReader’s type containing a sequence with a smaller maximum length. Since the types are not assignable, the DataReader will not match when type information is available.

If true, a sequence in a DataReader's type can have a maximum length smaller than that of a sequence in a DataWriter's type. The types will be assignable, and the DataReader will match; however, when the length of the sequence in a particular DataWriter's sample is larger than the DataReader's maximum length, that sample is discarded. See "Verifying Sample Consistency: Sample Assignability" in the Core Libraries Extensible Types Guide.

Default: true

DDS_Boolean

ignore_string_bounds

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

If false, then a DataWriter’s type containing a string with a larger maximum length will not be assigned to a DataReader’s type containing a string with a smaller maximum length. Since the types are not assignable, the DataReader will not match when type information is available.

If true, then a string in a DataReader’s type can have a maximum length smaller than that of a string in a DataWriter’s type. They are assignable, and the DataReader will match; however, when the length of the string in a particular DataWriter’s sample is larger than the DataReader’s maximum length, that sample is discarded. See "Verifying Sample Consistency: Sample Assignability" in the Core Libraries Extensible Types Guide.

Default: true

DDS_Boolean

ignore_member_names

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

If false, types containing members with the same ID and different names are not assignable to each other. Since the types are not assignable, the DataReader will not match when type information is available.

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;
};

Since the types are assignable, the DataReader will match.

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 with fewer members because T1 is not assignable to T2.

If a DataReader of T2 sets prevent_type_widening to false, then the DataReader will match with the DataWriter of T1. The DataReader will assume a value for members in T2 that are not in T1. See "Prevent Type Widening" below.

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 the types are not assignable, DataReaders may fail to deserialize incoming data samples. If force_type_validation is true and no type information is available, then the DataReader will not match.

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 type 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

The type-consistency enforcement rules consist of two steps:

  1. If both the DataWriter and DataReader specify a TypeObject, it is considered first. If the DataReader allows type coercion, then its type must be assignable from the DataWriter’s type, taking into account the values of prevent_type_widening, ignore_sequence_bounds, ignore_string_bounds, ignore_member_names, and ignore_enum_literal_names. If the DataReader does not allow type coercion, then its type must be equivalent to the type of the DataWriter.
  2. If either the DataWriter or the DataReader does not provide a TypeObject definition, then the registered type names are examined. The DataReader’s and DataWriter’s registered type names must match exactly, as was true in Connext releases prior to 5.0. This step will fail if force_type_validation is true, regardless of the type names.

If either Step 1 or Step 2 fails, the Topics associated with the DataReader and DataWriter are considered to be inconsistent and the 18.2.1 INCONSISTENT_TOPIC Status is updated.

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

  • When a Zero Copy DataReader is used, the kind is translated to DDS_DISALLOW_TYPE_COERCION.
  • When the middleware is introspecting the built-in topic data declaration of a remote DataReader in order to determine whether it can match with a local DataWriter, if it observes that no TypeConsistencyEnforcementQosPolicy value is provided (as would be the case when communicating with a Service implementation not in conformance with this specification), it assumes a kind of DDS_DISALLOW_TYPE_COERCION.

48.6.1 Values for TypeConsistencyKind

  • AUTO_TYPE_COERCION (default)
  • For a regular DataReader, this default value is translated to ALLOW_TYPE_COERCION. For a Zero Copy DataReader, this default value is translated to DISALLOW_TYPE_COERCION. (See 34.1.5 Zero Copy Transfer Over Shared Memory for information on why a Zero Copy DataReader requires the DISALLOW_TYPE_COERCION option.)

  • DISALLOW_TYPE_COERCION
  • With this setting, the DataWriter and DataReader must support the same data type in order for them to communicate. (This is the degree of enforcement required by the OMG DDS Specification prior to the OMG ‘Extensible and Dynamic Topic Types for DDS’ specification.)

    When Connext is introspecting the built-in topic data declaration of a remote DataWriter or DataReader, if no TypeConsistencyEnforcementQosPolicy value is provided (as would be the case when communicating with an implementation not in conformance with the Extensible and Dynamic Topic Types for DDS" (DDS-XTypes) specification), Connext shall assume a kind of DISALLOW_TYPE_COERCION.

  • ALLOW_TYPE_COERCION
  • With this setting, the DataWriter and the DataReader need not support the same data type in order for them to communicate, as long as the DataReader’s type is assignable from the DataWriter’s type.

    For example, the following two extensible types will be assignable to each other since MyDerivedType contains all the members of MyBaseType (member_1) plus an additional element (member_2).

    struct MyBaseType {
    	int32 member_1;
    };
    struct MyDerivedType: MyBaseType {
    	int32 member_2;
    };

    Even if MyDerivedType was not explicitly inherited from MyBaseType, the types would still be assignable. For example:

    struct MyBaseType {
    	int32 member_1;
    };
    struct MyDerivedType {
    	int32 member_1;
    	int32 member_2;
    };

For more information, see the RTI Connext Core Libraries Extensible Types Guide and the OMG ‘Extensible and Dynamic Topic Types for DDS’ Specification.

48.6.2 Prevent Type Widening

The prevent_type_widening field determines whether type widening is allowed. In Figure 48.3: 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 48.3: prevent_type_widening = false

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

Figure 48.4: prevent_type_widening = true

48.6.3 Properties

This QosPolicy cannot be modified after the DataReader is enabled.

It only applies to DataReaders, so there is no requirement that the publishing and subscribing sides use compatible values.

48.6.4 Related QoS Policies

  • None.

48.6.5 Applicable Entities

48.6.6 System Resource Considerations

  • None.