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

commonMain.maryk.core.yaml.MarykYamlReader.kt Maven / Gradle / Ivy

Go to download

Maryk is a Kotlin Multiplatform library which helps you to store, query and send data in a structured way over multiple platforms. The data store stores any value with a version, so it is possible to request only the changed data or live listen for updates.

The newest version!
@file:Suppress("FunctionName")

package maryk.core.yaml

import maryk.core.properties.definitions.PropertyDefinitionType
import maryk.core.properties.definitions.index.IndexKeyPartType
import maryk.json.IsJsonLikeReader
import maryk.json.TokenType
import maryk.yaml.YamlReader

const val maryk2018 = "tag:maryk.io,2018:"

/** Creates a Yaml reader preset to read Maryk Models */
fun MarykYamlModelReader(
    yaml: String
): IsJsonLikeReader {
    var index = 0
    return MarykYamlModelReader {
        yaml[index++].also {
            if (it == '\u0000') {
                // So JS correctly exits at end of string
                throw Throwable("0 char encountered")
            }
        }
    }
}

/** Creates a Yaml reader preset to read Maryk Models */
@Suppress("FunctionName")
fun MarykYamlModelReader(
    reader: () -> Char
): IsJsonLikeReader =
    YamlReader(
        defaultTag = maryk2018,
        tagMap = mapOf(
            maryk2018 to marykTypeMap
        ),
        allowUnknownTags = false,
        reader = reader
    )

/** Creates a Yaml reader preset to read Maryk */
fun MarykYamlReader(
    yaml: String
): IsJsonLikeReader {
    var index = 0
    return MarykYamlReader {
        yaml[index++].also {
            if (it == '\u0000') {
                // So JS correctly exits at end of string
                throw Throwable("0 char encountered")
            }
        }
    }
}

/** Creates a Yaml reader preset to read Maryk */
@Suppress("FunctionName")
fun MarykYamlReader(
    reader: () -> Char
): IsJsonLikeReader =
    YamlReader(
        defaultTag = maryk2018,
        tagMap = mapOf(maryk2018 to marykTypeMap),
        allowUnknownTags = true,
        reader = reader
    )

val marykTypeMap: Map = arrayOf>()
    .plus(
        PropertyDefinitionType.values().map { it.name to it }
    )
    .plus(
        IndexKeyPartType.cases().map { it.name to it }
    ).toMap()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy