prost icon indicating copy to clipboard operation
prost copied to clipboard

support message option?

Open brianjcj opened this issue 5 years ago • 5 comments

support message option? e.g.:

syntax = "proto3";

package snazzy.items;

import "uri.proto";

// A snazzy new shirt!
message Shirt {
  enum Size {
    SMALL = 0;
    MEDIUM = 1;
    LARGE = 2;
  }

  string color = 1;
  Size size = 2;

  option (yyp.uri) = 999;   // <==== message option
}

make the option value can be retrieved from the message struct.

brianjcj avatar Jan 15 '21 10:01 brianjcj

uri.proto for references:

syntax = "proto3";

package yyp;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
  uint32 uri = 1001;
}

brianjcj avatar Jan 15 '21 11:01 brianjcj

in python, i can get the option value as following:

def get_yyp_uri(msg):
    return msg.DESCRIPTOR.GetOptions().Extensions[yyp_uri_opt]

brianjcj avatar Jan 15 '21 11:01 brianjcj

This would be really useful. I'd like to define some data that relates to some event messages (exchange/topic name) along side the message itself. I can do this if I choose go but I'd like to try it out with rust as well

itmecho avatar Aug 17 '21 20:08 itmecho