custom-options.proto 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import "google/protobuf/descriptor.proto";
  2. extend google.protobuf.FileOptions {
  3. optional string my_file_option = 50000;
  4. }
  5. extend google.protobuf.MessageOptions {
  6. optional int32 my_message_option = 50001;
  7. }
  8. extend google.protobuf.FieldOptions {
  9. optional float my_field_option = 50002;
  10. }
  11. extend google.protobuf.EnumOptions {
  12. optional bool my_enum_option = 50003;
  13. }
  14. extend google.protobuf.EnumValueOptions {
  15. optional uint32 my_enum_value_option = 50004;
  16. }
  17. extend google.protobuf.ServiceOptions {
  18. optional MyEnum my_service_option = 50005;
  19. }
  20. extend google.protobuf.MethodOptions {
  21. optional MyMessage my_method_option = 50006;
  22. }
  23. option (my_file_option) = "Hello world!";
  24. message MyMessage {
  25. option (my_message_option) = 1234;
  26. optional int32 foo = 1 [(my_field_option) = 4.5];
  27. optional string bar = 2;
  28. }
  29. enum MyEnum {
  30. option (my_enum_option) = true;
  31. FOO = 1 [(my_enum_value_option) = 321];
  32. BAR = 2;
  33. }
  34. message RequestType {}
  35. message ResponseType {}
  36. service MyService {
  37. option (my_service_option) = FOO;
  38. rpc MyMethod(RequestType) returns(ResponseType) {
  39. // Note: my_method_option has type MyMessage. We can set each field
  40. // within it using a separate "option" line.
  41. option (my_method_option).foo = 567;
  42. option (my_method_option).bar = "Some string";
  43. }
  44. }