<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/25872">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">tlv: Don't require encoder/decoder methods for TLV without value<br><br>There are instances where a TLV IE is used as just a flag, i.e.<br>length zero and no value part.  In those situations, it would require<br>a lot of boilerplate code to require the TLV_IE class definitions to<br>have _to_bytes/_from_bytes methods that do nothing.<br><br>So instead, add a shortcut: If we want to encode 'None', then return<br>b'', and if we want to decode b'' return None.<br><br>Change-Id: Ie8eb2830e8eefa81e94b8b8b157062c085aeb777<br>---<br>M pySim/tlv.py<br>1 file changed, 6 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/72/25872/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/tlv.py b/pySim/tlv.py</span><br><span>index 05f824e..0dc746b 100644</span><br><span>--- a/pySim/tlv.py</span><br><span>+++ b/pySim/tlv.py</span><br><span>@@ -80,7 +80,9 @@</span><br><span>     def to_bytes(self) -> bytes:</span><br><span>         """Convert from internal representation to binary bytes.  Store the binary result</span><br><span>         in the internal state and return it."""</span><br><span style="color: hsl(0, 100%, 40%);">-        if self._construct:</span><br><span style="color: hsl(120, 100%, 40%);">+        if not self.decoded:</span><br><span style="color: hsl(120, 100%, 40%);">+            do = b''</span><br><span style="color: hsl(120, 100%, 40%);">+        elif self._construct:</span><br><span>             do = self._construct.build(self.decoded, total_len=None)</span><br><span>         elif self.__class__._construct:</span><br><span>             do = self.__class__._construct.build(self.decoded, total_len=None)</span><br><span>@@ -97,7 +99,9 @@</span><br><span>         """Convert from binary bytes to internal representation. Store the decoded result</span><br><span>         in the internal state and return it."""</span><br><span>         self.encoded = do</span><br><span style="color: hsl(0, 100%, 40%);">-        if self._construct:</span><br><span style="color: hsl(120, 100%, 40%);">+        if self.encoded == b'':</span><br><span style="color: hsl(120, 100%, 40%);">+            self.decoded = None</span><br><span style="color: hsl(120, 100%, 40%);">+        elif self._construct:</span><br><span>             self.decoded = parse_construct(self._construct, do)</span><br><span>         elif self.__class__._construct:</span><br><span>             self.decoded = parse_construct(self.__class__._construct, do)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/25872">change 25872</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/25872"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ie8eb2830e8eefa81e94b8b8b157062c085aeb777 </div>
<div style="display:none"> Gerrit-Change-Number: 25872 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>