using protobuf as a textual configuraton file

浪子不回头ぞ 提交于 2019-12-23 18:53:25

问题


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 ?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/12873653/using-protobuf-as-a-textual-configuraton-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!