Remove cython marshalling pass-through functions
This commit is contained in:
@@ -26,6 +26,7 @@ from cassandra.util import is_little_endian
|
||||
|
||||
cdef bint PY3 = six.PY3
|
||||
|
||||
|
||||
ctypedef fused num_t:
|
||||
int64_t
|
||||
int32_t
|
||||
@@ -38,56 +39,24 @@ ctypedef fused num_t:
|
||||
double
|
||||
float
|
||||
|
||||
cdef inline num_t copy_maybe_swap(char *buf, num_t *dummy=NULL): # dummy pointer because cython wants the fused type as an arg
|
||||
cdef inline num_t unpack_num(Buffer *buf, num_t *dummy=NULL): # dummy pointer because cython wants the fused type as an arg
|
||||
"""
|
||||
Copy to aligned destination, conditionally swapping to native byte order
|
||||
"""
|
||||
cdef num_t ret = 0
|
||||
cdef Py_ssize_t start, end, i
|
||||
cdef char* out = <char*> &ret
|
||||
cdef char *src = buf_read(buf, sizeof(num_t))
|
||||
cdef num_t ret = 0
|
||||
cdef char *out = <char*> &ret
|
||||
|
||||
if is_little_endian:
|
||||
for i in range(sizeof(num_t)):
|
||||
out[sizeof(num_t) - i - 1] = buf[i]
|
||||
out[sizeof(num_t) - i - 1] = src[i]
|
||||
else:
|
||||
# TODO: use inline function as in numpy_parser
|
||||
memcpy(out, buf, sizeof(num_t))
|
||||
memcpy(out, src, sizeof(num_t))
|
||||
|
||||
return ret
|
||||
|
||||
cdef inline Py_ssize_t div2(Py_ssize_t x):
|
||||
return x >> 1
|
||||
|
||||
cdef inline int64_t int64_unpack(Buffer *buf) except ?0xDEAD:
|
||||
return copy_maybe_swap[int64_t](buf_read(buf, sizeof(int64_t)))
|
||||
|
||||
cdef inline int32_t int32_unpack(Buffer *buf) except ?0xDEAD:
|
||||
return copy_maybe_swap[int32_t](buf_read(buf, sizeof(int32_t)))
|
||||
|
||||
cdef inline int16_t int16_unpack(Buffer *buf) except ?0xDED:
|
||||
return copy_maybe_swap[int16_t](buf_read(buf, sizeof(int16_t)))
|
||||
|
||||
cdef inline int8_t int8_unpack(Buffer *buf) except ?80:
|
||||
return copy_maybe_swap[int8_t](buf_read(buf, sizeof(int8_t)))
|
||||
|
||||
cdef inline uint64_t uint64_unpack(Buffer *buf) except ?0xDEAD:
|
||||
return copy_maybe_swap[uint64_t](buf_read(buf, sizeof(uint64_t)))
|
||||
|
||||
cdef inline uint32_t uint32_unpack(Buffer *buf) except ?0xDEAD:
|
||||
return copy_maybe_swap[uint32_t](buf_read(buf, sizeof(uint32_t)))
|
||||
|
||||
cdef inline uint16_t uint16_unpack(Buffer *buf) except ?0xDEAD:
|
||||
return copy_maybe_swap[uint16_t](buf_read(buf, sizeof(uint16_t)))
|
||||
|
||||
cdef inline uint8_t uint8_unpack(Buffer *buf) except ?0xff:
|
||||
return copy_maybe_swap[uint8_t](buf_read(buf, sizeof(uint8_t)))
|
||||
|
||||
cdef inline double double_unpack(Buffer *buf) except ?1.74:
|
||||
return copy_maybe_swap[double](buf_read(buf, sizeof(double)))
|
||||
|
||||
cdef inline float float_unpack(Buffer *buf) except ?1.74:
|
||||
return copy_maybe_swap[float](buf_read(buf, sizeof(float)))
|
||||
|
||||
cdef varint_unpack(Buffer *term):
|
||||
"""Unpack a variable-sized integer"""
|
||||
if PY3:
|
||||
|
||||
@@ -53,7 +53,7 @@ cdef class DesDecimalType(Deserializer):
|
||||
cdef Buffer varint_buf
|
||||
slice_buffer(buf, &varint_buf, 4, buf.size - 4)
|
||||
|
||||
scale = int32_unpack(buf)
|
||||
scale = unpack_num[int32_t](buf)
|
||||
unscaled = varint_unpack(&varint_buf)
|
||||
|
||||
return Decimal('%de%d' % (unscaled, -scale))
|
||||
@@ -66,14 +66,14 @@ cdef class DesUUIDType(Deserializer):
|
||||
|
||||
cdef class DesBooleanType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
if int8_unpack(buf):
|
||||
if unpack_num[int8_t](buf):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
cdef class DesByteType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return int8_unpack(buf)
|
||||
return unpack_num[int8_t](buf)
|
||||
|
||||
|
||||
cdef class DesAsciiType(Deserializer):
|
||||
@@ -85,22 +85,22 @@ cdef class DesAsciiType(Deserializer):
|
||||
|
||||
cdef class DesFloatType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return float_unpack(buf)
|
||||
return unpack_num[float](buf)
|
||||
|
||||
|
||||
cdef class DesDoubleType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return double_unpack(buf)
|
||||
return unpack_num[double](buf)
|
||||
|
||||
|
||||
cdef class DesLongType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return int64_unpack(buf)
|
||||
return unpack_num[int64_t](buf)
|
||||
|
||||
|
||||
cdef class DesInt32Type(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return int32_unpack(buf)
|
||||
return unpack_num[int32_t](buf)
|
||||
|
||||
|
||||
cdef class DesIntegerType(Deserializer):
|
||||
@@ -127,7 +127,7 @@ cdef class DesCounterColumnType(DesLongType):
|
||||
|
||||
cdef class DesDateType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
cdef double timestamp = int64_unpack(buf) / 1000.0
|
||||
cdef double timestamp = unpack_num[int64_t](buf) / 1000.0
|
||||
return datetime_from_timestamp(timestamp)
|
||||
|
||||
|
||||
@@ -147,18 +147,18 @@ EPOCH_OFFSET_DAYS = 2 ** 31
|
||||
|
||||
cdef class DesSimpleDateType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
days = uint32_unpack(buf) - EPOCH_OFFSET_DAYS
|
||||
days = unpack_num[uint32_t](buf) - EPOCH_OFFSET_DAYS
|
||||
return util.Date(days)
|
||||
|
||||
|
||||
cdef class DesShortType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return int16_unpack(buf)
|
||||
return unpack_num[int16_t](buf)
|
||||
|
||||
|
||||
cdef class DesTimeType(Deserializer):
|
||||
cdef deserialize(self, Buffer *buf, int protocol_version):
|
||||
return util.Time(int64_unpack(buf))
|
||||
return util.Time(unpack_num[int64_t](buf))
|
||||
|
||||
|
||||
cdef class DesUTF8Type(Deserializer):
|
||||
@@ -273,9 +273,9 @@ cdef int _unpack_len(itemlen_t idx, itemlen_t *elemlen, Buffer *buf) except -1:
|
||||
slice_buffer(buf, &itemlen_buf, idx, sizeof(itemlen_t))
|
||||
|
||||
if itemlen_t is uint16_t:
|
||||
elemlen[0] = uint16_unpack(&itemlen_buf)
|
||||
elemlen[0] = unpack_num[uint16_t](&itemlen_buf)
|
||||
else:
|
||||
elemlen[0] = int32_unpack(&itemlen_buf)
|
||||
elemlen[0] = unpack_num[int32_t](&itemlen_buf)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -359,7 +359,7 @@ cdef class DesTupleType(_DesParameterizedType):
|
||||
item = None
|
||||
if p < buf.size:
|
||||
slice_buffer(buf, &itemlen_buf, p, 4)
|
||||
itemlen = int32_unpack(&itemlen_buf)
|
||||
itemlen = unpack_num[int32_t](&itemlen_buf)
|
||||
p += 4
|
||||
if itemlen >= 0:
|
||||
slice_buffer(buf, &item_buf, p, itemlen)
|
||||
@@ -407,7 +407,7 @@ cdef class DesCompositeType(_DesParameterizedType):
|
||||
res = res[:i]
|
||||
break
|
||||
|
||||
element_length = uint16_unpack(buf)
|
||||
element_length = unpack_num[uint16_t](buf)
|
||||
slice_buffer(buf, &elem_buf, 2, element_length)
|
||||
|
||||
deserializer = self.deserializers[i]
|
||||
|
||||
@@ -44,4 +44,4 @@ cdef inline int32_t read_int(BytesIOReader reader) except ?0xDEAD:
|
||||
cdef Buffer buf
|
||||
buf.ptr = reader.read(4)
|
||||
buf.size = 4
|
||||
return int32_unpack(&buf)
|
||||
return unpack_num[int32_t](&buf)
|
||||
|
||||
Reference in New Issue
Block a user