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

Bytestrings (ay) #5

Open
LEW21 opened this issue Sep 28, 2016 · 1 comment
Open

Bytestrings (ay) #5

LEW21 opened this issue Sep 28, 2016 · 1 comment

Comments

@LEW21
Copy link

LEW21 commented Sep 28, 2016

Hi,

I'm the creator of pydbus, DBus bindings for Python. I've stumbled upon the case of bytestrings - ay - which are commonly used to send non-Unicode data over DBus.

Because of the GDBus's API, apps commonly require these strings to be '\0'-terminated. And that's completely unintuitive for high-level languages, and something that requires the user to read API docs.

I'm thinking about solving the problem automatically, and I see two solutions:

  1. Auto-append and auto-strip the last character of "ay"s; [EDIT: impossible, some APIs use not-terminated strings]
  2. Decree (how?) that GDBus API is wrong, and strings sent over the wire should not be \0-terminated.
  3. [EDIT:] Create a new DBus annotation meaning "All "ay"s in the arguments of this method/signal are \0-terminated bytestrings" - and auto-append/auto-strip \0 if it's present.

Whatever we choose, the solution should be agreed upon by authors of bindings for all languages. That's why I'm here.

Do you have any experience with "ay"-encoded bytestrings?

Relevant discussion: LEW21/pydbus#27 (please reply there, I've opened similar issues in 8 different projects to get attention of bindings authors)

@ghost
Copy link

ghost commented Sep 29, 2016

Note that obus is a pure OCaml implementation so it doesn't suffer from this problem. Values of D-Bus type ay are represented by obus as strings, which in OCaml are just array of bytes that can contain NUL bytes.

I looked at the C API and GDBus a while ago. I don't remember all the details, but requiring NUL-terminated strings for ay values is plain wrong IMO. ay values are supposed to be array of bytes so one shouldn't use NUL-terminated strings to represent them. It seems to me that the GDBus API should be updated to represent ay values as arbitrary array of bytes.

Alternatively, if there is a real need for passing NUL-terminated strings that are not UTF-8 encoded, then maybe it should be considered to add a D-Bus type for these. But that'd be really C-centric.

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

No branches or pull requests

1 participant