Removed IO dependency from Output

This commit is contained in:
Alexander Nozik 2020-10-17 17:22:34 +03:00
parent 01c209d1d6
commit d6ed5f94e4
6 changed files with 26 additions and 8 deletions

View File

@ -9,6 +9,7 @@
- Empty query in Name is null instead of ""
- Provider provides an empty map instead of error by default
- Hidden delegates hierarchy in favor of stdlib properties
- Removed io depdendency from `dataforge-output`. Replaced Output by Appendable.
### Deprecated
- Context activation API

View File

@ -12,7 +12,7 @@ allprojects {
group = "hep.dataforge"
version = dataforgeVersion
apply(plugin = "org.jetbrains.dokka")
apply<org.jetbrains.dokka.gradle.DokkaPlugin>()
repositories {
mavenLocal()

View File

@ -0,0 +1,18 @@
package hep.dataforge.names
import kotlinx.serialization.json.Json
import kotlin.test.Test
import kotlin.test.assertEquals
class NameSerializationTest {
@Test
fun testNameSerialization() {
val name = "aaa.bbb.ccc".toName()
val json = Json.encodeToJsonElement(Name.serializer(), name)
println(json)
val reconstructed = Json.decodeFromJsonElement(Name.serializer(), json)
assertEquals(name, reconstructed)
}
}

View File

@ -8,7 +8,7 @@ kotlin {
val commonMain by getting{
dependencies {
api(project(":dataforge-context"))
api(project(":dataforge-io"))
//api(project(":dataforge-io"))
}
}
}

View File

@ -7,8 +7,6 @@ import hep.dataforge.provider.Type
import hep.dataforge.provider.top
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.io.Output
import kotlinx.io.text.writeUtf8String
import kotlin.reflect.KClass
@ -26,7 +24,7 @@ public interface TextFormat {
*/
public val type: KClass<*>
public suspend fun Output.render(obj: Any)
public suspend fun Appendable.render(obj: Any)
public companion object {
public const val TEXT_RENDERER_TYPE: String = "dataforge.textRenderer"
@ -37,15 +35,15 @@ public object DefaultTextFormat : TextFormat {
override val priority: Int = Int.MAX_VALUE
override val type: KClass<*> = Any::class
override suspend fun Output.render(obj: Any) {
writeUtf8String(obj.toString() + "\n")
override suspend fun Appendable.render(obj: Any) {
append(obj.toString() + "\n")
}
}
/**
* A text-based renderer
*/
public class TextRenderer(override val context: Context, private val output: Output) : Renderer<Any> {
public class TextRenderer(override val context: Context, private val output: Appendable) : Renderer<Any> {
private val cache = HashMap<KClass<*>, TextFormat>()
/**

View File

@ -10,6 +10,7 @@ kotlin {
api(project(":dataforge-context"))
api(project(":dataforge-data"))
api(project(":dataforge-output"))
api(project(":dataforge-io"))
}
}
}