All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avsystem.commons.mongo.BsonValueUtils.scala Maven / Gradle / Ivy

The newest version!
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