Skip to content

Commit fb90e92

Browse files
committed
Reading and writing binary representation of ObjectId now just uses byte arrays produced and consumed by ObjectId class
1 parent 2ff578f commit fb90e92

File tree

3 files changed

+3
-24
lines changed

3 files changed

+3
-24
lines changed

bson/src/main/org/bson/BSONBinaryWriter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ public void writeObjectId(final ObjectId objectId) {
192192
buffer.write(BsonType.OBJECT_ID.getValue());
193193
writeCurrentName();
194194

195-
// TODO: Should this be pushed down into the buffer?
196-
buffer.writeIntBE(objectId.time());
197-
buffer.writeIntBE(objectId.machine());
198-
buffer.writeIntBE(objectId.inc());
199-
195+
buffer.write(objectId.toByteArray());
200196
setState(getNextState());
201197
}
202198

bson/src/main/org/bson/io/ByteBufferInput.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public String readString() {
8080

8181
@Override
8282
public ObjectId readObjectId() {
83-
return new ObjectId(readBigEndianInt(), readBigEndianInt(), readBigEndianInt());
83+
return new ObjectId(readBytes(12));
8484
}
8585

8686
@Override
@@ -97,12 +97,11 @@ public String readCString() {
9797
buffer.position(mark);
9898

9999
final byte[] bytes = readBytes(size);
100-
readByte(); // read the trailing null bytes
100+
readByte(); // read the trailing null byte
101101

102102
return new String(bytes, UTF8_CHARSET);
103103
}
104104

105-
106105
private void readUntilNullByte() {
107106
//CHECKSTYLE:OFF
108107
while (buffer.get() != 0) {
@@ -120,13 +119,4 @@ public void skipCString() {
120119
public void skip(final int numBytes) {
121120
buffer.position(buffer.position() + numBytes);
122121
}
123-
124-
private int readBigEndianInt() {
125-
int x = 0;
126-
x |= (0xFF & buffer.get()) << 24;
127-
x |= (0xFF & buffer.get()) << 16;
128-
x |= (0xFF & buffer.get()) << 8;
129-
x |= (0xFF & buffer.get());
130-
return x;
131-
}
132122
}

bson/src/main/org/bson/io/OutputBuffer.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ public void writeInt(final int x) {
7777
write(x >> 24);
7878
}
7979

80-
public void writeIntBE(final int x) {
81-
write(x >> 24);
82-
write(x >> 16);
83-
write(x >> 8);
84-
write(x);
85-
}
86-
8780
/**
8881
* Backpatches the size of a document or string by writing the size into the four bytes starting at getPosition() -
8982
* size.

0 commit comments

Comments
 (0)