aboutsummaryrefslogtreecommitdiff
path: root/py/modstruct.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-10 22:19:32 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-11 03:58:49 +0300
commit6582d64d01c448be4f575f964c549e1ebffe0db0 (patch)
tree6846b2fc507b55be40bd3f7b82d5a55d905ed0bc /py/modstruct.c
parent2b9419b5bfda98d2cd291a81c1fa79a2f94e1089 (diff)
modstruct: Refactor to support both LE and BE packed structs.
Diffstat (limited to 'py/modstruct.c')
-rw-r--r--py/modstruct.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/py/modstruct.c b/py/modstruct.c
index 23c2c903d..328ced913 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -37,7 +37,7 @@ STATIC uint calcsize_items(const char *fmt) {
STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
- assert(fmt_type == '<'); (void)fmt_type;
+ assert(fmt_type == '<' || fmt_type == '>'); (void)fmt_type;
machine_uint_t size;
for (size = 0; *fmt; fmt++) {
int sz = mp_binary_get_size(*fmt);
@@ -53,7 +53,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
// TODO: "The buffer must contain exactly the amount of data required by the format (len(bytes) must equal calcsize(fmt))."
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
- assert(fmt_type == '<'); (void)fmt_type;
+ assert(fmt_type == '<' || fmt_type == '>'); (void)fmt_type;
uint size = calcsize_items(fmt);
mp_obj_tuple_t *res = mp_obj_new_tuple(size, NULL);
buffer_info_t bufinfo;
@@ -61,7 +61,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
byte *p = bufinfo.buf;
for (uint i = 0; i < size; i++) {
- mp_obj_t item = mp_binary_get_val_unaligned_le(*fmt++, &p);
+ mp_obj_t item = mp_binary_get_val_unaligned(*fmt++, &p);
res->items[i] = item;
}
return res;