Source code for emod_api.serialization.dtkFileSupport

#!/usr/bin/python

import lz4.block

try:
    import snappy
    SNAPPY_SUPPORT = True
except:
    SNAPPY_SUPPORT = False


# noinspection PyCamelCase
[docs]class Uncompressed(object):
[docs] @classmethod def compress(cls, data): return data
[docs] @classmethod def uncompress(cls, data): return data
[docs]class EllZeeFour(object):
[docs] @classmethod def compress(cls, data): return lz4.block.compress(data if type(data) is bytes else data.encode())
[docs] @classmethod def uncompress(cls, data): return lz4.block.decompress(data)
[docs]class Snappy(object):
[docs] @classmethod def compress(cls, data): if SNAPPY_SUPPORT: return snappy.compress(data) raise UserWarning("Snappy [de]compression not available.")
[docs] @classmethod def uncompress(cls, data): if SNAPPY_SUPPORT: return snappy.uncompress(data) raise UserWarning("Snappy [de]compression not available.")
[docs]class SerialObject(dict): # noinspection PyDefaultArgument def __init__(self, dictionary={}): super(SerialObject, self).__init__(dictionary) self.__dict__ = self return
[docs]class NullPtr(SerialObject): def __init__(self): nullptr = {'__class__': 'nullptr'} super(NullPtr, self).__init__(nullptr)