use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.
the class BasicBSONEncoder method encode.
@Override
public byte[] encode(final BSONObject document) {
OutputBuffer outputBuffer = new BasicOutputBuffer();
set(outputBuffer);
putObject(document);
done();
return outputBuffer.toByteArray();
}
use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.
the class CodecTestCase method encode.
<T> OutputBuffer encode(final Codec<T> codec, final T value) {
OutputBuffer buffer = new BasicOutputBuffer();
BsonWriter writer = new BsonBinaryWriter(buffer);
codec.encode(writer, value, EncoderContext.builder().build());
return buffer;
}
use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.
the class PojoTestCase method decodesTo.
<T> void decodesTo(final Codec<T> codec, final String json, final T expected) {
OutputBuffer encoded = encode(DOCUMENT_CODEC, BsonDocument.parse(json), false);
T result = decode(codec, encoded);
assertEquals("Decoded value", expected, result);
}
use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.
the class PojoTestCase method encode.
<T> OutputBuffer encode(final Codec<T> codec, final T value, final boolean collectible) {
OutputBuffer buffer = new BasicOutputBuffer();
BsonWriter writer = new BsonBinaryWriter(buffer);
codec.encode(writer, value, EncoderContext.builder().isEncodingCollectibleDocument(collectible).build());
return buffer;
}
use of org.bson.io.OutputBuffer in project mongo-java-driver by mongodb.
the class PojoTestCase method encodesTo.
@SuppressWarnings("unchecked")
<T> void encodesTo(final Codec<T> codec, final T value, final String json, final boolean collectible) {
OutputBuffer encoded = encode(codec, value, collectible);
BsonDocument asBsonDocument = decode(DOCUMENT_CODEC, encoded);
assertEquals("Encoded value", BsonDocument.parse(json), asBsonDocument);
}
Aggregations