Created
March 11, 2021 21:07
-
-
Save lewoudar/448dbd057414dd4965c27ed4599dfa41 to your computer and use it in GitHub Desktop.
An example showing how to manipulate a kifurushi packet
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
import socket | |
import enum | |
from kifurushi import Packet, ShortField, ByteField, IntEnumField | |
HOST = 'disney-stuff.com' | |
PORT = 14006 | |
class Mood(enum.Enum): | |
happy = 1 | |
cool = 2 | |
angry = 4 | |
class Disney(Packet): | |
__fields__ = [ | |
ShortField('mickey', 2), | |
ByteField('minnie', 3, hex=True), | |
IntEnumField('donald', 1, Mood) | |
] | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
disney = Disney() | |
s.connect((HOST, PORT)) | |
disney.donald = Mood.cool.value | |
# we send the packet data | |
s.sendall(disney.raw) | |
# we create another packet object from raw bytes | |
received_packet = Disney.from_bytes(s.recv(1024)) | |
print(received_packet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment