protobuf-nim
protobuf-nim copied to clipboard
generated API should be generic, eg: stream.readExampleMessage => stream.toProto(ExampleMessage)
stream.readExampleMessage (as in https://github.com/PMunch/protobuf-nim/blob/master/README.rst) is not generic (eg can't be used in generic code), and also pollutes namespace with all the generated symbols.
Instead of stream.readExampleMessage how about:
option 1: stream.toProto(ExampleMessage) (preferred)
option 2: stream.toProto[ExampleMessage]
see https://github.com/nim-lang/Nim/issues/7430#issuecomment-377412261 for related discussion between option 1 vs option 2 (option 1 should be preferred)
NOTE: not sure if API generates other non-generic symbols such as readExampleMessage but same comment would apply
Well, that API is intended to be consistent with the streams module API. I agree that having to (from the linked issue) would be a good idea, and to extend that I would love to see a generic read in the streams module as well. What I can do is of course add a generic read procedure. It won't mitigate the name pollution though.
in the meantime https://github.com/PMunch/protobuf-nim/issues/12 would mitigate this
I've made a PR to the streams module adding the generic read procedure. If that get's accepted I will add this in for sure.
you gave wrong link in https://github.com/PMunch/protobuf-nim/issues/10#issuecomment-378174379 , shd be https://github.com/nim-lang/Nim/pull/7481