ts_51_011: Add encoder for EF.SST
We already have those for EF.UST, let's add them for EF.SST, too
Change-Id: Ib51bfffaf8444ec30415aad42e3a0f4f3f7598cb
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 5d1197c..3492a8d 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -505,6 +505,12 @@
def __init__(self, fid, sfid, name, desc, size, table):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
self.table = table
+ @staticmethod
+ def _bit_byte_offset_for_service(service:int) -> (int, int):
+ i = service - 1
+ byte_offset = i//4
+ bit_offset = (i % 4) * 2
+ return (byte_offset, bit_offset)
def _decode_bin(self, raw_bin):
ret = {}
for i in range(0, len(raw_bin)*4):
@@ -518,7 +524,26 @@
'activated': True if bits & 2 else False,
}
return ret
- # TODO: encoder
+ def _encode_bin(self, in_json):
+ # compute the required binary size
+ bin_len = 0
+ for srv in in_json.keys():
+ service_nr = int(srv)
+ (byte_offset, bit_offset) = EF_ServiceTable._bit_byte_offset_for_service(service_nr)
+ if byte_offset >= bin_len:
+ bin_len = byte_offset+1
+ # encode the actual data
+ out = bytearray(b'\x00' * bin_len)
+ for srv in in_json.keys():
+ service_nr = int(srv)
+ (byte_offset, bit_offset) = EF_ServiceTable._bit_byte_offset_for_service(service_nr)
+ bits = 0
+ if in_json[srv]['allocated'] == True:
+ bits |= 1
+ if in_json[srv]['activated'] == True:
+ bits |= 2
+ out[byte_offset] |= ((bits & 3) << bit_offset)
+ return out
# TS 51.011 Section 10.3.11
class EF_SPN(TransparentEF):