laforge submitted this change.

View Change

Approvals: dexter: Looks good to me, approved; Verified Jenkins Builder: Verified
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(-)

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))

To view, visit change 38187. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: I7c4eab60274bcb0dd95e7bc21867a37ad70e4fc0
Gerrit-Change-Number: 38187
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>