Skip to content

Commit

Permalink
Add Int32Type, a 4 byte signed integer format
Browse files Browse the repository at this point in the history
  • Loading branch information
thobbs committed Apr 17, 2012
1 parent 580f5f9 commit b840600
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pycassa/marshal.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions pycassa/types.py
Expand Up @@ -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
Expand Down

0 comments on commit b840600

Please sign in to comment.