mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
* [Kotlin] Add kotlin generate code for tests and add kotlin test to TestAll.sh * [Kotlin] Add Kotlin generator This change adds support for generating Kotlin classes. The approach of this generator is to keep it as close as possible to the java generator for now, in order to keep the change simple. It uses the already implemented java runtime, so we don't support cross-platform nor js Kotlin yet. Kotlin tests are just a copy of the java tests. * Add optional ident support for CodeWriter Identation is important for some languages and different projects have different ways of ident code, e.g. tabs vs spaces, so we are adding optional support on CodeWriter for identation. * [Kotlin] Add Documentation for Kotlin * [Kotlin] Modify generated code to use experimental Unsigned types.
81 lines
2.8 KiB
Kotlin
81 lines
2.8 KiB
Kotlin
// automatically generated by the FlatBuffers compiler, do not modify
|
|
|
|
package MyGame.Example
|
|
|
|
import java.nio.*
|
|
import kotlin.math.sign
|
|
import com.google.flatbuffers.*
|
|
|
|
@Suppress("unused")
|
|
@ExperimentalUnsignedTypes
|
|
class Referrable : Table() {
|
|
|
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
|
__reset(_i, _bb)
|
|
}
|
|
fun __assign(_i: Int, _bb: ByteBuffer) : Referrable {
|
|
__init(_i, _bb)
|
|
return this
|
|
}
|
|
val id : ULong
|
|
get() {
|
|
val o = __offset(4)
|
|
return if(o != 0) bb.getLong(o + bb_pos).toULong() else 0UL
|
|
}
|
|
fun mutateId(id: ULong) : Boolean {
|
|
val o = __offset(4)
|
|
return if (o != 0) {
|
|
bb.putLong(o + bb_pos, id.toLong())
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
override fun keysCompare(o1: Int, o2: Int, _bb: ByteBuffer) : Int {
|
|
val val_1 = _bb.getLong(__offset(4, o1, _bb))
|
|
val val_2 = _bb.getLong(__offset(4, o2, _bb))
|
|
return (val_1 - val_2).sign
|
|
}
|
|
companion object {
|
|
fun validateVersion() = Constants.FLATBUFFERS_1_11_1()
|
|
fun getRootAsReferrable(_bb: ByteBuffer): Referrable = getRootAsReferrable(_bb, Referrable())
|
|
fun getRootAsReferrable(_bb: ByteBuffer, obj: Referrable): Referrable {
|
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
|
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
|
}
|
|
fun createReferrable(builder: FlatBufferBuilder, id: ULong) : Int {
|
|
builder.startTable(1)
|
|
addId(builder, id)
|
|
return endReferrable(builder)
|
|
}
|
|
fun startReferrable(builder: FlatBufferBuilder) = builder.startTable(1)
|
|
fun addId(builder: FlatBufferBuilder, id: ULong) = builder.addLong(0, id.toLong(), 0)
|
|
fun endReferrable(builder: FlatBufferBuilder) : Int {
|
|
val o = builder.endTable()
|
|
return o
|
|
}
|
|
fun __lookup_by_key(obj: Referrable?, vectorLocation: Int, key: ULong, bb: ByteBuffer) : Referrable? {
|
|
var span = bb.getInt(vectorLocation - 4)
|
|
var start = 0
|
|
while (span != 0) {
|
|
var middle = span / 2
|
|
val tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb)
|
|
val value = bb.getLong(__offset(4, bb.capacity() - tableOffset, bb)).toULong()
|
|
val comp = value.compareTo(key)
|
|
when {
|
|
comp > 0 -> span = middle
|
|
comp < 0 -> {
|
|
middle++
|
|
start += middle
|
|
span -= middle
|
|
}
|
|
else -> {
|
|
return (obj ?: Referrable()).__assign(tableOffset, bb)
|
|
}
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
}
|
|
}
|