From 312f8c3cf3daf2cdb0419614227ed6b76b78f35d Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Wed, 4 Feb 2009 10:03:26 -0500 Subject: [PATCH] c bool encoding --- pymongo/_cbsonmodule.c | 4 ++++ tools/bson_benchmark.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pymongo/_cbsonmodule.c b/pymongo/_cbsonmodule.c index eb27ef765..27b5c68fb 100644 --- a/pymongo/_cbsonmodule.c +++ b/pymongo/_cbsonmodule.c @@ -131,6 +131,10 @@ static PyObject* _cbson_element_to_bson(PyObject* self, PyObject* args) { } else if (PyInt_CheckExact(value)) { int int_value = (int)PyInt_AsLong(value); return build_element(0x10, name, 4, (char*)&int_value); + } else if (PyBool_Check(value)) { + long bool = PyInt_AsLong(value); + char c = bool ? 0x01 : 0x00; + return build_element(0x08, name, 1, &c); } PyErr_SetString(CBSONError, "no c encoder for this type yet"); return NULL; diff --git a/tools/bson_benchmark.py b/tools/bson_benchmark.py index c178773e9..2fc4ab6a6 100644 --- a/tools/bson_benchmark.py +++ b/tools/bson_benchmark.py @@ -43,6 +43,10 @@ def main(): {"hello": "world", "mike": u"something", "here's": u"an\u8744other"}, + {"int": 200, + "bool": True, + "an int": 20, + "a bool": False}, {"this": 5, "is": {"a": True}, "big": [True, 5.5],