mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-17 02:48:34 +03:00
filesystem: Introduce 'construct' support
This allows for pure declarative encoders/decoders for linear fixed and transparent EFs. Change-Id: Id0765ec3ddb8c044838ce47d0ff8740720a32b15
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from construct import *
|
||||
from pySim.utils import b2h, h2b
|
||||
from pySim.utils import b2h, h2b, swap_nibbles
|
||||
|
||||
"""Utility code related to the integration of the 'construct' declarative parser."""
|
||||
|
||||
@@ -26,6 +26,13 @@ class HexAdapter(Adapter):
|
||||
def _encode(self, obj, context, path):
|
||||
return h2b(obj)
|
||||
|
||||
class BcdAdapter(Adapter):
|
||||
"""convert a bytes() type to a string of BCD nibbles."""
|
||||
def _decode(self, obj, context, path):
|
||||
return swap_nibbles(b2h(obj))
|
||||
def _encode(self, obj, context, path):
|
||||
return h2b(swap_nibbles(obj))
|
||||
|
||||
def filter_dict(d, exclude_prefix='_'):
|
||||
"""filter the input dict to ensure no keys starting with 'exclude_prefix' remain."""
|
||||
res = {}
|
||||
|
||||
Reference in New Issue
Block a user