Skip to content

Generate protobuf enums for datatype string with allowed option #493

@JohannSchramm

Description

@JohannSchramm

Given a sample vspec entry:

Media.Played.Source:
  datatype: string
  type: actuator
  allowed: ['UNKNOWN', 'SIRIUS_XM', 'AM', 'FM', 'DAB', 'TV', 'CD', 'DVD', 'AUX', 'USB', 'DISK', 'BLUETOOTH', 'INTERNET', 'VOICE', 'BEEP']
  description: Media selected for playback

The protobuf exporter currently generates this protobuf:

message MessageTitle {
  string Source = 1;
}

However according to the documentation the generated datatype should also restrict the possible values and treat every value outside of it as an error.

A protobuf enum would solve this by restricting the possible values to just the defined set.

I would expected the generated protobuf to be like this:

enum MessageTitleSourceEnum {
  UNKNOWN = 0;
  SIRIUS_XM = 1;
  AM = 2;
  FM = 3;
  DAB = 4;
  TV = 5;
  CD = 6;
  DVD = 7;
  AUX = 8;
  USB = 9;
  DISK = 10;
  BLUETOOTH = 11;
  INTERNET = 12;
  VOICE = 13;
  BEEP = 14;
}

message MessageTitle {
  MessageTitleSourceEnum Source = 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions