initial vints_unpack
This commit is contained in:
@@ -48,7 +48,7 @@ from cassandra.marshal import (int8_pack, int8_unpack, int16_pack, int16_unpack,
|
||||
uint16_pack, uint16_unpack, uint32_pack, uint32_unpack,
|
||||
int32_pack, int32_unpack, int64_pack, int64_unpack,
|
||||
float_pack, float_unpack, double_pack, double_unpack,
|
||||
varint_pack, varint_unpack)
|
||||
varint_pack, varint_unpack, vints_unpack)
|
||||
from cassandra import util
|
||||
|
||||
apache_cassandra_type_prefix = 'org.apache.cassandra.db.marshal.'
|
||||
@@ -660,6 +660,20 @@ class TimeType(_CassandraType):
|
||||
return int64_pack(nano)
|
||||
|
||||
|
||||
class DurationType(_CassandraType):
|
||||
typename = 'duration'
|
||||
|
||||
@staticmethod
|
||||
def deserialize(byts, protocol_version):
|
||||
print vints_unpack(byts)
|
||||
varint_unpack(byts)
|
||||
return varint_unpack(byts)
|
||||
|
||||
@staticmethod
|
||||
def serialize(byts, protocol_version):
|
||||
return # ...
|
||||
|
||||
|
||||
class UTF8Type(_CassandraType):
|
||||
typename = 'text'
|
||||
empty_binary_ok = True
|
||||
|
||||
@@ -84,3 +84,18 @@ def varint_pack(big):
|
||||
revbytes.append(0)
|
||||
revbytes.reverse()
|
||||
return six.binary_type(revbytes)
|
||||
|
||||
|
||||
def decode_zig_zag(n):
|
||||
return (n >> 1) ^ -(n & 1)
|
||||
|
||||
|
||||
def vints_unpack(term): # noqa
|
||||
first_byte = ord(term[0])
|
||||
if (first_byte & 128) == 0:
|
||||
val = first_byte
|
||||
else:
|
||||
extra_bytes = 8 - (~first_byte & 0xff).bit_length()
|
||||
# takes (8-extra_bytes) bits + extra_bytes
|
||||
|
||||
return decode_zig_zag(val)
|
||||
|
||||
Reference in New Issue
Block a user