Skip to content

Commit 9124529

Browse files
authored
Merge pull request #3659 from iot49/msgpack
module msgpack
2 parents 1fb3d24 + 13efbf2 commit 9124529

File tree

27 files changed

+952
-0
lines changed

27 files changed

+952
-0
lines changed

locale/circuitpython.pot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ msgstr ""
276276
msgid "3-arg pow() not supported"
277277
msgstr ""
278278

279+
#: shared-module/msgpack/__init__.c
280+
msgid "64 bit types"
281+
msgstr ""
282+
279283
#: ports/atmel-samd/common-hal/countio/Counter.c
280284
#: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c
281285
msgid "A hardware interrupt channel is already in use"
@@ -2426,6 +2430,10 @@ msgstr ""
24262430
msgid "circle can only be registered in one parent"
24272431
msgstr ""
24282432

2433+
#: shared-bindings/msgpack/ExtType.c
2434+
msgid "code outside range 0~127"
2435+
msgstr ""
2436+
24292437
#: shared-bindings/displayio/Palette.c
24302438
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)"
24312439
msgstr ""
@@ -2510,6 +2518,10 @@ msgstr ""
25102518
msgid "default 'except' must be last"
25112519
msgstr ""
25122520

2521+
#: shared-bindings/msgpack/__init__.c
2522+
msgid "default is not a function"
2523+
msgstr ""
2524+
25132525
#: shared-bindings/audiobusio/PDMIn.c
25142526
msgid ""
25152527
"destination buffer must be a bytearray or array of type 'B' for bit_depth = 8"
@@ -2609,6 +2621,10 @@ msgstr ""
26092621
msgid "expecting key:value for dict"
26102622
msgstr ""
26112623

2624+
#: shared-bindings/msgpack/__init__.c
2625+
msgid "ext_hook is not a function"
2626+
msgstr ""
2627+
26122628
#: py/argcheck.c
26132629
msgid "extra keyword arguments given"
26142630
msgstr ""
@@ -3141,6 +3157,10 @@ msgstr ""
31413157
msgid "no binding for nonlocal found"
31423158
msgstr ""
31433159

3160+
#: shared-module/msgpack/__init__.c
3161+
msgid "no default packer"
3162+
msgstr ""
3163+
31443164
#: py/builtinimport.c
31453165
msgid "no module named '%q'"
31463166
msgstr ""
@@ -3474,6 +3494,10 @@ msgstr ""
34743494
msgid "shape must be a tuple"
34753495
msgstr ""
34763496

3497+
#: shared-module/msgpack/__init__.c
3498+
msgid "short read"
3499+
msgstr ""
3500+
34773501
#: py/objstr.c
34783502
msgid "sign not allowed in string format specifier"
34793503
msgstr ""

ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
1414
CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_COUNTIO = 0
1616
CIRCUITPY_I2CPERIPHERAL = 0
17+
CIRCUITPY_MSGPACK = 0
1718
CIRCUITPY_VECTORIO = 0
1819
CIRCUITPY_BUSDEVICE = 0
1920

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ LONGINT_IMPL = MPZ
1515
CIRCUITPY_DISPLAYIO = 0
1616
CIRCUITPY_FREQUENCYIO = 0
1717
CIRCUITPY_I2CPERIPHERAL = 0
18+
CIRCUITPY_MSGPACK = 0
1819
MICROPY_PY_ASYNC_AWAIT = 0
1920

2021
SUPEROPT_GC = 0

ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
1616
CIRCUITPY_DISPLAYIO = 0
1717
CIRCUITPY_FREQUENCYIO = 0
1818
CIRCUITPY_I2CPERIPHERAL = 0
19+
CIRCUITPY_MSGPACK = 0
1920
CIRCUITPY_PIXELBUF = 1
2021
CIRCUITPY_ROTARYIO = 0
2122
CIRCUITPY_RTC = 0

ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
1616
CIRCUITPY_COUNTIO = 0
1717
CIRCUITPY_FREQUENCYIO = 0
1818
CIRCUITPY_I2CPERIPHERAL = 0
19+
CIRCUITPY_MSGPACK = 0
1920
CIRCUITPY_PIXELBUF = 0
2021
CIRCUITPY_ROTARYIO = 0
2122
CIRCUITPY_RTC = 0

ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_FREQUENCYIO = 0
1616
CIRCUITPY_COUNTIO = 0
1717
CIRCUITPY_I2CPERIPHERAL = 0
18+
CIRCUITPY_MSGPACK = 0
1819
CIRCUITPY_VECTORIO = 0
1920
CIRCUITPY_BUSDEVICE = 0
2021

ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CIRCUITPY_FREQUENCYIO = 0
1818
CIRCUITPY_I2CPERIPHERAL = 0
1919
CIRCUITPY_GAMEPAD = 0
2020
CFLAGS_INLINE_LIMIT = 50
21+
CIRCUITPY_MSGPACK = 0
2122

2223
# Include these Python libraries in firmware.
2324
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice

ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_FREQUENCYIO = 0
1616
CIRCUITPY_COUNTIO = 0
1717
CIRCUITPY_I2CPERIPHERAL = 0
18+
CIRCUITPY_MSGPACK = 0
1819
# supersized, not ultra-supersized
1920
CIRCUITPY_VECTORIO = 0
2021
CIRCUITPY_BUSDEVICE = 0

ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
1414
CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_COUNTIO = 0
1616
CIRCUITPY_I2CPERIPHERAL = 0
17+
CIRCUITPY_MSGPACK = 0
1718
CIRCUITPY_VECTORIO = 0
1819
CIRCUITPY_BUSDEVICE = 0
1920

ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CIRCUITPY_BITBANGIO = 0
1717
CIRCUITPY_COUNTIO = 0
1818
CIRCUITPY_FREQUENCYIO = 0
1919
CIRCUITPY_I2CPERIPHERAL = 0
20+
CIRCUITPY_MSGPACK = 0
2021

2122
SUPEROPT_GC = 0
2223

ports/atmel-samd/boards/snekboard/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LONGINT_IMPL = MPZ
1414
CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_GAMEPAD = 0
1616
CIRCUITPY_I2CPERIPHERAL = 0
17+
CIRCUITPY_MSGPACK = 0
1718
CIRCUITPY_VECTORIO = 0
1819
CIRCUITPY_BUSDEVICE = 0
1920

ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CIRCUITPY_BITBANGIO = 0
1515
CIRCUITPY_COUNTIO = 0
1616
CIRCUITPY_GAMEPAD = 0
1717
CIRCUITPY_I2CPERIPHERAL = 0
18+
CIRCUITPY_MSGPACK = 0
1819
CIRCUITPY_VECTORIO = 0
1920
CIRCUITPY_BUSDEVICE = 0
2021

ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_BITBANGIO = 0
1616
CIRCUITPY_FREQUENCYIO = 0
1717
CIRCUITPY_COUNTIO = 0
1818
CIRCUITPY_I2CPERIPHERAL = 0
19+
CIRCUITPY_MSGPACK = 0
1920
CIRCUITPY_VECTORIO = 0
2021
CIRCUITPY_BUSDEVICE = 0
2122

ports/cxd56/boards/spresense/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ USB_PRODUCT = "Spresense"
44
USB_MANUFACTURER = "Sony"
55

66
INTERNAL_FLASH_FILESYSTEM = 1
7+
8+
CIRCUITPY_MSGPACK = 0

ports/nrf/boards/pca10100/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CIRCUITPY_DISPLAYIO = 0
1515
CIRCUITPY_FRAMEBUFFERIO = 0
1616
CIRCUITPY_FREQUENCYIO = 0
1717
CIRCUITPY_I2CPERIPHERAL = 0
18+
CIRCUITPY_MSGPACK = 0
1819
CIRCUITPY_NEOPIXEL_WRITE = 0
1920
CIRCUITPY_NVM = 0
2021
CIRCUITPY_PIXELBUF = 0

ports/nrf/boards/simmel/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CIRCUITPY_AUDIOMP3 = 0
1616
CIRCUITPY_BUSIO = 1
1717
CIRCUITPY_DISPLAYIO = 0
1818
CIRCUITPY_FRAMEBUFFERIO = 0
19+
CIRCUITPY_MSGPACK = 0
1920
CIRCUITPY_GAMEPAD = 0
2021
CIRCUITPY_NEOPIXEL_WRITE = 0
2122
CIRCUITPY_NVM = 0

py/circuitpy_defns.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ endif
292292
ifeq ($(CIRCUITPY_PEW),1)
293293
SRC_PATTERNS += _pew/%
294294
endif
295+
ifeq ($(CIRCUITPY_MSGPACK),1)
296+
SRC_PATTERNS += msgpack/%
297+
endif
295298

296299
# All possible sources are listed here, and are filtered by SRC_PATTERNS in SRC_COMMON_HAL
297300
SRC_COMMON_HAL_ALL = \
@@ -412,6 +415,8 @@ $(filter $(SRC_PATTERNS), \
412415
math/__init__.c \
413416
microcontroller/ResetReason.c \
414417
microcontroller/RunMode.c \
418+
msgpack/__init__.c \
419+
msgpack/ExtType.c \
415420
supervisor/RunReason.c \
416421
)
417422

@@ -481,6 +486,7 @@ SRC_SHARED_MODULE_ALL = \
481486
memorymonitor/AllocationAlarm.c \
482487
memorymonitor/AllocationSize.c \
483488
network/__init__.c \
489+
msgpack/__init__.c \
484490
os/__init__.c \
485491
random/__init__.c \
486492
rgbmatrix/RGBMatrix.c \

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,13 @@ extern const struct _mp_obj_module_t wifi_module;
774774
#define WIFI_MODULE
775775
#endif
776776

777+
#if CIRCUITPY_MSGPACK
778+
extern const struct _mp_obj_module_t msgpack_module;
779+
#define MSGPACK_MODULE { MP_ROM_QSTR(MP_QSTR_msgpack), MP_ROM_PTR(&msgpack_module) },
780+
#else
781+
#define MSGPACK_MODULE
782+
#endif
783+
777784
// Define certain native modules with weak links so they can be replaced with Python
778785
// implementations. This list may grow over time.
779786
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
@@ -830,6 +837,7 @@ extern const struct _mp_obj_module_t wifi_module;
830837
_EVE_MODULE \
831838
MEMORYMONITOR_MODULE \
832839
MICROCONTROLLER_MODULE \
840+
MSGPACK_MODULE \
833841
NEOPIXEL_WRITE_MODULE \
834842
NETWORK_MODULE \
835843
SOCKET_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,6 @@ CFLAGS += -DCIRCUITPY_WIFI=$(CIRCUITPY_WIFI)
308308
# Enabled micropython.native decorator (experimental)
309309
CIRCUITPY_ENABLE_MPY_NATIVE ?= 0
310310
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)
311+
312+
CIRCUITPY_MSGPACK ?= $(CIRCUITPY_FULL_BUILD)
313+
CFLAGS += -DCIRCUITPY_MSGPACK=$(CIRCUITPY_MSGPACK)

shared-bindings/msgpack/ExtType.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Bernhard Boser
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/runtime.h"
28+
#include "py/smallint.h"
29+
#include "py/objproperty.h"
30+
#include "shared-bindings/msgpack/ExtType.h"
31+
32+
//| class ExtType:
33+
//| """ExtType represents ext type in msgpack."""
34+
//| def __init__(self, code: int, data: bytes) -> None:
35+
//| """Constructor
36+
//| :param int code: type code in range 0~127.
37+
//| :param bytes data: representation."""
38+
//|
39+
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) {
40+
mod_msgpack_extype_obj_t *self = m_new_obj(mod_msgpack_extype_obj_t);
41+
self->base.type = &mod_msgpack_exttype_type;
42+
enum { ARG_code, ARG_data };
43+
static const mp_arg_t allowed_args[] = {
44+
{ MP_QSTR_code, MP_ARG_INT | MP_ARG_REQUIRED },
45+
{ MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED },
46+
};
47+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
48+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
49+
50+
int code = args[ARG_code].u_int;
51+
if (code < 0 || code > 127) {
52+
mp_raise_AttributeError(translate("code outside range 0~127"));
53+
}
54+
self->code = code;
55+
56+
mp_obj_t data = args[ARG_data].u_obj;
57+
self->data = data;
58+
return MP_OBJ_FROM_PTR(self);
59+
}
60+
61+
62+
//| code: int
63+
//| """The type code, in range 0~127."""
64+
//| ...
65+
//|
66+
STATIC mp_obj_t mod_msgpack_exttype_get_code(mp_obj_t self_in) {
67+
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
68+
return MP_OBJ_NEW_SMALL_INT(self->code);
69+
}
70+
MP_DEFINE_CONST_FUN_OBJ_1(mod_msgpack_exttype_get_code_obj, mod_msgpack_exttype_get_code);
71+
72+
STATIC mp_obj_t mod_msgpack_exttype_set_code(mp_obj_t self_in, mp_obj_t code_in) {
73+
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
74+
int code = mp_obj_get_int(code_in);
75+
if (code < 0 || code > 127) {
76+
mp_raise_AttributeError(translate("code outside range 0~127"));
77+
}
78+
self->code = code;
79+
return mp_const_none;
80+
}
81+
MP_DEFINE_CONST_FUN_OBJ_2(mod_msgpack_exttype_set_code_obj, mod_msgpack_exttype_set_code);
82+
83+
const mp_obj_property_t mod_msgpack_exttype_code_obj = {
84+
.base.type = &mp_type_property,
85+
.proxy = {(mp_obj_t)&mod_msgpack_exttype_get_code_obj,
86+
(mp_obj_t)&mod_msgpack_exttype_set_code_obj,
87+
(mp_obj_t)&mp_const_none_obj},
88+
};
89+
90+
//| data: bytes
91+
//| """Data."""
92+
//| ...
93+
//|
94+
STATIC mp_obj_t mod_msgpack_exttype_get_data(mp_obj_t self_in) {
95+
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
96+
return self->data;
97+
}
98+
MP_DEFINE_CONST_FUN_OBJ_1(mod_msgpack_exttype_get_data_obj, mod_msgpack_exttype_get_data);
99+
100+
STATIC mp_obj_t mod_msgpack_exttype_set_data(mp_obj_t self_in, mp_obj_t data_in) {
101+
mod_msgpack_extype_obj_t *self = MP_OBJ_TO_PTR(self_in);
102+
self->data = data_in;
103+
return mp_const_none;
104+
}
105+
MP_DEFINE_CONST_FUN_OBJ_2(mod_msgpack_exttype_set_data_obj, mod_msgpack_exttype_set_data);
106+
107+
const mp_obj_property_t mod_msgpack_exttype_data_obj = {
108+
.base.type = &mp_type_property,
109+
.proxy = {(mp_obj_t)&mod_msgpack_exttype_get_data_obj,
110+
(mp_obj_t)&mod_msgpack_exttype_set_data_obj,
111+
(mp_obj_t)&mp_const_none_obj},
112+
};
113+
114+
STATIC mp_rom_map_elem_t mod_msgpack_exttype_locals_dict_table[] = {
115+
// Properties
116+
{ MP_ROM_QSTR(MP_QSTR_code), MP_ROM_PTR(&mod_msgpack_exttype_code_obj) },
117+
{ MP_ROM_QSTR(MP_QSTR_data), MP_ROM_PTR(&mod_msgpack_exttype_data_obj) },
118+
};
119+
STATIC MP_DEFINE_CONST_DICT(mod_msgpack_exttype_locals_dict, mod_msgpack_exttype_locals_dict_table);
120+
121+
const mp_obj_type_t mod_msgpack_exttype_type = {
122+
{ &mp_type_type },
123+
.name = MP_QSTR_ExtType,
124+
.make_new = mod_msgpack_exttype_make_new,
125+
.locals_dict = (mp_obj_dict_t*)&mod_msgpack_exttype_locals_dict,
126+
};

0 commit comments

Comments
 (0)