diff --git a/cassandra/deserializers.pyx b/cassandra/deserializers.pyx index 35667694..ad1e5d1a 100644 --- a/cassandra/deserializers.pyx +++ b/cassandra/deserializers.pyx @@ -36,8 +36,13 @@ cdef class DesLongType(Deserializer): # TODO: Use libmpdec: http://www.bytereef.org/mpdecimal/index.html cdef class DesDecimalType(Deserializer): cdef deserialize(self, Buffer *buf, int protocol_version): + cdef Buffer varint_buf + varint_buf.ptr = buf.ptr + 4 + varint_buf.size = buf.size - 4 + scale = int32_unpack(buf.ptr) - unscaled = varint_unpack(buf.ptr + 4) + unscaled = varint_unpack(to_bytes(&varint_buf)) + return Decimal('%de%d' % (unscaled, -scale)) diff --git a/cassandra/marshal.pyx b/cassandra/marshal.pyx index 336ee1c7..0ab65c46 100644 --- a/cassandra/marshal.pyx +++ b/cassandra/marshal.pyx @@ -177,6 +177,7 @@ cpdef varint_unpack(term): # TODO: Optimize these two functions def varint_unpack_py3(term): cdef int64_t one = 1L + val = int(''.join("%02x" % i for i in term), 16) if (term[0] & 128) != 0: # There is a bug in Cython (0.20 - 0.22), where if we do