forked from public/pysim
sms: don't mutate digits in AddressField.to_bytes()
to_bytes() appended the BCD filler nibble, so the next call saw one digit more and derived a wrong length. This affects any code that encodes an address twice, even for printing/logging. Man, I really miss my beloved c++ const function decoration... Fix: keep the filler in a local. Change-Id: I81691c5a1fc5072d6d20c52d22da1eb2e180d04a
This commit is contained in:
+3
-3
@@ -246,8 +246,8 @@ class AddressField:
|
|||||||
def to_bytes(self) -> bytes:
|
def to_bytes(self) -> bytes:
|
||||||
"""Encode the AddressField into the binary representation as used in T-PDU."""
|
"""Encode the AddressField into the binary representation as used in T-PDU."""
|
||||||
num_digits = len(self.digits)
|
num_digits = len(self.digits)
|
||||||
if num_digits % 2:
|
# don't store the filler nibble or get_bytes() encodes it as digit and ends up too large
|
||||||
self.digits += 'f'
|
digits = self.digits + 'f' if num_digits % 2 else self.digits
|
||||||
d = {
|
d = {
|
||||||
'addr_len': num_digits,
|
'addr_len': num_digits,
|
||||||
'type_of_addr': {
|
'type_of_addr': {
|
||||||
@@ -255,7 +255,7 @@ class AddressField:
|
|||||||
'type_of_number': self.ton,
|
'type_of_number': self.ton,
|
||||||
'numbering_plan_id': self.npi,
|
'numbering_plan_id': self.npi,
|
||||||
},
|
},
|
||||||
'digits': self.digits,
|
'digits': digits,
|
||||||
}
|
}
|
||||||
return self._construct.build(d)
|
return self._construct.build(d)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user