Skip to content

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

BsonArrayReader

@LowLevelApi
interface BsonArrayReader

Utilities for decomposing a BsonArray into its elements.

To obtain an instance of this interface, see BsonArray.reader.

Example

val bson: BsonArray = 

for ((index, field) in bson.read().elements.withIndex()) {
    println("[$index] • ${field.type}")
}

Implementation constraints

Different implementations of BsonArrayReader should be considered equal if they have the same elements in the same order. The methods BsonArrayReader.Companion.equals and BsonArrayReader.Companion.hashCode are provided to facilitate implementation.

Types

Companion

object Companion

Properties

elements

abstract val elements: List<BsonValueReader>

A list of all elements in this reader.

indices

open val indices: IntRange

A range of the valid indices in this array.

size

open val size: Int

The number of elements in this array.

Functions

asValue

abstract fun asValue(): BsonValueReader

Reads this entire array as a BsonValueReader.

diff

@LowLevelApi
infix fun BsonArrayReader.diff(other: BsonArrayReader): String?

Analyzes the difference between two BSON arrays.

read

abstract fun read(index: Int): BsonValueReader?

Attempts to read an element at index index.

abstract fun <T : Any> read(type: KType, klass: KClass<T>): T?

Reads this document into an instance of type.

toBson

abstract fun toBson(): BsonArray

Reads this document into a BsonArray instance.

toString

abstract override fun toString(): String

JSON representation of the array this BsonArrayReader is reading, as a String.