Unfortunately the .proto syntax doesn't currently have support for defining
arbitrary constants in .proto files. There are various ways you can kinda
do it, including making a proto2 syntax file and a message where every
field has some default value set, and then in your code just using the
default instance of that message and reading the fields to observe the
'defaults' (that technique doesn't enable you have config instances of
message types defined otherwise though, just primitives). You also can
kinda achieve it by making a FileOption, and then set that FileOption on a
file with whatever values (which does allow for specifying message types).

More typically the config usecase is satisfied by keeping a config in
TextProto format separate from the .proto schema today.

Constants in .proto files is on our radar as a possible future syntax
addition, but there's a lot of nuances to it and so its not definite that
it will be added at any point.

On Wed, Sep 11, 2024 at 1:52 PM a...@binoklo.com <a...@binoklo.com> wrote:

> Hello,
>
> I'd like to do something like this:
>
> syntax = "proto3";
>
> package foo;
>
> enum ModuleId {
>   MODULE_ID_UNKNOWN = 0;
>   MODULE_ID_BAR = 1;
>   ...
> }
>
> message ModuleDetails {
>   ModuleId id = 1;
>   string name = 2;
>   ...
> }
>
> message Modules {
>   repeated ModuleDetails modules = 1;
> }
>
> And then define a static Modules message. This seems better to me than
> shipping a, for example, yaml configuration file.
>
> It looks like this feature has been suggested and rejected a couple of
> times. Any suggestions on how I could achieve something like this?
>
> Thanks,
>
> --
> Adriano
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/87550fdf-ea86-44de-8268-1ac721c0886bn%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/87550fdf-ea86-44de-8268-1ac721c0886bn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CAKRmVH8-nvDHOO-r3rOLfbmO39MSDvvwN9VU%3DSZHiTQMJX8pWA%40mail.gmail.com.

Reply via email to