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

module msgpack #3659

Merged
merged 36 commits into from Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
90c203a
add module msgpack
Nov 9, 2020
748472d
removed empty line at end of py/circuitpy_mpconfig.mk
Nov 9, 2020
513253b
moved logic to shared-module and added documentation
Nov 10, 2020
e197826
removed blanks to make pre-commit check happy
Nov 10, 2020
912691e
removed blanks line at end of file
Nov 10, 2020
f38bd59
added signatures to documenation
Nov 10, 2020
f91932d
make translate
Nov 12, 2020
44bc75a
output little endian; update example
Nov 12, 2020
b805bf8
cleanup
Nov 12, 2020
a310cde
fixed res may not be initialized in read_size
Nov 13, 2020
4b71079
update translations
Nov 14, 2020
59c3e25
disable on boards tight on memory. add stddef.h to imports (not actua…
Nov 17, 2020
582a47d
rename read, write to read_bytes, write_bytes
Nov 18, 2020
87d4184
exclude spresense
Nov 18, 2020
546b15b
add trailing newline
Nov 18, 2020
34bbcc4
exclude nrf/simmel due to lack of flash
ha-rvc Dec 2, 2020
608c985
Merge remote-tracking branch 'adafruit/main' into msgpack
tannewt Dec 2, 2020
b5b6b6d
add ExtType, update doc, add a test
ha-rvc Dec 7, 2020
534b48f
remove a ~ from doc that causes an error; add ExtType.c to circuitpy_…
ha-rvc Dec 8, 2020
9412c3f
moved misplaced triple-quote
ha-rvc Dec 8, 2020
5875a27
removed extra triple quote
ha-rvc Dec 8, 2020
9903c9e
fixed (?) typespec for callback functions
ha-rvc Dec 8, 2020
413885a
fix typspec in function declarations
ha-rvc Dec 8, 2020
1f14d39
remove two extra closing angular brackets
ha-rvc Dec 8, 2020
9e7a7b9
uglify typing hints
ha-rvc Dec 8, 2020
a5c3dc2
typing ...
ha-rvc Dec 8, 2020
3c72432
cosmetics
ha-rvc Dec 9, 2020
6d2329f
add blank lines after all comment sections
ha-rvc Dec 10, 2020
d29184b
try without ... in docs
ha-rvc Dec 10, 2020
344d3c5
Merge branch 'main' into msgpack
tannewt Dec 11, 2020
c875d7c
speedup pack_bin, ext, str; catch short reads
ha-rvc Dec 20, 2020
79e3c3d
Merge branch 'msgpack' of github.com:iot49/iotpython into msgpack
ha-rvc Jan 5, 2021
90a299b
added //| to (hopefully) get CI to pass
ha-rvc Jan 5, 2021
1a82555
Merge branch 'main' into msgpack
Jan 5, 2021
cdad59f
Fix doc build with extra blank lines
tannewt Jan 6, 2021
13efbf2
disable msgpack on boards without room
FoamyGuy Jan 9, 2021
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
24 changes: 24 additions & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ msgstr ""
msgid "3-arg pow() not supported"
msgstr ""

#: shared-module/msgpack/__init__.c
msgid "64 bit types"
msgstr ""

#: ports/atmel-samd/common-hal/countio/Counter.c
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
msgid "A hardware interrupt channel is already in use"
Expand Down Expand Up @@ -2426,6 +2430,10 @@ msgstr ""
msgid "circle can only be registered in one parent"
msgstr ""

#: shared-bindings/msgpack/ExtType.c
msgid "code outside range 0~127"
msgstr ""

#: shared-bindings/displayio/Palette.c
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)"
msgstr ""
Expand Down Expand Up @@ -2510,6 +2518,10 @@ msgstr ""
msgid "default 'except' must be last"
msgstr ""

#: shared-bindings/msgpack/__init__.c
msgid "default is not a function"
msgstr ""

#: shared-bindings/audiobusio/PDMIn.c
msgid ""
"destination buffer must be a bytearray or array of type 'B' for bit_depth = 8"
Expand Down Expand Up @@ -2609,6 +2621,10 @@ msgstr ""
msgid "expecting key:value for dict"
msgstr ""

#: shared-bindings/msgpack/__init__.c
msgid "ext_hook is not a function"
msgstr ""

#: py/argcheck.c
msgid "extra keyword arguments given"
msgstr ""
Expand Down Expand Up @@ -3141,6 +3157,10 @@ msgstr ""
msgid "no binding for nonlocal found"
msgstr ""

#: shared-module/msgpack/__init__.c
msgid "no default packer"
msgstr ""

#: py/builtinimport.c
msgid "no module named '%q'"
msgstr ""
Expand Down Expand Up @@ -3474,6 +3494,10 @@ msgstr ""
msgid "shape must be a tuple"
msgstr ""

#: shared-module/msgpack/__init__.c
msgid "short read"
msgstr ""

#: py/objstr.c
msgid "sign not allowed in string format specifier"
msgstr ""
Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
MICROPY_PY_ASYNC_AWAIT = 0

SUPEROPT_GC = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_PIXELBUF = 1
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_GAMEPAD = 0
CFLAGS_INLINE_LIMIT = 50
CIRCUITPY_MSGPACK = 0

# Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
# supersized, not ultra-supersized
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0
Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0

SUPEROPT_GC = 0

Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/snekboard/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_BUSDEVICE = 0

Expand Down
2 changes: 2 additions & 0 deletions ports/cxd56/boards/spresense/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ USB_PRODUCT = "Spresense"
USB_MANUFACTURER = "Sony"

INTERNAL_FLASH_FILESYSTEM = 1

CIRCUITPY_MSGPACK = 0
1 change: 1 addition & 0 deletions ports/nrf/boards/pca10100/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_PIXELBUF = 0
Expand Down
1 change: 1 addition & 0 deletions ports/nrf/boards/simmel/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BUSIO = 1
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
Expand Down
6 changes: 6 additions & 0 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ endif
ifeq ($(CIRCUITPY_PEW),1)
SRC_PATTERNS += _pew/%
endif
ifeq ($(CIRCUITPY_MSGPACK),1)
SRC_PATTERNS += msgpack/%
endif

# All possible sources are listed here, and are filtered by SRC_PATTERNS in SRC_COMMON_HAL
SRC_COMMON_HAL_ALL = \
Expand Down Expand Up @@ -412,6 +415,8 @@ $(filter $(SRC_PATTERNS), \
math/__init__.c \
microcontroller/ResetReason.c \
microcontroller/RunMode.c \
msgpack/__init__.c \
msgpack/ExtType.c \
supervisor/RunReason.c \
)

Expand Down Expand Up @@ -481,6 +486,7 @@ SRC_SHARED_MODULE_ALL = \
memorymonitor/AllocationAlarm.c \
memorymonitor/AllocationSize.c \
network/__init__.c \
msgpack/__init__.c \
os/__init__.c \
random/__init__.c \
rgbmatrix/RGBMatrix.c \
Expand Down
8 changes: 8 additions & 0 deletions py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@ extern const struct _mp_obj_module_t wifi_module;
#define WIFI_MODULE
#endif

#if CIRCUITPY_MSGPACK
extern const struct _mp_obj_module_t msgpack_module;
#define MSGPACK_MODULE { MP_ROM_QSTR(MP_QSTR_msgpack), MP_ROM_PTR(&msgpack_module) },
#else
#define MSGPACK_MODULE
#endif

// Define certain native modules with weak links so they can be replaced with Python
// implementations. This list may grow over time.
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
Expand Down Expand Up @@ -830,6 +837,7 @@ extern const struct _mp_obj_module_t wifi_module;
_EVE_MODULE \
MEMORYMONITOR_MODULE \
MICROCONTROLLER_MODULE \
MSGPACK_MODULE \
NEOPIXEL_WRITE_MODULE \
NETWORK_MODULE \
SOCKET_MODULE \
Expand Down
3 changes: 3 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,6 @@ CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
# Enabled micropython.native decorator (experimental)
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)

CIRCUITPY_MSGPACK ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_MSGPACK=$(CIRCUITPY_MSGPACK)
126 changes: 126 additions & 0 deletions shared-bindings/msgpack/ExtType.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Bernhard Boser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "py/runtime.h"
#include "py/smallint.h"
#include "py/objproperty.h"
#include "shared-bindings/msgpack/ExtType.h"

//| class ExtType:
//| """ExtType represents ext type in msgpack."""
//| def __init__(self, code: int, data: bytes) -> None:
//| """Constructor
//| :param int code: type code in range 0~127.
//| :param bytes data: representation."""
//|
STATIC mp_obj_t mod_msgpack_exttype_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mod_msgpack_extype_obj_t *self = m_new_obj(mod_msgpack_extype_obj_t);
self->base.type = &mod_msgpack_exttype_type;
enum { ARG_code, ARG_data };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_code, MP_ARG_INT | MP_ARG_REQUIRED },
{ MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

int code = args[ARG_code].u_int;
if (code < 0 || code > 127) {
mp_raise_AttributeError(translate("code outside range 0~127"));
}
self->code = code;

mp_obj_t data = args[ARG_data].u_obj;
self->data = data;
return MP_OBJ_FROM_PTR(self);
}


//| code: int
//| """The type code, in range 0~127."""
//| ...
//|
STATIC mp_obj_t mod_msgpack_exttype_get_code(mp_obj_t self_in) {
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->code);
}
MP_DEFINE_CONST_FUN_OBJ_1(mod_msgpack_exttype_get_code_obj, mod_msgpack_exttype_get_code);

STATIC mp_obj_t mod_msgpack_exttype_set_code(mp_obj_t self_in, mp_obj_t code_in) {
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
int code = mp_obj_get_int(code_in);
if (code < 0 || code > 127) {
mp_raise_AttributeError(translate("code outside range 0~127"));
}
self->code = code;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_msgpack_exttype_set_code_obj, mod_msgpack_exttype_set_code);

const mp_obj_property_t mod_msgpack_exttype_code_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&mod_msgpack_exttype_get_code_obj,
(mp_obj_t)&mod_msgpack_exttype_set_code_obj,
(mp_obj_t)&mp_const_none_obj},
};

//| data: bytes
//| """Data."""
//| ...
//|
STATIC mp_obj_t mod_msgpack_exttype_get_data(mp_obj_t self_in) {
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
return self->data;
}
MP_DEFINE_CONST_FUN_OBJ_1(mod_msgpack_exttype_get_data_obj, mod_msgpack_exttype_get_data);

STATIC mp_obj_t mod_msgpack_exttype_set_data(mp_obj_t self_in, mp_obj_t data_in) {
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->data = data_in;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_msgpack_exttype_set_data_obj, mod_msgpack_exttype_set_data);

const mp_obj_property_t mod_msgpack_exttype_data_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&mod_msgpack_exttype_get_data_obj,
(mp_obj_t)&mod_msgpack_exttype_set_data_obj,
(mp_obj_t)&mp_const_none_obj},
};

STATIC mp_rom_map_elem_t mod_msgpack_exttype_locals_dict_table[] = {
// Properties
{ MP_ROM_QSTR(MP_QSTR_code), MP_ROM_PTR(&mod_msgpack_exttype_code_obj) },
{ MP_ROM_QSTR(MP_QSTR_data), MP_ROM_PTR(&mod_msgpack_exttype_data_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_msgpack_exttype_locals_dict, mod_msgpack_exttype_locals_dict_table);

const mp_obj_type_t mod_msgpack_exttype_type = {
{ &mp_type_type },
.name = MP_QSTR_ExtType,
.make_new = mod_msgpack_exttype_make_new,
.locals_dict = (mp_obj_dict_t*)&mod_msgpack_exttype_locals_dict,
};
Loading