Example #1
0
 public void writeNativeObjectId(org.bson.types.ObjectId objectId) throws IOException {
   _writeArrayFieldNameIfNeeded();
   _verifyValueWrite("write datetime");
   _buffer.putByte(_typeMarker, BsonConstants.TYPE_OBJECTID);
   // ObjectIds have their byte order flipped
   int time = ByteOrderUtil.flip(Long.valueOf(objectId.getTime() / 1000L).intValue());
   int machine = ByteOrderUtil.flip(objectId.getMachine());
   int inc = ByteOrderUtil.flip(objectId.getInc());
   _buffer.putInt(time);
   _buffer.putInt(machine);
   _buffer.putInt(inc);
   flushBuffer();
 }
Example #2
0
 /**
  * Reads a ObjectID from the input stream
  *
  * @return the ObjectID
  * @throws IOException if the ObjectID could not be read
  */
 protected ObjectId readObjectId() throws IOException {
   int time = ByteOrderUtil.flip(_in.readInt());
   int machine = ByteOrderUtil.flip(_in.readInt());
   int inc = ByteOrderUtil.flip(_in.readInt());
   return new ObjectId(time, machine, inc);
 }