Adding custom methods in Python

24 views
Skip to first unread message

Michael Armida

unread,
Jun 28, 2016, 4:16:04 PM6/28/16
to FlatBuffers

Regarding the Python integration, is there a way to extend the behavior of the classes generated from a schema file? For example, a way to extend those classes to add methods in a child class, or to add a mix-in class?


A proper solution would ensure that custom behaviors are associated with objects loaded from a message, and conversely, would not interfere with the serialization of an object to a message.

Wouter van Oortmerssen

unread,
Jun 29, 2016, 12:49:47 PM6/29/16
to Michael Armida, FlatBuffers
The classes generated from the schema are nothing more than offsets into a buffer, meant to make it easy to access the data.

You could subclass them, but since they're returned from generated code, that wouldn't do you much good. If you want to add functionality to them, the only way would be by wrapping them, or use plain functions.

On Tue, Jun 28, 2016 at 1:16 PM, Michael Armida <m...@marmida.com> wrote:

Regarding the Python integration, is there a way to extend the behavior of the classes generated from a schema file? For example, a way to extend those classes to add methods in a child class, or to add a mix-in class?


A proper solution would ensure that custom behaviors are associated with objects loaded from a message, and conversely, would not interfere with the serialization of an object to a message.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Rene Armida

unread,
Jun 29, 2016, 4:07:29 PM6/29/16
to Wouter van Oortmerssen, FlatBuffers
Is there any way to add to the generated code reliably and consistently? Or to get the generated code to include a class as a mixin?

Wouter van Oortmerssen

unread,
Jul 1, 2016, 1:18:03 PM7/1/16
to Michael Rene Armida, FlatBuffers
There's no explicit functionality to add to the generated code, no, beyond what Python already allows.
Reply all
Reply to author
Forward
0 new messages