summaryrefslogtreecommitdiffstatshomepage
path: root/py/binary.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-14 20:21:50 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-14 20:38:46 +0200
commitc203324e6c28264f5660e33d386f56aa21aad422 (patch)
treeb7b8c1b135a3d4d8bd6b7f425314f131c287fa23 /py/binary.c
parent8bc3516389cd148ebeaa58ceaf3d3f7fb13440d8 (diff)
downloadmicropython-c203324e6c28264f5660e33d386f56aa21aad422.tar.gz
micropython-c203324e6c28264f5660e33d386f56aa21aad422.zip
objarray: Refactor to use array accessors from binary.c .
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/py/binary.c b/py/binary.c
index a738dd62a9..71d715c3e1 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -11,6 +11,36 @@
// Helpers to work with binary-encoded data
+int mp_binary_get_size(char typecode) {
+ // This assumes that unsigned and signed types are of the same type,
+ // which is invariant for [u]intN_t.
+ switch (typecode) {
+ case BYTEARRAY_TYPECODE:
+ case 'b':
+ case 'B':
+ return sizeof(int8_t);
+ case 'h':
+ case 'H':
+ return sizeof(int16_t);
+ case 'i':
+ case 'I':
+ return sizeof(int32_t);
+ case 'l':
+ case 'L':
+ return sizeof(int32_t);
+ case 'q':
+ case 'Q':
+ return sizeof(long long);
+#if MICROPY_ENABLE_FLOAT
+ case 'f':
+ return sizeof(float);
+ case 'd':
+ return sizeof(double);
+#endif
+ }
+ return -1;
+}
+
mp_obj_t mp_binary_get_val(char typecode, void *p, int index) {
int val = 0;
switch (typecode) {