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 examples for handling strings and bytes with python bindings #67

Closed
domire8 opened this issue Sep 20, 2023 · 4 comments · Fixed by #70
Closed

Add examples for handling strings and bytes with python bindings #67

domire8 opened this issue Sep 20, 2023 · 4 comments · Fixed by #70
Assignees

Comments

@domire8
Copy link
Member

domire8 commented Sep 20, 2023

As proposed in #66, it would be nice to clarify the usage of the Python bindings regarding the reception and sending of bytes vs strings.

An example snippet could go into the README

@JasperTan97
Copy link
Contributor

JasperTan97 commented Mar 11, 2024

So I am trying to understand what you mean here, but when I do:

    str_msg = "HELLO!"
    server.send_bytes(str_msg)
    str_msg = client.receive_bytes()
    print(str_msg)
    time.sleep(0.4)

I get b'HELLO!' instead of HELLO! as I expected. The additional b' and ' is the issue in question? And that the user should strip away these additional characters that get added when converting c++ strings into python?

The theory is explained as: https://realpython.com/lessons/defining-literal-bytes-object/

@domire8
Copy link
Member Author

domire8 commented Mar 12, 2024

You can have a look at the tests, it is indeed expected that you get b'HELLO!' back. As discussed in #66, it's the responsibility of the receiver to decode and sanitize the bytes

@JasperTan97
Copy link
Contributor

JasperTan97 commented Mar 12, 2024

I understand. Sorry I think I misworded my question. What I meant to ask was, is this what the issue should deal with? I provide examples like this in the readme?

I am not particularly sure what the problem referred to in #66 is exactly. Is it the problem of "extra information" added around a byte literal, that we have decode/sanitize the received data.

@domire8
Copy link
Member Author

domire8 commented Mar 12, 2024

Yeah, the goal is just to provide a code snippet that shows how to use this library.
At the beginning, I thought that if you do send_bytes("hello") then the return value of receive_bytes() should be "hello". However there is no easy and general solution that would enable this so it would be good to say in the README that the user can't expect that and has to decode and strip the return value of receive him/herself

@JasperTan97 JasperTan97 linked a pull request Mar 12, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants