xref: /aosp_15_r20/external/flatbuffers/tests/MyGame/Example/Stat.kt (revision 890232f25432b36107d06881e0a25aaa6b473652)
1 // automatically generated by the FlatBuffers compiler, do not modify
2 
3 package MyGame.Example
4 
5 import java.nio.*
6 import kotlin.math.sign
7 import com.google.flatbuffers.*
8 
9 @Suppress("unused")
10 class Stat : Table() {
11 
__initnull12     fun __init(_i: Int, _bb: ByteBuffer)  {
13         __reset(_i, _bb)
14     }
__assignnull15     fun __assign(_i: Int, _bb: ByteBuffer) : Stat {
16         __init(_i, _bb)
17         return this
18     }
19     val id : String?
20         get() {
21             val o = __offset(4)
22             return if (o != 0) __string(o + bb_pos) else null
23         }
24     val idAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
idInByteBuffernull25     fun idInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
26     val val_ : Long
27         get() {
28             val o = __offset(6)
29             return if(o != 0) bb.getLong(o + bb_pos) else 0L
30         }
mutateVal_null31     fun mutateVal_(val_: Long) : Boolean {
32         val o = __offset(6)
33         return if (o != 0) {
34             bb.putLong(o + bb_pos, val_)
35             true
36         } else {
37             false
38         }
39     }
40     val count : UShort
41         get() {
42             val o = __offset(8)
43             return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
44         }
mutateCountnull45     fun mutateCount(count: UShort) : Boolean {
46         val o = __offset(8)
47         return if (o != 0) {
48             bb.putShort(o + bb_pos, count.toShort())
49             true
50         } else {
51             false
52         }
53     }
keysComparenull54     override fun keysCompare(o1: Int, o2: Int, _bb: ByteBuffer) : Int {
55         val val_1 = _bb.getShort(__offset(8, o1, _bb))
56         val val_2 = _bb.getShort(__offset(8, o2, _bb))
57         return (val_1 - val_2).sign
58     }
59     companion object {
validateVersionnull60         fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
61         fun getRootAsStat(_bb: ByteBuffer): Stat = getRootAsStat(_bb, Stat())
62         fun getRootAsStat(_bb: ByteBuffer, obj: Stat): Stat {
63             _bb.order(ByteOrder.LITTLE_ENDIAN)
64             return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
65         }
createStatnull66         fun createStat(builder: FlatBufferBuilder, idOffset: Int, val_: Long, count: UShort) : Int {
67             builder.startTable(3)
68             addVal_(builder, val_)
69             addId(builder, idOffset)
70             addCount(builder, count)
71             return endStat(builder)
72         }
startStatnull73         fun startStat(builder: FlatBufferBuilder) = builder.startTable(3)
74         fun addId(builder: FlatBufferBuilder, id: Int) = builder.addOffset(0, id, 0)
75         fun addVal_(builder: FlatBufferBuilder, val_: Long) = builder.addLong(1, val_, 0L)
76         fun addCount(builder: FlatBufferBuilder, count: UShort)  {
77             builder.addShort(count.toShort())
78             builder.slot(2)
79         }
endStatnull80         fun endStat(builder: FlatBufferBuilder) : Int {
81             val o = builder.endTable()
82             return o
83         }
__lookup_by_keynull84         fun __lookup_by_key(obj: Stat?, vectorLocation: Int, key: UShort, bb: ByteBuffer) : Stat? {
85             var span = bb.getInt(vectorLocation - 4)
86             var start = 0
87             while (span != 0) {
88                 var middle = span / 2
89                 val tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb)
90                 val value = bb.getShort(__offset(8, bb.capacity() - tableOffset, bb)).toUShort()
91                 val comp = value.compareTo(key)
92                 when {
93                     comp > 0 -> span = middle
94                     comp < 0 -> {
95                         middle++
96                         start += middle
97                         span -= middle
98                     }
99                     else -> {
100                         return (obj ?: Stat()).__assign(tableOffset, bb)
101                     }
102                 }
103             }
104             return null
105         }
106     }
107 }
108