using protobuf as a textual configuraton file

2019-07-01 20:09发布

I recently encountered a very large mission-critical project where all the configuration files were defined using textual protobuf definitions. The configuration files are meant to be human readable and editable.

For example

message ServerSettings {
  required int32 port = 3022;
  optional string name = "mywebserver";
}

Personally I found this humorous. But is it in fact a reasonable keep-it-simple technique, or clearly moronic ?!

In other words, are there REAL, ACTUAL problems with this ?

2条回答
Fickle 薄情
2楼-- · 2019-07-01 20:31

I think it's quite clever. I am guessing they pass it through protoc --encode to generate a binary which is what is actually parsed.

Pros: 1. Code is generated to parse configuration 2. Type validation 3. More robust configuration file compared to a key/value as it supports structs, unions, maps and arrays 4. The configuration data is now serializable meaning it can be easily exposed to an RPC or IPC interface.

Cons: 1. The syntax can be a little verbose for maps/arrays. 2. It requires protoc to be installed on the target as well as libprotobuf.so if you are on a system with tight memory limits.

查看更多
来,给爷笑一个
3楼-- · 2019-07-01 20:47

If that is the text proto if format, then... Whatever, I guess. If it works, then it is as reasonable as any other serialization format.

If that is meant to be proto schema, then it is illegal (the value after the = is meant to be the field number).

Json or XML might be more typical, but as long as it works it isn't "moronic". So the ultimate question is: does it work?

查看更多
登录 后发表回答