Skip to content

Commit 657389c

Browse files
author
Konstantin Podshumok
authored
Merge pull request #36 from pespin/pack-big-endian
command: Pack struct in big-endian byte order
2 parents 42ec263 + 2d85cea commit 657389c

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

smpplib/command.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _generate_int(self, field):
168168
fmt = self._pack_format(field)
169169
data = getattr(self, field)
170170
if data:
171-
return struct.pack(fmt, data)
171+
return struct.pack(">" + fmt, data)
172172
else:
173173
return consts.NULL_STRING
174174

@@ -268,9 +268,8 @@ def _parse_int(self, field, data, pos):
268268
Return (data, pos) tuple."""
269269

270270
size = self.params[field].size
271-
field_value = getattr(self, field)
272-
unpacked_data = self._unpack(self._pack_format(field),
273-
data[pos:pos + size])
271+
fmt = self._pack_format(field)
272+
unpacked_data = struct.unpack(">" + fmt, data[pos:pos + size])
274273
field_value = ''.join(map(str, unpacked_data))
275274
setattr(self, field, field_value)
276275
pos += size

smpplib/pdu.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ def parse(self, data):
132132
if len(data) > 16:
133133
self.parse_params(data[16:])
134134

135-
def _unpack(self, fmt, data):
136-
"""Unpack values. Uses struct.unpack. TODO: remove this"""
137-
return struct.unpack(fmt, data)
138-
139135
def generate(self):
140136
"""Generate raw PDU"""
141137

0 commit comments

Comments
 (0)