forked from sportorg/pysport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use default selector in server and client for teamwork
- Loading branch information
Showing
5 changed files
with
198 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import socket | ||
from typing import Optional | ||
|
||
import orjson | ||
|
||
from .packet_header import Header, ObjectTypes, Operations | ||
|
||
|
||
class Command: | ||
def __init__( | ||
self, | ||
data=None, | ||
op=Operations.Update.name, | ||
sender: Optional[socket.socket] = None, | ||
): | ||
self.data = data | ||
self.header = Header(data, op) | ||
self.next_cmd_obj_type = ObjectTypes.Unknown.value | ||
self._sender = sender | ||
|
||
def __repr__(self) -> str: | ||
return str(self.data) | ||
|
||
def is_sender(self, sender: socket.socket) -> bool: | ||
return self._sender is sender | ||
|
||
def get_packet(self) -> bytes: | ||
pack_data = orjson.dumps(self.data) | ||
return self.header.pack_header(len(pack_data)) + pack_data |
Oops, something went wrong.