use of org.bson.BsonBinaryWriter in project mongo-java-driver by mongodb.
the class CodecTestUtil method prepareReaderWithObjectToBeDecoded.
static <T> BsonBinaryReader prepareReaderWithObjectToBeDecoded(final T objectToDecode, final Codec<T> codec) {
BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
BsonBinaryWriter writer = new BsonBinaryWriter(outputBuffer);
byte[] documentAsByteArrayForReader;
try {
codec.encode(writer, objectToDecode, EncoderContext.builder().build());
documentAsByteArrayForReader = outputBuffer.toByteArray();
} finally {
writer.close();
}
return new BsonBinaryReader(new ByteBufferBsonInput(new ByteBufNIO(wrap(documentAsByteArrayForReader))));
}
use of org.bson.BsonBinaryWriter in project mongo-java-driver by mongodb.
the class DocumentCodecTest method setUp.
@Before
public void setUp() throws Exception {
buffer = new BasicOutputBuffer();
writer = new BsonBinaryWriter(buffer);
}
use of org.bson.BsonBinaryWriter in project mongo-java-driver by mongodb.
the class MessageHelper method encodeJson.
private static ByteBuf encodeJson(final String json) {
OutputBuffer outputBuffer = new BasicOutputBuffer();
JsonReader jsonReader = new JsonReader(json);
BsonDocumentCodec codec = new BsonDocumentCodec();
BsonDocument document = codec.decode(jsonReader, DecoderContext.builder().build());
BsonBinaryWriter writer = new BsonBinaryWriter(outputBuffer);
codec.encode(writer, document, EncoderContext.builder().build());
ByteBuffer documentByteBuffer = ByteBuffer.allocate(outputBuffer.size());
documentByteBuffer.put(outputBuffer.toByteArray());
return new ByteBufNIO(documentByteBuffer);
}
Aggregations