-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
msgpack not choosing type correctly #6851
Comments
@bboser @iot49 of interest to you |
I'm poking around in the |
I looked at it briefly when somebody brought it up on discord a few weeks ago, it's an issue that msgpack can't really decode what is encoded by C python. I think adding uints is straightforward, but there's 64 bit types to support too, including doubles which is the default that C-python uses for encoding floats it seems. circuitpython/shared-module/msgpack/__init__.c Lines 485 to 490 in 884371f
|
Python does not have native uint's - hence the encoder never generates them in the output. The decoder converts received uint's to int's. You may consider adding special encoders (e.g. pack_uint) to serve your purpose. |
Yes, that would be a bug. I have no time to fix right now. |
To be more accurate when I say that, a simple (uint*_t) cast works for ints that fit in a CP int (below
Note that C-Python does use uint for positive ints in msgpack. A matter of implementation choices I guess. I don't think we need it in CP because it's more code that does not add functionality, it only makes the packing potentially smaller. ❯ python
Python 3.9.6 (default, Aug 11 2021, 01:29:00)
>>> import msgpack
>>> msgpack.packb(151)
b'\xcc\x97' Versus |
CircuitPython version
Code/REPL
Behavior
Output in CircuitPython is
b'\xd1\x00\x91'
, which is anint16
, but this is encoded on unix asb'\xcc\x91'
, which is auint8
. The value is < 255 and positive, so I think it should be a uint8. Additionally, CircuitPython decodesb'\xcc\x91'
as -111, which I'm pretty sure is incorrect per the msgpack spec.Description
This causes problems for passing msgpack'd data back and forth between the two platforms. I recompiled the firmware with different pin definitions, but I don't think that is the issue.
Additional information
No response
The text was updated successfully, but these errors were encountered: