Representing default device/folder in proto

I’d like to get configurable folder and device defaults working. Now the question is how to represent that in proto. In pure go my intention was to have a DefaultFolderConfiguration type with a subset of the configurable options in FolderConfiguration and embed that.

There’s gogoproto.embed which allows me to do the same in proto. However that seems against the spirit of proto: If proto is used for anything non-go, there’s likely no equivalent to embedding and/or the proto generator wont support it. And having to access a config value through an intermediate object like cfg.defaults.ignorePerms is not nice.

Alternatively we could define our own proto extension e.g. called ext.nodefault and then store an entire FolderConfiguration object as default. Then we translate that to an attribute and when using the defaults object, ignore any members with said attribute.

And finally we could just accept some duplication, having both FolderConfiguration and DefaultFolderConfiguration proto messages where the default one contains copies of the desired fields.

I am currently favoring the last option, just because it’s the simplest for actual usage. The manual work of copy&pasting fields is really small, and if it’s a concern I could create some config file that contains a list of fields to be excluded from defaults and autogenerate/check the defaults proto message at build time.

What are your thoughts on this?

I think the last option is the easiest one, or just have a FolderConfiguration object which carries default values, and have a proto field mask that declares what gets copied what doesn’t.

This is clearly not great for json/xml as it would still serialize/deserialize things like ids which we wouldn’t copy.

So a copy proto struct with fields that are relevant the same names and prot ids is best.

1 Like