Skip to content

Commit

Permalink
Merge pull request #49 from rackerlabs/bool-type
Browse files Browse the repository at this point in the history
unmarshalling boolean type
  • Loading branch information
manishtomar committed Apr 1, 2015
2 parents 6c490e4 + c34270e commit a411897
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -30,6 +30,8 @@ Prerequisites:
Version History
===============

- 0.1.11
- Unmarshalling bool type
- 0.1.10
- (vvoznesensky) Fixed authentication
- 0.1.9
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,7 +16,7 @@ def visit(arg, directory, files):

setup(
name='silverberg',
version='0.1.10',
version='0.1.11',
description='Twisted CQL Cassandra Client',
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
6 changes: 6 additions & 0 deletions silverberg/marshal.py
Expand Up @@ -30,6 +30,7 @@
_param_re = re.compile(r"(?<!strategy_options)(:[a-zA-Z_][a-zA-Z0-9_]*)", re.M)

BYTES_TYPE = "org.apache.cassandra.db.marshal.BytesType"
BOOLEAN_TYPE = "org.apache.cassandra.db.marshal.BooleanType"
ASCII_TYPE = "org.apache.cassandra.db.marshal.AsciiType"
UTF8_TYPE = "org.apache.cassandra.db.marshal.UTF8Type"
INTEGER_TYPE = "org.apache.cassandra.db.marshal.IntegerType"
Expand Down Expand Up @@ -83,6 +84,10 @@ def unmarshal_noop(bytestr):
return bytestr


def unmarshal_bool(bytestr):
return bytestr == "\x01"


def unmarshal_utf8(bytestr):
return bytestr.decode("utf8")

Expand Down Expand Up @@ -140,6 +145,7 @@ def unmarshal_list(objtype, bytesstr):


unmarshallers = {BYTES_TYPE: unmarshal_noop,
BOOLEAN_TYPE: unmarshal_bool,
ASCII_TYPE: unmarshal_noop,
UTF8_TYPE: unmarshal_utf8,
INTEGER_TYPE: unmarshal_int,
Expand Down
14 changes: 12 additions & 2 deletions silverberg/test/test_marshal.py
Expand Up @@ -24,8 +24,9 @@

from twisted.trial.unittest import TestCase

from silverberg.marshal import marshal, unmarshal_timestamp, unmarshal_int, \
unmarshal_initializable_int, unmarshal_double, prepare
from silverberg.marshal import (
marshal, unmarshal_timestamp, unmarshal_int, unmarshal_bool,
unmarshal_initializable_int, unmarshal_double, prepare)


class StatementPreparation(TestCase):
Expand Down Expand Up @@ -102,3 +103,12 @@ class MarshallingUnmarshallingDouble(TestCase):
def test_unmarshal_double(self):
marshaled = '?\xc1\x99\x99\x99\x99\x99\x9a'
self.assertEqual(unmarshal_double(marshaled), 0.1375)


class MarshallingUnmarshallingBoolean(TestCase):
"""
Test marshalling and unmarshalling of boolean
"""
def test_unmarshal(self):
self.assertEqual(unmarshal_bool('\x01'), True)
self.assertEqual(unmarshal_bool('\x00'), False)

0 comments on commit a411897

Please sign in to comment.