Skip to content

Commit 55556a6

Browse files
author
MarcoFalke
committed
test: Remove struct import from messages.py
1 parent fa3fa86 commit 55556a6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

test/functional/test_framework/messages.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import math
2626
import random
2727
import socket
28-
import struct
2928
import time
3029
import unittest
3130

@@ -92,11 +91,11 @@ def ser_compact_size(l):
9291
if l < 253:
9392
r = l.to_bytes(1, "little")
9493
elif l < 0x10000:
95-
r = struct.pack("<BH", 253, l)
94+
r = (253).to_bytes(1, "little") + l.to_bytes(2, "little")
9695
elif l < 0x100000000:
97-
r = struct.pack("<BI", 254, l)
96+
r = (254).to_bytes(1, "little") + l.to_bytes(4, "little")
9897
else:
99-
r = struct.pack("<BQ", 255, l)
98+
r = (255).to_bytes(1, "little") + l.to_bytes(8, "little")
10099
return r
101100

102101

@@ -1635,12 +1634,12 @@ def __init__(self, announce=False, version=1):
16351634
self.version = version
16361635

16371636
def deserialize(self, f):
1638-
self.announce = struct.unpack("<?", f.read(1))[0]
1637+
self.announce = bool(int.from_bytes(f.read(1), "little"))
16391638
self.version = int.from_bytes(f.read(8), "little")
16401639

16411640
def serialize(self):
16421641
r = b""
1643-
r += struct.pack("<?", self.announce)
1642+
r += int(self.announce).to_bytes(1, "little")
16441643
r += self.version.to_bytes(8, "little")
16451644
return r
16461645

0 commit comments

Comments
 (0)