Permalink
Browse files

Add Int32Type, a 4 byte signed integer format

  • Loading branch information...
1 parent 580f5f9 commit b840600e28da64266b08ba95228b62d5afeca462 @thobbs thobbs committed Apr 17, 2012
Showing with 20 additions and 1 deletion.
  1. +16 −1 pycassa/marshal.py
  2. +4 −0 pycassa/types.py
View
@@ -26,7 +26,7 @@
_BASIC_TYPES = ['BytesType', 'LongType', 'IntegerType', 'UTF8Type',
'AsciiType', 'LexicalUUIDType', 'TimeUUIDType',
'CounterColumnType', 'FloatType', 'DoubleType',
- 'DateType', 'BooleanType', 'UUIDType']
+ 'DateType', 'BooleanType', 'UUIDType', 'Int32Type']
def extract_type_name(typestr):
if typestr is None:
@@ -194,6 +194,15 @@ def pack_long(v, _=None):
return struct.pack('>q', v)
return pack_long
+ elif data_type == 'Int32Type':
+ if _have_struct:
+ def pack_int32(v, _=None):
+ return _int_packer.pack(v)
+ else:
+ def pack_int32(v, _=None):
+ return struct.pack('>i', v)
+ return pack_int32
+
elif data_type == 'IntegerType':
return encode_int
@@ -282,6 +291,12 @@ def unpacker_for(typestr):
else:
return lambda v: struct.unpack('>q', v)[0]
+ elif data_type == 'Int32Type':
+ if _have_struct:
+ return lambda v: _int_packer.unpack(v)[0]
+ else:
+ return lambda v: struct.unpack('>i', v)[0]
+
elif data_type == 'IntegerType':
return decode_int
View
@@ -81,6 +81,10 @@ class IntegerType(CassandraType):
"""
pass
+class Int32Type(CassandraType):
+ """ Stores data as a 4 byte integer """
+ pass
+
class AsciiType(CassandraType):
""" Stores data as ASCII text """
pass

0 comments on commit b840600

Please sign in to comment.