Skip to content

Kotlin BSON • Multiplatform abstraction for different BSON implementationsopensavvy.ktmongo.bsonBsonFactory

BsonFactory

interface BsonFactory

Entrypoint for creating Bson and BsonArray instances.

Instances of this interface are platform-specific and are used to create BSON documents. Each instance may allow parameterization of some behaviors.

Functions

buildArray

@LowLevelApi
abstract fun buildArray(block: BsonValueWriter.() -> Unit): BsonArray

Instantiates a new BSON array.

@LowLevelApi
open fun buildArray(instance: BsonValueWriteable): BsonArray

Instantiates a new BSON array representing the provided instance.

buildDocument

@LowLevelApi
abstract fun buildDocument(block: BsonFieldWriter.() -> Unit): Bson

Instantiates a new BSON document.

@LowLevelApi
open fun buildDocument(instance: BsonFieldWriteable): Bson

Instantiates a new BSON document representing the provided instance.

@LowLevelApi
abstract fun <T : Any> buildDocument(obj: T, type: KType, klass: KClass<T>): Bson

Writes an arbitrary Kotlin obj into a top-level BSON document.

readArray

@LowLevelApi
abstract fun readArray(bytes: ByteArray): BsonArray

Instantiates a new BSON array by reading its bytes representation.

readDocument

@LowLevelApi
abstract fun readDocument(bytes: ByteArray): Bson

Instantiates a new BSON document by reading its bytes representation.

write

inline fun <T : Any> BsonFactory.write(obj: T): Bson

Writes an arbitrary Kotlin obj into a top-level BSON document.