[S] Change in ...pyosmocom[master]: tlv.py: add bertlv_to_str()
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/44188?usp=email ) Change subject: tlv.py: add bertlv_to_str() ...................................................................... tlv.py: add bertlv_to_str() Elevate the pysim/contrib/unber.py tool to library level. For BF76 unit tests, I want to output BER data in human readable form. For that, I found unber.py. To be able to use its output in unit tests, I want it to be a library function. Here is the best place. Change-Id: I5fd5368c01267de8551d0ad384352971d510935b --- M src/osmocom/tlv.py 1 file changed, 18 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/88/44188/1 diff --git a/src/osmocom/tlv.py b/src/osmocom/tlv.py index ada7380..1aa0103 100644 --- a/src/osmocom/tlv.py +++ b/src/osmocom/tlv.py @@ -22,6 +22,7 @@ from typing import List, Tuple, Optional import osmocom +from osmocom.utils import b2h ######################################################################### # poor man's COMPREHENSION-TLV decoder. @@ -279,6 +280,23 @@ remainder = remainder[length:] return (tag, length, value, remainder) +def bertlv_to_str(content: bytes): + def one_level(content: bytes, indent: int): + res = [] + remainder = content + while len(remainder): + tdict, l, v, remainder = bertlv_parse_one(remainder) + #res.append(str(tdict)) + rawtag = bertlv_encode_tag(tdict) + if tdict['constructed']: + res.append("%s%s l=%d" % (indent*" ", b2h(rawtag), l)) + res.extend(one_level(v, indent + 1)) + else: + res.append("%s%s l=%d %s" % (indent*" ", b2h(rawtag), l, b2h(v))) + return res + + return '\n'.join(one_level(content, 0)) + ######################################################################### # poor man's DGI decoder. ######################################################################### -- To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/44188?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I5fd5368c01267de8551d0ad384352971d510935b Gerrit-Change-Number: 44188 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr@sysmocom.de>
participants (1)
-
neels