public static BsonDocument getTestDocument(final File file) throws IOException { return new BsonDocumentCodec().decode(new JsonReader(getFileAsString(file)), DecoderContext.builder().build()); }
static JsonReader asGsonReader(BsonDocument bson) { BasicOutputBuffer output = new BasicOutputBuffer(); new BsonDocumentCodec().encode(new BsonBinaryWriter(output), bson, EncoderContext.builder().build()); return new BsonReader(new BsonBinaryReader(ByteBuffer.wrap(output.toByteArray()))); }
static BsonDocument toBson(JsonObject gson) throws IOException { return new BsonDocumentCodec().decode(asBsonReader(gson), DecoderContext.builder().build()); }
@Benchmark public Object encodeMongoTest() throws Exception { BasicOutputBuffer out = new BasicOutputBuffer(512); new BsonDocumentCodec().encode(new BsonBinaryWriter(out), doc1, EncoderContext.builder().build()); return out.getByteBuffers(); }
@Benchmark public Object decodeMongoTest() throws Exception { BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(encoded)); return new BsonDocumentCodec().decode(reader, DecoderContext.builder().build()); }