Skip to content

Commit e425a66

Browse files
committed
Reverse time and inc for Timestamp (de)serialization
1 parent ec63197 commit e425a66

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pymongo/_cbsonmodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static int write_element_to_buffer(bson_buffer* buffer, int type_byte, PyObject*
467467
PyObject* obj;
468468
long i;
469469

470-
obj = PyObject_GetAttrString(value, "time");
470+
obj = PyObject_GetAttrString(value, "inc");
471471
if (!obj) {
472472
return 0;
473473
}
@@ -477,7 +477,7 @@ static int write_element_to_buffer(bson_buffer* buffer, int type_byte, PyObject*
477477
return 0;
478478
}
479479

480-
obj = PyObject_GetAttrString(value, "inc");
480+
obj = PyObject_GetAttrString(value, "time");
481481
if (!obj) {
482482
return 0;
483483
}
@@ -1438,11 +1438,11 @@ static PyObject* get_value(const char* buffer, int* position, int type) {
14381438
}
14391439
case 17:
14401440
{
1441-
int i,
1442-
j;
1443-
memcpy(&i, buffer + *position, 4);
1444-
memcpy(&j, buffer + *position + 4, 4);
1445-
value = PyObject_CallFunction(Timestamp, "ii", i, j);
1441+
int time,
1442+
inc;
1443+
memcpy(&inc, buffer + *position, 4);
1444+
memcpy(&time, buffer + *position + 4, 4);
1445+
value = PyObject_CallFunction(Timestamp, "ii", time, inc);
14461446
if (!value) {
14471447
return NULL;
14481448
}

pymongo/bson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ def _get_ref(data):
327327

328328

329329
def _get_timestamp(data):
330-
(timestamp, data) = _get_int(data)
331330
(inc, data) = _get_int(data)
331+
(timestamp, data) = _get_int(data)
332332
return (Timestamp(timestamp, inc), data)
333333

334334
def _get_long(data):
@@ -451,7 +451,7 @@ def _element_to_bson(key, value, check_keys):
451451
if isinstance(value, Timestamp):
452452
time = struct.pack("<i", value.time)
453453
inc = struct.pack("<i", value.inc)
454-
return "\x11" + name + time + inc
454+
return "\x11" + name + inc + time
455455
if value is None:
456456
return "\x0A" + name
457457
if isinstance(value, _RE_TYPE):

test/test_bson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def test_basic_to_dict(self):
7777

7878
def test_data_timestamp(self):
7979
self.assertEqual({"test": Timestamp(4, 20)},
80-
BSON("\x13\x00\x00\x00\x11\x74\x65\x73\x74\x00\x04"
81-
"\x00\x00\x00\x14\x00\x00\x00\x00").to_dict())
80+
BSON("\x13\x00\x00\x00\x11\x74\x65\x73\x74\x00\x14"
81+
"\x00\x00\x00\x04\x00\x00\x00\x00").to_dict())
8282

8383
def test_basic_from_dict(self):
8484
self.assertRaises(TypeError, BSON.from_dict, 100)

0 commit comments

Comments
 (0)