text format serialization and deserialization
timotheecour opened this issue · comments
Timothee Cour commented
text format is very useful for debugging, or for cross language, human readable,, type safe, configuration files:
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format
example of text format
https://github.com/BVLC/caffe/blob/master/models/bvlc_reference_caffenet/solver.prototxt
usage
let message = newTest1()
message.a = 150
## serialize
let data = protoToText(message)
echo data # a : 150
echo message # would use `$` as alias to serializeText
## deserialize
let message2 = Test1.deserializeText(data)
assert message2 == message
## serialize with option
let data = serializeText(message, oneline = false)
WORKAROUND
same as msoucy/dproto#71 (comment) : shell out to protoc eg:
## serializeText
serialize message to /tmp/z01.pb
protoc --decode=Test1 --proto_path=tests/t29_nimpb/ tests/t29_nimpb/test1.proto < /tmp/z01.pb > /tmp/z01.txt
read /tmp/z01.txt
## deserializeText
TODO
workaround is not great, as not as efficient, and requires passing the proto file; the proper solution should involve using reflection
Oskari Timperi commented
This could be a nice addition. Need to take a look at some point.