Is there a way to add some functionality to class methods, generated by protocol buffers? The goal is to be able to add message to .proto file, and then automatically generate a class which is sent over network on each data change (e.g. network exchange can be managed by some custom class written in advance with the same peer on another end). To achieve this I will need at least to generate some custom code in set_ methods which calls some predefined callback to notify that buffer is changed.
No, that isn't supported. The accessors are all inline methods, not virtual, so you can't override them.
You could consider writing a custom code generator which generates wrappers around each type with additional setter logic. Basically you would write a code generator plugin as if you were trying to support a new language, but you'd actually output C++ code which #includes the regular C++ output and defines the wrapper types. See:
https://developers.google.com/protocol-buffers/docs/reference/other
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With