
com.avsystem.commons.mongo.BsonValueUtils.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-mongo_2.13 Show documentation
Show all versions of commons-mongo_2.13 Show documentation
AVSystem commons library for Scala
package com.avsystem.commons
package mongo
import org.bson.codecs.{BsonValueCodec, DecoderContext, EncoderContext}
import org.bson.{BsonReader, BsonValue, BsonWriter}
object BsonValueUtils {
private val bsonValueCodec = new BsonValueCodec
private val encoderContext = EncoderContext.builder.build
private val decoderContext = DecoderContext.builder.build
def encode(bw: BsonWriter, bv: BsonValue): Unit =
bsonValueCodec.encode(bw, bv, encoderContext)
def decode(br: BsonReader): BsonValue = {
if (br.getCurrentBsonType eq null) {
br.readBsonType()
}
bsonValueCodec.decode(br, decoderContext)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy