summaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-10 12:58:31 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-10 12:58:31 +0100
commit3a8b1607fcbffdbff0a0001d6baacea7693d15b9 (patch)
tree359d2b30a91c4ffc37ce2ce2734abfa6331d6dd3 /py/binary.c
parent635543c72cc9ccfb20c1ec1f64d329eef35ebe2d (diff)
parent978607aeffb5b1deca3a4ad4b0ab0d0e15b5e271 (diff)
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/py/binary.c b/py/binary.c
index 7a8ed4611..95e82a688 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -77,6 +77,52 @@ mp_obj_t mp_binary_get_val(char typecode, void *p, int index) {
return MP_OBJ_NEW_SMALL_INT(val);
}
+mp_obj_t mp_binary_get_val_unaligned_le(char typecode, byte **ptr) {
+ machine_int_t val = 0;
+ byte *p = *ptr;
+ switch (typecode) {
+ case 'b':
+ val = (int8_t)*p++;
+ break;
+ case BYTEARRAY_TYPECODE:
+ case 'B':
+ val = *p++;
+ break;
+ case 'h':
+ val = (int16_t)((p[1] << 8) | p[0]);
+ break;
+ case 'H':
+ val = (p[1] << 8) | p[0];
+ break;
+ case 'i':
+ case 'l':
+ val = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+ *ptr = p + 4;
+ return mp_obj_new_int(val);
+ case 'I':
+ case 'L':
+ val = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+ *ptr = p + 4;
+ return mp_obj_new_int_from_uint(val);
+#if 0 //TODO
+#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
+ case 'q':
+ case 'Q':
+ // TODO: Explode API more to cover signedness
+ return mp_obj_new_int_from_ll(((long long*)p)[index]);
+#endif
+#if MICROPY_ENABLE_FLOAT
+ case 'f':
+ return mp_obj_new_float(((float*)p)[index]);
+ case 'd':
+ return mp_obj_new_float(((double*)p)[index]);
+#endif
+#endif
+ }
+ *ptr = p;
+ return MP_OBJ_NEW_SMALL_INT(val);
+}
+
void mp_binary_set_val(char typecode, void *p, int index, mp_obj_t val_in) {
machine_int_t val = 0;
if (MP_OBJ_IS_INT(val_in)) {