nimpb icon indicating copy to clipboard operation
nimpb copied to clipboard

text format serialization and deserialization

Open timotheecour opened this issue 7 years ago • 1 comments

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 https://github.com/msoucy/dproto/issues/71#issuecomment-365172146 : 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

timotheecour avatar May 08 '18 21:05 timotheecour

This could be a nice addition. Need to take a look at some point.

oskaritimperi avatar May 09 '18 16:05 oskaritimperi