From c203324e6c28264f5660e33d386f56aa21aad422 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 14 Feb 2014 20:21:50 +0200 Subject: objarray: Refactor to use array accessors from binary.c . --- py/binary.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'py/binary.c') 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) { -- cgit v1.2.3