83 buffsize = len(buff) |
83 buffsize = len(buff) |
84 buffptr = cast(ctypes.pythonapi.PyString_AsString(id(buff)), c_void_p).value |
84 buffptr = cast(ctypes.pythonapi.PyString_AsString(id(buff)), c_void_p).value |
85 for iectype in indexes: |
85 for iectype in indexes: |
86 c_type, unpack_func, _pack_func = \ |
86 c_type, unpack_func, _pack_func = \ |
87 TypeTranslator.get(iectype, (None, None, None)) |
87 TypeTranslator.get(iectype, (None, None, None)) |
88 if c_type is not None and buffoffset < buffsize: |
88 |
89 cursor = c_void_p(buffptr + buffoffset) |
89 cursor = c_void_p(buffptr + buffoffset) |
|
90 if iectype == "STRING": |
|
91 # strlen is stored in c_uint8 and sizeof(c_uint8) is 1 |
|
92 # first check we can read size |
|
93 if (buffoffset + 1) <= buffsize: |
|
94 size = 1 + cast(cursor,POINTER(c_type)).contents.len |
|
95 else: |
|
96 return None |
|
97 else: |
|
98 size = sizeof(c_type) |
|
99 |
|
100 if c_type is not None and (buffoffset + size) <= buffsize: |
90 value = unpack_func(cast(cursor, |
101 value = unpack_func(cast(cursor, |
91 POINTER(c_type)).contents) |
102 POINTER(c_type)).contents) |
92 buffoffset += sizeof(c_type) if iectype != "STRING" else len(value)+1 |
103 buffoffset += size |
93 res.append(value) |
104 res.append(value) |
94 else: |
105 else: |
95 return None |
106 return None |
96 if buffoffset and buffoffset == buffsize: |
107 if buffoffset and buffoffset == buffsize: |
97 return res |
108 return res |