>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
- >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="bbqii"))
+ >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii"))
1 2 3 4 5
"""
print buf[0].a, buf[0].b, buf[0].c, buf[0].d, buf[0].e
>>> _int("b")
Traceback (most recent call last):
...
- ValueError: Buffer dtype mismatch, expected 'int' but got 'char'
+ ValueError: Buffer dtype mismatch, expected 'int' but got 'signed char'
>>> _int("if")
Traceback (most recent call last):
def unpacked_struct(fmt):
"""
Native formats:
- >>> unpacked_struct("biZffbiii")
- >>> unpacked_struct("@bi3fb3i")
- >>> unpacked_struct("@biZffbi2i")
- >>> unpacked_struct("biZffT{biii}")
- >>> unpacked_struct("bT{ifffb2i}i")
- >>> unpacked_struct("biZffb3T{i}")
- >>> unpacked_struct("T{b}T{T{iZffT{bi}}}2T{T{i}}")
+ >>> unpacked_struct("ciZffciii")
+ >>> unpacked_struct("@ci3fc3i")
+ >>> unpacked_struct("@ciZffci2i")
+ >>> unpacked_struct("ciZffT{ciii}")
+ >>> unpacked_struct("cT{ifffc2i}i")
+ >>> unpacked_struct("ciZffc3T{i}")
+ >>> unpacked_struct("T{c}T{T{iZffT{ci}}}2T{T{i}}")
"""
assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2)
Assuming int is four bytes:
>>> packed_struct("^cici")
- >>> packed_struct("=cibi")
+ >>> packed_struct("=cici")
However aligned access won't work:
return 0
cdef get_itemsize(self): return sizeof(MyStruct)
- cdef get_default_format(self): return b"2bq2i"
+ cdef get_default_format(self): return b"2cq2i"
cdef class NestedStructMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1:
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
- >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="bbqii"))
+ >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii"))
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]
"""
buf = mslice
77 11 1
-1 -1 -1
'''
- cdef char[:,:,:] larr = array((5,7,11), 1, 'b')
+ cdef char[:,:,:] larr = array((5,7,11), 1, 'c')
print larr.shape[0], larr.shape[1], larr.shape[2]
print larr.strides[0], larr.strides[1], larr.strides[2]
print larr.suboffsets[0], larr.suboffsets[1], larr.suboffsets[2]
print
- larr = array((5,7,11), 1, 'b', mode='fortran')
+ larr = array((5,7,11), 1, 'c', mode='fortran')
print larr.shape[0], larr.shape[1], larr.shape[2]
print larr.strides[0], larr.strides[1], larr.strides[2]
print larr.suboffsets[0], larr.suboffsets[1], larr.suboffsets[2]
>>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
- >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="bbqii"))
+ >>> basic_struct(MyStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ccqii"))
1 2 3 4 5
"""
print buf[0].a, buf[0].b, buf[0].c, buf[0].d, buf[0].e