From 2277ee35316a486b7d536da609117570e82cb3d7 Mon Sep 17 00:00:00 2001 From: Luke Lovett Date: Mon, 21 Jul 2014 17:37:11 +0000 Subject: [PATCH] PYTHON-707 Encode BSONInt64 in C extensions. --- bson/_cbsonmodule.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 111a4cccb..f301f5f1a 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -770,6 +770,21 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer, *(buffer_get_buffer(buffer) + type_byte) = 0x11; return 1; } + case 18: + { + /* BSONInt64 */ + const long long ll = PyLong_AsLongLong(value); + if (PyErr_Occurred()) { /* Overflow */ + PyErr_SetString(PyExc_OverflowError, + "MongoDB can only handle up to 8-byte ints"); + return 0; + } + if (!buffer_write_bytes(buffer, (const char*)&ll, 8)) { + return 0; + } + *(buffer_get_buffer(buffer) + type_byte) = 0x12; + return 1; + } case 100: { /* DBRef */