oskaritimperi / nimpb

Protocol Buffers for Nim
MIT License
38 stars 6 forks source link

API design discussion #3

Closed timotheecour closed 6 years ago

timotheecour commented 6 years ago

on API side, I much prefer the way it's done in dproto ; that one is in D but IMO should be doable in nim too:

instead of:

let message = newTest1()
setA(message, 150)
let pbso = newProtobufStream(newFileStream(stdout))
writeTest1(pbso, message)

we could have:

let message = newTest1()
message.a = 150
assert message.a == 150
auto serializedObject = message.serialize();
auto message2 = newTest1(serializedObject);
assert message2 == message

and more generally for more complex example, see example in their readme

oskaritimperi commented 6 years ago

Thank you for the suggestions!

Setting fields with the message.a = 150 syntax is definitely something that we should have.

And I think that serialize proc makes it easier for the user and it can be implemented using the current stream implementation very easily.

I'll have to dig their implementation more. Thanks for the pointer!

oskaritimperi commented 6 years ago

This simple attribute setting syntax and serialize/newMessage(data) have been implemented.