eclipse-cyclonedds / cyclonedds-python

Other
54 stars 44 forks source link

TypeObject parsing: union over enum case labels #217

Closed eboasson closed 10 months ago

eboasson commented 10 months ago

This converts the plain integer case label in the TypeObject to an enum symbol if the discriminator is an enum type.

Fixes #215

adam-lee commented 10 months ago

It's working! This is quite amazing. Thanks for the quick fix :).

> cyclonedds typeof HelloWorldData_Msg
   0:00:01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Entities discovered: 1

As defined in participant(s) 01106dd6-1858-10c4-08b8-c4d5000001c1
module HelloWorldData {
    @final
    enum signal_value_type {
        integer_value,
        double_value,
        string_value
    };
    @final
    union value_s switch (HelloWorldData::signal_value_type) {
        case HelloWorldData::integer_value:
            unsigned long long int_value;
        case HelloWorldData::double_value:
            double double_value;
        case HelloWorldData::string_value:
            bounded_str<512>  str_value;
    };
    @final
    struct Msg {
        @key long userID;
        string message;
        HelloWorldData::value_s value;
    };
};

> cyclonedds subscribe HelloWorldData_Msg
   0:00:01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Entities discovered: 1

 Subscribing, CTRL-C to quit

Msg(
    userID=1,
    message='Hello World',
    value=value_s(discriminator=<signal_value_type.integer_value: 0>, int_value=0)
)