Created
August 30, 2017 11:34
-
-
Save lukashaertel/62260de0519f5bb4dc8497a8f8c5643e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.metatools.kfunnels.tests | |
import eu.metatools.kfunnels.* | |
/** | |
* Funnels and unfunnels Container. | |
*/ | |
object ContainerFunneler : GeneratedFunneler<Container<*, *>> { | |
override val module = eu.metatools.kfunnels.tests.TestsModule | |
override val type = Container::class | |
override fun read(module: Module, type: Type, source: SeqSource): Container<*, *> { | |
val T__type = +type.args[0] | |
val T_ = module.resolve<Any?>(T__type) | |
val U_type = +type.args[1] | |
val U = module.resolve<Any?>(U_type) | |
val entry0 = source.readIfNotNull { | |
source.beginNested() | |
val r = T_.read(module, T__type, source) | |
source.endNested() | |
r | |
} | |
source.beginNested() | |
val entry1 = U.read(module, U_type, source) | |
source.endNested() | |
return Container(entry0, entry1).apply { | |
} | |
} | |
override fun read(module: Module, type: Type, source: LabelSource): Container<*, *> { | |
val T__type = +type.args[0] | |
val T_ = module.resolve<Any?>(T__type) | |
val U_type = +type.args[1] | |
val U = module.resolve<Any?>(U_type) | |
source.beginNested("t") | |
val entry0 = T_.read(module, T__type, source) | |
source.endNested() | |
source.beginNested("u") | |
val entry1 = U.read(module, U_type, source) | |
source.endNested() | |
return Container(entry0, entry1).apply { | |
} | |
} | |
override fun write(module: Module, type: Type, sink: SeqSink, item: Container<*, *>) { | |
val T__type = +type.args[0] | |
val T_ = module.resolve<Any?>(T__type) | |
val U_type = +type.args[1] | |
val U = module.resolve<Any?>(U_type) | |
if(item.t == null) | |
sink.putNull(true) | |
else { | |
sink.putNull(false) | |
sink.beginNested() | |
T_.write(module, T__type, sink, item.t) | |
sink.endNested() | |
} | |
sink.beginNested() | |
U.write(module, U_type, sink, item.u) | |
sink.endNested() | |
} | |
override fun write(module: Module, type: Type, sink: LabelSink, item: Container<*, *>) { | |
val T__type = +type.args[0] | |
val T_ = module.resolve<Any?>(T__type) | |
val U_type = +type.args[1] | |
val U = module.resolve<Any?>(U_type) | |
if(item.t == null) | |
sink.putNull("t", true) | |
else { | |
sink.putNull("t", false) | |
sink.beginNested("t") | |
T_.write(module, T__type, sink, item.t) | |
sink.endNested() | |
} | |
sink.beginNested("u") | |
U.write(module, U_type, sink, item.u) | |
sink.endNested() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment