feat: port the client to MyGo native UI (0.3.0)

Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
This commit is contained in:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

@@ -0,0 +1 @@
/build
@@ -0,0 +1,15 @@
// The Kotlin of the native module roundtrip: an Android library, which mygo
// build adds to the app's Gradle build. The build sets its SDK levels, Java
// and Kotlin, and its dependency on MyGo's host library (dev.mygo), which
// brings coroutines: add only what the implementation uses.
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.github.egoist.mygo.native_.internal.roundtrip"
}
dependencies {
}
@@ -0,0 +1,126 @@
package com.github.egoist.mygo.native_.internal.roundtrip
import android.graphics.RectF
import dev.mygo.NativeBuffer
import dev.mygo.NativeCloser
import dev.mygo.NativeException
import dev.mygo.NativeUnsupportedException
import java.time.Instant
import java.util.Timer
import java.util.concurrent.atomic.AtomicLong
import kotlin.concurrent.fixedRateTimer
import kotlin.time.Duration
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
// The implementation of package roundtrip on Android: every value it is
// given, back, as the Swift, Rust and Zig ones do.
fun makeEcho(): Echo = Echoer()
private class Echoer : Echo {
override fun scalars(i: Long, i8: Byte, u16: UShort, i32: Int, u64: ULong, f32: Float, f: Double, b: Boolean): Scalars =
Scalars(i + 1, (i8 + 1).toByte(), (u16 + 1u).toUShort(), i32 + 1, u64 + 1u, f32 + 1, f + 1, !b)
override fun add(a: Long, b: Long): Long = a + b
override fun text(s: String, b: ByteArray): Texts = Texts(s + s, b.reversedArray())
override fun record(r: Record): Record = r.copy(counts = r.counts.map { it * 2 })
override fun lists(words: List<String>, nested: List<List<Long>>): Map<String, Long> {
val m = HashMap<String, Long>()
for (w in words) m[w] = w.toByteArray(Charsets.UTF_8).size.toLong()
m["nested"] = nested.sumOf { it.sum() }
return m
}
override fun maybe(p: Long?): Long? = p?.plus(1)
override fun times(t: Instant, d: Duration): Moment = Moment(t.plusNanos(d.inWholeNanoseconds), d * 2)
override fun kind(k: Kind, l: Level): Kinds {
val all = Kind.entries
return Kinds(all[(all.indexOf(k) + 1) % all.size], if (l == Level.LOW) Level.HIGH else Level.LOW)
}
override fun fail(name: String) {
when (name) {
"" -> return
"named" -> throw RoundtripException(RoundtripError.NAMED)
"unsupported" -> throw NativeUnsupportedException()
else -> throw NativeException("RoundtripDomain", 7, name)
}
}
override suspend fun wait(d: Duration, s: String): String {
delay(d)
return s
}
override fun count(n: Long, fail: Long): Flow<Long> = flow {
for (i in 0 until n) {
if (i == fail) throw RoundtripException(RoundtripError.NAMED)
emit(i)
}
}
override fun records(n: Long): Flow<Record> = flow {
for (i in 0 until n) {
emit(Record("r$i", listOf(i), mapOf("i" to "$i"), Inner(i.toDouble(), 0.0), null, Kind.KIND_A, byteArrayOf(i.toByte())))
}
}
override fun counter(n: Long): Counter = Counting(n)
override fun each(words: List<String>, f: (String, Long) -> Unit): Long {
words.forEachIndexed { i, w -> f(w, i.toLong()) }
return words.size.toLong()
}
override fun ask(ns: List<Long>, f: (Long) -> Long): Long = ns.sumOf { f(it) }
override fun ticks(interval: Duration, f: (Long) -> Unit): AutoCloseable {
var n = 0L
val period = maxOf(interval.inWholeMilliseconds, 1)
val timer: Timer = fixedRateTimer("roundtrip-ticks", daemon = true, initialDelay = period, period = period) {
n++
f(n)
}
return NativeCloser { timer.cancel() }
}
override suspend fun use(s: Scorer, words: List<String>): Double {
var sum = words.sumOf { s.score(it) }
words.firstOrNull()?.let { sum += s.explain(it).toByteArray(Charsets.UTF_8).size }
return sum
}
override fun fill(buf: NativeBuffer, x: Long): Long {
val b = buf.bytes
for (i in 0 until buf.size) b.put(i, (i.toLong() xor x).toByte())
return buf.size.toLong()
}
override fun mix(f: Float, d: Double, b: Boolean, i: Byte): Double = f + d + (if (b) 1 else 0) + i
override fun box(r: RectF): RectF = RectF(r).apply { offset(r.width(), r.height()) }
override fun nothing(e: List<Empty>): Long = e.size.toLong()
override fun onMain(r: Record, f: (Inner) -> Unit): Texts {
f(r.inner)
return Texts(r.name, r.data)
}
}
private class Counting(start: Long) : Counter {
private val n = AtomicLong(start)
override fun next(): Long = n.getAndIncrement()
override fun same(): Counter = Counting(n.get())
override fun close() {}
}
@@ -0,0 +1,742 @@
// Code generated by mygo generate from the interfaces of the native module. DO NOT EDIT.
// mygo:native 3 aebdfd9f7bfb2215
//
// The declarations of package roundtrip, which the implementation implements,
// and the object Go calls. See docs/native-modules.md.
@file:Suppress("unused", "UNUSED_PARAMETER", "UNUSED_VARIABLE", "RedundantVisibilityModifier", "FunctionName", "ClassName", "LocalVariableName")
package com.github.egoist.mygo.native_.internal.roundtrip
import dev.mygo.GoFunc
import dev.mygo.NativeBuffer
import dev.mygo.NativeCodedError
import dev.mygo.NativeModule
import dev.mygo.NativeReader
import dev.mygo.NativeWireException
import dev.mygo.NativeWriter
import kotlinx.coroutines.flow.Flow
/**
* Echo returns what it is given.
*/
interface Echo {
/**
* Scalars returns its arguments, one more each.
*/
fun scalars(i: Long, i8: Byte, u16: UShort, i32: Int, u64: ULong, f32: Float, f: Double, b: Boolean): Scalars
/**
* Add is a plain sum, the cheapest call.
*/
fun add(a: Long, b: Long): Long
/**
* Text returns s twice, and b reversed.
*/
fun text(s: String, b: ByteArray): Texts
/**
* Record returns r with its counts doubled.
*/
fun record(r: Record): Record
/**
* Lists returns the lengths of the words, and a map of each to its
* length.
*/
fun lists(words: List<String>, nested: List<List<Long>>): Map<String, Long>
/**
* Maybe returns p's value plus one, or nil for nil.
*/
fun maybe(p: Long?): Long?
/**
* Times returns t moved by d, and d doubled.
*/
fun times(t: java.time.Instant, d: kotlin.time.Duration): Moment
/**
* Kind returns the next kind, and the next level.
*/
fun kind(k: Kind, l: Level): Kinds
/**
* Fail throws the error named, or nothing for "".
*/
fun fail(name: String)
/**
* Wait waits d, or until ctx is done, then returns s.
*/
suspend fun wait(d: kotlin.time.Duration, s: String): String
/**
* Count yields 0 to n-1, failing at fail when it is not -1.
*/
fun count(n: Long, fail: Long): Flow<Long>
/**
* Records yields n records.
*/
fun records(n: Long): Flow<Record>
/**
* Counter makes a counter starting at n.
*/
fun counter(n: Long): Counter
/**
* Each calls f with each word and its index, and returns how many.
*/
fun each(words: List<String>, f: (String, Long) -> kotlin.Unit): Long
/**
* Ask asks f for the double of each number, and returns their sum.
*/
fun ask(ns: List<Long>, f: (Long) -> Long): Long
/**
* Ticks calls f every interval until closed.
*/
fun ticks(interval: kotlin.time.Duration, f: (Long) -> kotlin.Unit): AutoCloseable
/**
* Use asks s for a score of each word, and returns their sum.
*/
suspend fun use(s: Scorer, words: List<String>): Double
/**
* Fill writes b's index into each byte of buf, xor x.
*/
fun fill(buf: NativeBuffer, x: Long): Long
/**
* Mix sums numbers of each kind, a call of numbers only.
*/
fun mix(f: Float, d: Double, b: Boolean, i: Byte): Double
/**
* Box returns r moved by its size.
*/
fun box(r: android.graphics.RectF): android.graphics.RectF
/**
* Nothing returns how many structs without fields it was given.
*/
fun nothing(e: List<Empty>): Long
/**
* OnMain runs on the main thread, which go test does not run: the
* tests only build it.
* It runs on the main thread.
*/
fun onMain(r: Record, f: (Inner) -> kotlin.Unit): Texts
}
/**
* Counter counts.
*/
interface Counter : AutoCloseable {
/**
* Next returns the count, then adds one.
*/
fun next(): Long
/**
* Same returns another counter of the same count.
*/
fun same(): Counter
}
/**
* Scorer is implemented by Go.
* Go implements it: the module's Kotlin calls it.
*/
interface Scorer {
/**
* Score scores a word.
*/
fun score(word: String): Double
/**
* Explain explains a score, which may wait.
*/
suspend fun explain(word: String): String
}
/**
* Scalars are the scalars back.
*/
data class Scalars(
val i: Long,
val i8: Byte,
val u16: UShort,
val i32: Int,
val u64: ULong,
val f32: Float,
val f: Double,
val b: Boolean,
)
/**
* Texts are a string and bytes back.
*/
data class Texts(
val s: String,
val b: ByteArray = ByteArray(0),
)
/**
* Inner is nested.
*/
data class Inner(
val x: Double,
val y: Double,
)
/**
* Record is a struct with every kind of field.
*/
data class Record(
val name: String,
val counts: List<Long> = emptyList(),
val tags: Map<String, String> = emptyMap(),
val inner: Inner,
val next: Inner? = null,
val kind: Kind,
val data: ByteArray = ByteArray(0),
)
/**
* Moment is a time and a duration back.
*/
data class Moment(
val at: java.time.Instant,
val twice: kotlin.time.Duration,
)
/**
* Kinds are an enum of each kind back.
*/
data class Kinds(
val kind: Kind,
val level: Level,
)
/**
* Empty has no fields.
*/
class Empty {
override fun equals(other: Any?): Boolean = other is Empty
override fun hashCode(): Int = 0
}
/**
* Kind is a string enum.
*/
enum class Kind(val value: String) {
KIND_A("a"),
KIND_B("b"),
KIND_C("c"),
;
companion object {
/** The constant of a value, which Go sent. */
fun of(value: String): Kind = entries.firstOrNull { it.value == value } ?: throw NativeWireException("native: Kind has no constant $value")
}
}
/**
* Level is an integer enum.
*/
enum class Level(val value: Long) {
LOW(1L),
HIGH(2L),
;
companion object {
/** The constant of a value, which Go sent. */
fun of(value: Long): Level = entries.firstOrNull { it.value == value } ?: throw NativeWireException("native: Level has no constant $value")
}
}
/**
* The errors package roundtrip declares, with native.NewError: throw
* RoundtripException(RoundtripError.X) for Go to get that error, which errors.Is
* compares.
*/
enum class RoundtripError(val code: String) {
/**
* ErrNamed is the error Fail throws for "named".
*/
NAMED("named"),
;
}
/** An error package roundtrip declares. */
class RoundtripException(val error: RoundtripError, message: String = error.code) : Exception(message), NativeCodedError {
override val nativeCode: String get() = error.code
}
/** What Go calls: the functions of the module, by name. */
object MygoModule : NativeModule() {
override fun invoke(sym: String, h: Long, args: ByteArray, call: Long): ByteArray = when (sym) {
"new_Echo" -> answer { _w -> _w.u64(retain(makeEcho())) }
"Echo_Scalars" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.i64()
val _p1 = _a.i64().toByte()
val _p2 = _a.i64().toUShort()
val _p3 = _a.i64().toInt()
val _p4 = _a.i64().toULong()
val _p5 = _a.double().toFloat()
val _p6 = _a.double()
val _p7 = _a.bool()
val _r = _o.scalars(_p0, _p1, _p2, _p3, _p4, _p5, _p6, _p7)
_write_Scalars(_w, _r)
}
"Echo_Add" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.i64()
val _p1 = _a.i64()
val _r = _o.add(_p0, _p1)
_w.i64(_r.toLong())
}
"Echo_Text" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.string()
val _p1 = _a.data()
val _r = _o.text(_p0, _p1)
_write_Texts(_w, _r)
}
"Echo_Record" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_Record(_a)
val _r = _o.record(_p0)
_write_Record(_w, _r)
}
"Echo_Lists" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_slice_string(_a)
val _p1 = _read_slice_slice_int(_a)
val _r = _o.lists(_p0, _p1)
_write_map_int(_w, _r)
}
"Echo_Maybe" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_ptr_int(_a)
val _r = _o.maybe(_p0)
_write_ptr_int(_w, _r)
}
"Echo_Times" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.time()
val _p1 = _a.duration()
val _r = _o.times(_p0, _p1)
_write_Moment(_w, _r)
}
"Echo_Kind" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_Kind(_a)
val _p1 = _read_Level(_a)
val _r = _o.kind(_p0, _p1)
_write_Kinds(_w, _r)
}
"Echo_Fail" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.string()
_o.fail(_p0)
}
"Echo_Wait" -> start {
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.duration()
val _p1 = _a.string()
task(call, false) { _w ->
val _r = _o.wait(_p0, _p1)
_w.string(_r)
}
}
"Echo_Count" -> start {
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.i64()
val _p1 = _a.i64()
stream(call, false, { _o.count(_p0, _p1) }) { _w, _r -> _w.i64(_r.toLong()) }
}
"Echo_Records" -> start {
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.i64()
stream(call, false, { _o.records(_p0) }) { _w, _r -> _write_Record(_w, _r) }
}
"Echo_Counter" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.i64()
val _r = _o.counter(_p0)
_w.u64(MygoModule.handle(_r))
}
"Echo_Each" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_slice_string(_a)
val _p1 = _a.u64()
val _g1 = goFunc(_p1)
val _f1: (String, Long) -> kotlin.Unit = { q0, q1 ->
val _cw = NativeWriter()
_cw.string(q0)
_cw.i64(q1.toLong())
_g1.notify(_cw)
}
val _r = _o.each(_p0, _f1)
_w.i64(_r.toLong())
}
"Echo_Ask" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_slice_int(_a)
val _p1 = _a.u64()
val _g1 = goFunc(_p1)
val _f1: (Long) -> Long = { q0 ->
val _cw = NativeWriter()
_cw.i64(q0.toLong())
_g1.ask(_cw) { _r -> _r.i64() }
}
val _r = _o.ask(_p0, _f1)
_w.i64(_r.toLong())
}
"Echo_Ticks" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.duration()
val _p1 = _a.u64()
val _g1 = goFunc(_p1)
val _f1: (Long) -> kotlin.Unit = { q0 ->
val _cw = NativeWriter()
_cw.i64(q0.toLong())
_g1.notify(_cw)
}
_w.u64(retain(_o.ticks(_p0, _f1)))
}
"Echo_Use" -> start {
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.u64()
val _p1 = _read_slice_string(_a)
task(call, false) { _w ->
val _r = _o.use(_GoScorer(_p0), _p1)
_w.double(_r.toDouble())
}
}
"Echo_Fill" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.buffer()
val _p1 = _a.i64()
val _r = _o.fill(_p0, _p1)
_w.i64(_r.toLong())
}
"Echo_Mix" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.double().toFloat()
val _p1 = _a.double()
val _p2 = _a.bool()
val _p3 = _a.i64().toByte()
val _r = _o.mix(_p0, _p1, _p2, _p3)
_w.double(_r.toDouble())
}
"Echo_Box" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _a.rect()
val _r = _o.box(_p0)
_w.rect(_r)
}
"Echo_Nothing" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_slice_Empty(_a)
val _r = _o.nothing(_p0)
_w.i64(_r.toLong())
}
"Echo_OnMain" -> answer { _w ->
val _o: Echo = obj(h)
val _a = NativeReader(args)
val _p0 = _read_Record(_a)
val _p1 = _a.u64()
val _g1 = goFunc(_p1)
val _f1: (Inner) -> kotlin.Unit = { q0 ->
val _cw = NativeWriter()
_write_Inner(_cw, q0)
_g1.notify(_cw)
}
val _r = _o.onMain(_p0, _f1)
_write_Texts(_w, _r)
}
"Counter_Next" -> answer { _w ->
val _o: Counter = obj(h)
val _r = _o.next()
_w.i64(_r.toLong())
}
"Counter_Same" -> answer { _w ->
val _o: Counter = obj(h)
val _r = _o.same()
_w.u64(MygoModule.handle(_r))
}
"close" -> answer { close(h) }
else -> unknown(sym)
}
override fun direct(sym: String, h: Long, args: LongArray): Long = try {
when (sym) {
"Echo_Add_direct" -> {
obj<Echo>(h).add(args[0], args[1]).toLong()
}
"Echo_Mix_direct" -> {
obj<Echo>(h).mix(Double.fromBits(args[0]).toFloat(), Double.fromBits(args[1]), args[2] != 0L, args[3].toByte()).toDouble().toRawBits()
}
"Counter_Next_direct" -> {
obj<Counter>(h).next().toLong()
}
else -> 0L
}
} catch (e: Throwable) {
0L
}
override fun error(code: String): Throwable? = RoundtripError.entries.firstOrNull { it.code == code }?.let { RoundtripException(it) }
/** A handle of an object of the implementation, which Go holds. */
fun handle(v: Any): Long = retain(v)
}
/** Calls a Go value implementing Scorer. */
internal class _GoScorer(private val _id: Long) : Scorer {
init {
if (_id == 0L) throw NativeWireException("Roundtrip: Go passed nil for Scorer")
MygoModule.releaseWith(this, _id)
}
override fun score(word: String): Double {
val _w = NativeWriter()
_w.i64(0)
_w.string(word)
return MygoModule.invokeGo(_id, _w) { _r -> _r.double() }
}
override suspend fun explain(word: String): String {
val _w = NativeWriter()
_w.i64(1)
_w.string(word)
return MygoModule.invokeGoAsync(_id, _w) { _r -> _r.string() }
}
}
private fun _read_Empty(r: NativeReader): Empty {
r.bool()
return Empty()
}
private fun _write_Empty(w: NativeWriter, v: Empty) {
w.bool(false)
}
private fun _read_Inner(r: NativeReader): Inner {
return Inner(
x = r.double(),
y = r.double(),
)
}
private fun _write_Inner(w: NativeWriter, v: Inner) {
w.double(v.x.toDouble())
w.double(v.y.toDouble())
}
private fun _read_Kind(r: NativeReader): Kind {
return Kind.of(r.string())
}
private fun _write_Kind(w: NativeWriter, v: Kind) {
w.string(v.value)
}
private fun _read_Kinds(r: NativeReader): Kinds {
return Kinds(
kind = _read_Kind(r),
level = _read_Level(r),
)
}
private fun _write_Kinds(w: NativeWriter, v: Kinds) {
_write_Kind(w, v.kind)
_write_Level(w, v.level)
}
private fun _read_Level(r: NativeReader): Level {
return Level.of(r.i64())
}
private fun _write_Level(w: NativeWriter, v: Level) {
w.i64(v.value)
}
private fun _read_Moment(r: NativeReader): Moment {
return Moment(
at = r.time(),
twice = r.duration(),
)
}
private fun _write_Moment(w: NativeWriter, v: Moment) {
w.time(v.at)
w.duration(v.twice)
}
private fun _read_Record(r: NativeReader): Record {
return Record(
name = r.string(),
counts = _read_slice_int(r),
tags = _read_map_string(r),
inner = _read_Inner(r),
next = _read_ptr_Inner(r),
kind = _read_Kind(r),
data = r.data(),
)
}
private fun _write_Record(w: NativeWriter, v: Record) {
w.string(v.name)
_write_slice_int(w, v.counts)
_write_map_string(w, v.tags)
_write_Inner(w, v.inner)
_write_ptr_Inner(w, v.next)
_write_Kind(w, v.kind)
w.data(v.data)
}
private fun _read_Scalars(r: NativeReader): Scalars {
return Scalars(
i = r.i64(),
i8 = r.i64().toByte(),
u16 = r.i64().toUShort(),
i32 = r.i64().toInt(),
u64 = r.i64().toULong(),
f32 = r.double().toFloat(),
f = r.double(),
b = r.bool(),
)
}
private fun _write_Scalars(w: NativeWriter, v: Scalars) {
w.i64(v.i.toLong())
w.i64(v.i8.toLong())
w.i64(v.u16.toLong())
w.i64(v.i32.toLong())
w.i64(v.u64.toLong())
w.double(v.f32.toDouble())
w.double(v.f.toDouble())
w.bool(v.b)
}
private fun _read_Texts(r: NativeReader): Texts {
return Texts(
s = r.string(),
b = r.data(),
)
}
private fun _write_Texts(w: NativeWriter, v: Texts) {
w.string(v.s)
w.data(v.b)
}
private fun _read_map_int(r: NativeReader): Map<String, Long> {
val n = r.count()
val v = LinkedHashMap<String, Long>(n)
repeat(n) {
val k = r.string()
v[k] = r.i64()
}
return v
}
private fun _write_map_int(w: NativeWriter, v: Map<String, Long>) {
w.count(v.size)
for ((k, x) in v) {
w.string(k)
w.i64(x.toLong())
}
}
private fun _read_map_string(r: NativeReader): Map<String, String> {
val n = r.count()
val v = LinkedHashMap<String, String>(n)
repeat(n) {
val k = r.string()
v[k] = r.string()
}
return v
}
private fun _write_map_string(w: NativeWriter, v: Map<String, String>) {
w.count(v.size)
for ((k, x) in v) {
w.string(k)
w.string(x)
}
}
private fun _read_ptr_Inner(r: NativeReader): Inner? {
return if (r.bool()) _read_Inner(r) else null
}
private fun _write_ptr_Inner(w: NativeWriter, v: Inner?) {
if (v == null) {
w.bool(false)
} else {
w.bool(true)
_write_Inner(w, v)
}
}
private fun _read_ptr_int(r: NativeReader): Long? {
return if (r.bool()) r.i64() else null
}
private fun _write_ptr_int(w: NativeWriter, v: Long?) {
if (v == null) {
w.bool(false)
} else {
w.bool(true)
w.i64(v.toLong())
}
}
private fun _read_slice_Empty(r: NativeReader): List<Empty> {
val n = r.count()
return List(n) { _read_Empty(r) }
}
private fun _write_slice_Empty(w: NativeWriter, v: List<Empty>) {
w.count(v.size)
for (x in v) _write_Empty(w, x)
}
private fun _read_slice_int(r: NativeReader): List<Long> {
val n = r.count()
return List(n) { r.i64() }
}
private fun _write_slice_int(w: NativeWriter, v: List<Long>) {
w.count(v.size)
for (x in v) w.i64(x.toLong())
}
private fun _read_slice_slice_int(r: NativeReader): List<List<Long>> {
val n = r.count()
return List(n) { _read_slice_int(r) }
}
private fun _write_slice_slice_int(w: NativeWriter, v: List<List<Long>>) {
w.count(v.size)
for (x in v) _write_slice_int(w, x)
}
private fun _read_slice_string(r: NativeReader): List<String> {
val n = r.count()
return List(n) { r.string() }
}
private fun _write_slice_string(w: NativeWriter, v: List<String>) {
w.count(v.size)
for (x in v) w.string(x)
}