first working implementation
This commit is contained in:
22
common.py
Normal file
22
common.py
Normal 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)
|
Reference in New Issue
Block a user