2 ms·
I see, the point is that you want to extend someone else's protocol, without their cooperation, and without conflicting with any future protocol changes they ma
by kentonv 7y ago
I see, the point is that you want to extend someone else's protocol, without their cooperation, and without conflicting with any future protocol changes they make.
That is indeed tricky. With protobuf you could claim some high-numbered fields and hope that no one else does the same thing -- with some randomization you can probably be pretty confident. With Cap'n Proto you can't really do it at all since fields are identified by offset, and making structs arbitrarily large is probably not what you want. With JSON, because fields are identified by name, it's possible to choose a name that almost certainly will not collide with anyone else.
I'd argue that the right answer here would be to ask the spec owners to add extension points, which hopefully would not be controversial. Conceptually this could take the form of something like map<string, any> (there are cleaner idiomatic ways to do it in each of Protobuf and Cap'n Proto but the details are beside the point of this conversation).