laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/38187?usp=email )
Change subject: Allow caller to pass total_len in context of osmocom.construct.build_construct ......................................................................
Allow caller to pass total_len in context of osmocom.construct.build_construct
The current code hard-coded 'total_len' as None during build_construct, which prevented the caller from passing a different value in the context. Let's change it in a way that the default remains None, but the caller can override it. This is useful for pySim size computations that depend on the target size of the file/record.
Change-Id: I7c4eab60274bcb0dd95e7bc21867a37ad70e4fc0 --- M src/osmocom/construct.py 1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/87/38187/1
diff --git a/src/osmocom/construct.py b/src/osmocom/construct.py index 8f01f3c..def5d85 100644 --- a/src/osmocom/construct.py +++ b/src/osmocom/construct.py @@ -492,7 +492,8 @@
def build_construct(c, decoded_data, context: dict = {}): """Helper function to handle total_len.""" - return c.build(decoded_data, total_len=None, **context) + context.setdefault('total_len', None) + return c.build(decoded_data, **context)
# here we collect some shared / common definitions of data types LV = Prefixed(Int8ub, HexAdapter(GreedyBytes))