Skip to content

Commit

Permalink
Add object id features
Browse files Browse the repository at this point in the history
  • Loading branch information
Parkayun committed Apr 12, 2016
1 parent a1ee0cd commit 8a0bb83
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bson/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import calendar
import pytz
from binascii import b2a_hex

from six import integer_types, iterkeys, text_type, PY3
from six.moves import xrange

Expand Down Expand Up @@ -171,6 +173,7 @@ def decode_double(data, base):
0x03: "document",
0x04: "array",
0x05: "binary",
0x07: "object_id",
0x08: "boolean",
0x09: "UTCdatetime",
0x0A: "none",
Expand Down Expand Up @@ -371,3 +374,13 @@ def decode_int64_element(data, base):
base, name = decode_cstring(data, base + 1)
value = struct.unpack("<q", data[base:base + 8])[0]
return base + 8, name, value


def encode_object_id_element(name, value):
return b"\x07" + encode_cstring(name) + value


def decode_object_id_element(data, base):
base, name = decode_cstring(data, base + 1)
value = b2a_hex(data[base:base + 12])
return base + 12, name, value

0 comments on commit 8a0bb83

Please sign in to comment.