first working implementation

This commit is contained in:
2025-01-31 19:42:29 -06:00
parent fde1f10719
commit 107f5116d5
3 changed files with 106 additions and 0 deletions

22
common.py Normal file
View File

@ -0,0 +1,22 @@
import numpy as np
class Packet:
def __init__(self, x: int, y: int, array: np.ndarray):
self.x = x
self.y = y
self.array = array
def to_bytestr(self) -> bytes:
bytestr = b""
bytestr += self.x.to_bytes(length=4, signed = False)
bytestr += self.y.to_bytes(length=4, signed = False)
bytestr += self.array.tobytes()
return bytestr
def from_bytes(b: bytes) -> Packet:
x = int.from_bytes(b[0:4], signed = False)
y = int.from_bytes(b[4:8], signed = False)
array = np.frombuffer(b[8:], np.uint8).reshape(16, 16, 3)
return Packet(x, y, array)