1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
from mmtf import converters
from .decoders import delta_decode,run_length_decode
from .encoders import delta_encode,run_length_encode
class DeltaRecursiveFloat():
"""Covert an array of floats to integers, perform delta
encoding and then use recursive indexing to store as 2
byte integers in a byte array."""
@staticmethod
def decode(in_array, param):
return converters.convert_ints_to_floats(
delta_decode(
converters.recursive_index_decode(
converters.convert_bytes_to_ints(in_array,2))),param)
@staticmethod
def encode(in_array, param):
return converters.convert_ints_to_bytes(
converters.recursive_index_encode(
delta_encode(
converters.convert_floats_to_ints(in_array,param))),2)
class RunLengthFloat():
"""Covert an array of floats to integers, perform run-length
encoding and then store as four byte integers in a byte array."""
@staticmethod
def decode(in_array, param):
return converters.convert_ints_to_floats(
run_length_decode(
converters.convert_bytes_to_ints(in_array,4)),param)
@staticmethod
def encode(in_array,param):
return converters.convert_ints_to_bytes(
run_length_encode(
converters.convert_floats_to_ints(in_array,param)),4)
class RunLengthDeltaInt():
"""Delta encode an array of integers and then perform run-length
encoding on this and then store as four byte integers in a byte array."""
@staticmethod
def decode(in_array, param):
return delta_decode(
run_length_decode(
converters.convert_bytes_to_ints(in_array, 4)))
@staticmethod
def encode(in_array,param):
return converters.convert_ints_to_bytes(
run_length_encode(
delta_encode(in_array)),4)
class RunLengthChar():
"""Convert chars to integers and run-length encoode these and then store as
four byte integers in a byte array."""
@staticmethod
def decode(in_array, param):
return converters.convert_ints_to_chars(
run_length_decode(
converters.convert_bytes_to_ints(in_array, 4)))
@staticmethod
def encode(in_array, param):
return converters.convert_ints_to_bytes(
run_length_encode(
converters.convert_chars_to_ints(in_array)),4)
class EncodeString():
"""Convert strings to set length byte arrays (in this case four). If
a string is of lenght less than four a null byte is used instead."""
@staticmethod
def decode(in_array,param):
return converters.decode_chain_list(in_array)
@staticmethod
def encode(in_array,param):
return converters.encode_chain_list(in_array)
class ByteToInt():
"""Convert integers to single bytes and store in byte array."""
@staticmethod
def decode(in_array,param):
return converters.convert_bytes_to_ints(in_array, 1)
@staticmethod
def encode(in_array,param):
return converters.convert_ints_to_bytes(in_array,1)
class FourByteToInt():
"""Convert integers to four bytes and store in byte array."""
@staticmethod
def decode(in_array,param):
return converters.convert_bytes_to_ints(in_array, 4)
@staticmethod
def encode(in_array, param):
return converters.convert_ints_to_bytes(in_array, 4)
|