protobuf-nim icon indicating copy to clipboard operation
protobuf-nim copied to clipboard

generated API should be generic, eg: stream.readExampleMessage => stream.toProto(ExampleMessage)

Open timotheecour opened this issue 7 years ago • 4 comments
trafficstars

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

timotheecour avatar Apr 02 '18 03:04 timotheecour

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.

PMunch avatar Apr 02 '18 12:04 PMunch

in the meantime https://github.com/PMunch/protobuf-nim/issues/12 would mitigate this

timotheecour avatar Apr 02 '18 22:04 timotheecour

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.

PMunch avatar Apr 03 '18 08:04 PMunch

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

timotheecour avatar Apr 06 '18 05:04 timotheecour