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

commonMain.kotlinx.serialization.json.internal.JsonElementMarker.kt Maven / Gradle / Ivy

/*
 * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")

package kotlinx.serialization.json.internal

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.internal.ElementMarker

@OptIn(ExperimentalSerializationApi::class)
internal class JsonElementMarker(descriptor: SerialDescriptor) {
    private val origin: ElementMarker = ElementMarker(descriptor, ::readIfAbsent)

    internal var isUnmarkedNull: Boolean = false
        private set

    internal fun mark(index: Int) {
        origin.mark(index)
    }

    internal fun nextUnmarkedIndex(): Int {
        return origin.nextUnmarkedIndex()
    }

    private fun readIfAbsent(descriptor: SerialDescriptor, index: Int): Boolean {
        isUnmarkedNull = !descriptor.isElementOptional(index) && descriptor.getElementDescriptor(index).isNullable
        return isUnmarkedNull
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy