Working on ustruct

This commit is contained in:
2026-03-17 17:40:53 +00:00
parent 79a992ac72
commit c1808cfa75

View File

@@ -830,6 +830,27 @@ class UStructTest:
self.failedtests = {} self.failedtests = {}
def print_results(self): def print_results(self):
packed = struct.pack('ii', 42, 100)
print(f'Packed bytes using pack(): {packed}')
unpacked = struct.unpack('ii', packed)
print(f'Unpacked values using unpack(): {unpacked}')
print(unpacked == (42, 100))
format_string = 'hhl'
size = struct.calcsize(format_string)
buffer = bytearray(size)
struct.pack_into(format_string, buffer, 0, 5, 10, 15)
print("Packed buffer using pack_into():", buffer)
unpackedfrom = struct.unpack_from(format_string, buffer, 0)
print("Unpacked buffer using unpack_from():", unpackedfrom)
if(unpackedfrom == (5, 10, 15)):
print("Completed Test 2/2: pack_into - SUCCESSFUL")
else:
print("Completed Test 2/2: pack_into - FAILED")
print(f"\n=== Results: {self.successfultests}/0 tests passed ===") print(f"\n=== Results: {self.successfultests}/0 tests passed ===")
if self.failedtests: if self.failedtests:
print("Failed tests:") print("Failed tests:")