msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

Feature request: make the tag ids of message members knowable #57

Closed cporter closed 8 years ago

cporter commented 9 years ago

I have a project where I'm assembling messages by hand. (Don't ask.) For this I need to know the values of some of the tags. It's better to have it available in code than to try to keep source and .proto files up to date. (Even though the tag numbers should never change.)

msoucy commented 9 years ago

Saying "don't ask" makes me even more curious. But jokes aside, I'd like to have a use case posted, at the very least for documentation?

cporter commented 8 years ago

Let's say you have a type of message A that you're storing as a blob in a database. You want to create a repeated field of type A out of those blobs, but you don't want to deserialize and then re-serialize them. If you know the tag number of the repeated type you can construct the serialized repeated message by hand and save yourself the cost of running each A through an object. The advantage of going to the trouble rather than sending the blobs as one concatenated bytes array with a list of lengths for each is that whoever is reading the message can treat it as a normal repeated field.

msoucy commented 8 years ago

That sounds reasonable, I hadn't quite thought of that. Give me a few minutes to take care of some things and we should be good to go.

denizzzka commented 8 years ago

Agreed with that! protobuf have not just a markers of message members, but count numbers (ids) too then it's needs to add possibility to use it!