mardi 15 mai 2018

Exposing serialization functions in Python

What is the preferred way to expose binary serialization functions in Python?

I sometimes use or write parsers for binary serialization and I encountered several ways to expose serialization/deserialization functions:

Here is a prototype of a Message object with the above-mentionned functions:

class Message(object):

    @staticmethod
    def dumps(obj):
        pass

    @staticmethod
    def loads(bytes_object):
        pass

    def __bytes__(self):
        pass

    @classmethod
    def from_bytes(cls, bytes_object):
        pass

    def serialize(self):
        pass

    @classmethod
    def deserialize(cls, bytes_object):
        pass

Is there a preferred technique? If not, which one is more common?

Aucun commentaire:

Enregistrer un commentaire