CBOR support? #15406
Replies: 8 comments
-
Related: #4241 |
Beta Was this translation helpful? Give feedback.
-
I would recommend first trying to build this as a dynamically loadable native module. There are lots of examples (and some documentation) to help get started, see the |
Beta Was this translation helpful? Give feedback.
-
I think I have most of this module sorted, but I'm a bit stuck on iterating through a dictionary in a native module; I basically need to have the As far as I can tell from looking at the My current implementation (not finished) is here: https://github.com/jeremyherbert/micropython/blob/3a41f2e935fb33f070b77ad77fc3bd2488d4d922/examples/natmod/ucbor/ucbor.c related to #5643 |
Beta Was this translation helpful? Give feedback.
-
The way to access an iterator using the current code is something like this: mp_obj_t dest[2];
mp_fun_table.load_method(dict_obj, MP_QSTR_items, dest);
mp_obj_t dict_iter = mp_fun_table.call_method_n_kw(0, 0, dest);
mp_obj_iter_buf_t iter_buf;
mp_fun_table.getiter(dict_iter, &iter_buf);
mp_obj_t item;
while ((item = mp_fun_table.iternext(&iter_buf)) != MP_OBJ_NULL) {
// use item
} |
Beta Was this translation helpful? Give feedback.
-
Thanks, got it sorted. I think the CBOR module is done now, so I would appreciate a review if possible. Would also like to hear your thoughts on how to take this forward (is there a folder in the source tree for native modules, should I keep this in a separate repo or should this be added into the
changes to |
Beta Was this translation helpful? Give feedback.
-
@jeremyherbert Thanks for the effort to implementing cbor in micropython. |
Beta Was this translation helpful? Give feedback.
-
Dynamic native modules can be built standalone and loaded at runtime as a .mpy file. So there is no need to merge it into the MicroPython repository, but can be done in a standalone repo. Such a project would ideally provide pre-build .mpy files that people can download directly to their devices. See https://github.com/emlearn/emlearn-micropython for one example of this. |
Beta Was this translation helpful? Give feedback.
-
There's a reasonable Python-based, mip-installable ( |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It seems that micropython has great support for JSON, but there seems to be not much for CBOR. CBOR is like json but is binary encoded so it is faster, and supports typing of fields (for example, it makes a distinction between byte strings and text strings). It also is very well standardised under RFC 7049: https://tools.ietf.org/html/rfc7049
I personally have found it much more useful than json for sending data over serial links because I don’t need to constantly base64 encoded and decode binary data.
I propose adding a module which wraps the https://github.com/intel/tinycbor library, which is used in a lot of embedded frameworks (mbed, RIOT, etc) which can be added in with a #define. Is this something which is likely to be accepted as a pull request, given that it would add in a new binary library?
Beta Was this translation helpful? Give feedback.
All reactions