Re:NestedText, a nice alternative to JSON, YAML, TOML
by zmj on Saturday October 03, 2020 @06:11PM
(#24675063)
Protobufs have a text representation.
[ Parent
| on HN ]
Re:NestedText, a nice alternative to JSON, YAML, TOML
by andrewg on Saturday October 03, 2020 @06:23PM
(#24675124)
Yes indeed - it's actually pretty nice. You just define a message for your configuration schema:
message Config {
repeated Server server = 1;
}
message Server {
string address = 1;
int32 port = 2;
bool standby = 3;
}
And then you use the text representation in a config file: # main instance
server { address: "127.0.0.1" port: 4567 }
# backup instance
server { address: "127.0.0.1" port: 9876 standby: true }
And load it into a message instance: Config config;
google::protobuf::TextFormat::ParseFromString(input, &config);
Re:NestedText, a nice alternative to JSON, YAML, TOML
by atombender on Sunday October 04, 2020 @01:26AM
(#24676706)
Unfortunately, it is undocumented and has no formal spec, and this appears to be intentional, with no plans for improvement: https://github.com/protocolbuffers/protobuf/issues/3755.
Re:NestedText, a nice alternative to JSON, YAML, TOML
by kortex on Saturday October 03, 2020 @09:34PM
(#24675992)
Wow, I use pb's a ton and didn't know this. I'd upvote this twice if I could!
It looks oddly like HCL. I wonder...
Re:NestedText, a nice alternative to JSON, YAML, TOML
by quietbritishjim on Saturday October 03, 2020 @11:36PM
(#24676359)
As of protobuf 3 they also have a canonical JSON representation, which you can access from all the supported languages.