java - Using Protobuf to process a config file -


i'm relatively new protobufs , wondering how use process list of structures.

lets have configuration file looks this:

bucket{     name = "a";     path = "~/document/...";     traffic = 5; } bucket{     name = "b";     path = "~/document/...";     traffic = 6; } bucket{     name = "c";     path = "~/document/...";     traffic = 7; } 

etc etc.

so using protobuf structure ease of use later in java. i'm trying make map in map (a protobuf find correct bucket, , map obtain member attributes inside bucket).

option java_outer_classname = "buckets";  message bucket {     required string name = 1;     required string path = 2;     optional int32 traffic = 3; }  message bucketlist {     required bucket bucket = 1; } 

i'm confused on how link two, in, how pass configuration file protobuf methods (after compiles java class) , use to access bucket member stuff path bucket name a?

thank you!

you've got wrong idea of protobuf used for, data interchange library means used encode , exchange data between programs. never meant used configuration , doesn't have way read text-based definition of data since deals binary files.

looking @ config format have 2 options:

  1. the format you've chosen looks lot hocon, https://github.com/typesafehub/config should able read , provide readable config object small amount of editing.
  2. if want type-safe config (defining structure of config actual java object) need use other format supports deserialization object. json configuration can read objects using libraries https://github.com/google/gson or https://github.com/fasterxml/jackson