Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format for bytes objects #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions PyCmdMessenger/PyCmdMessenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self,
"f":self._send_float,
"d":self._send_double,
"s":self._send_string,
"B":self._send_bytes,
"?":self._send_bool,
"g":self._send_guess}

Expand All @@ -114,6 +115,7 @@ def __init__(self,
"f":self._recv_float,
"d":self._recv_double,
"s":self._recv_string,
"B":self._recv_bytes,
"?":self._recv_bool,
"g":self._recv_guess}

Expand Down Expand Up @@ -497,6 +499,16 @@ def _send_string(self,value):

return value

def _send_bytes(self,value):
"""
Convert value to a bytes object using the standard constructor.
"""

if type(value) != bytes:
value = bytes(value)

return value

def _send_bool(self,value):
"""
Convert a boolean value into a bytes object. Uses 0 and 1 as output.
Expand Down Expand Up @@ -600,6 +612,13 @@ def _recv_string(self,value):

return s

def _recv_bytes(self,value):
"""
Recieve a binary (bytes) string, return it unchanged.
"""

return value

def _recv_bool(self,value):
"""
Receive a binary bool, return as python bool.
Expand Down