1 package flatbuffers
2
3
4
5
6 type Table struct {
7 Bytes []byte
8 Pos UOffsetT
9 }
10
11
12
13
14 func (t *Table) Offset(vtableOffset VOffsetT) VOffsetT {
15 vtable := UOffsetT(SOffsetT(t.Pos) - t.GetSOffsetT(t.Pos))
16 if vtableOffset < t.GetVOffsetT(vtable) {
17 return t.GetVOffsetT(vtable + UOffsetT(vtableOffset))
18 }
19 return 0
20 }
21
22
23 func (t *Table) Indirect(off UOffsetT) UOffsetT {
24 return off + GetUOffsetT(t.Bytes[off:])
25 }
26
27
28 func (t *Table) String(off UOffsetT) string {
29 b := t.ByteVector(off)
30 return byteSliceToString(b)
31 }
32
33
34 func (t *Table) ByteVector(off UOffsetT) []byte {
35 off += GetUOffsetT(t.Bytes[off:])
36 start := off + UOffsetT(SizeUOffsetT)
37 length := GetUOffsetT(t.Bytes[off:])
38 return t.Bytes[start : start+length]
39 }
40
41
42
43 func (t *Table) VectorLen(off UOffsetT) int {
44 off += t.Pos
45 off += GetUOffsetT(t.Bytes[off:])
46 return int(GetUOffsetT(t.Bytes[off:]))
47 }
48
49
50
51 func (t *Table) Vector(off UOffsetT) UOffsetT {
52 off += t.Pos
53 x := off + GetUOffsetT(t.Bytes[off:])
54
55 x += UOffsetT(SizeUOffsetT)
56 return x
57 }
58
59
60
61 func (t *Table) Union(t2 *Table, off UOffsetT) {
62 off += t.Pos
63 t2.Pos = off + t.GetUOffsetT(off)
64 t2.Bytes = t.Bytes
65 }
66
67
68 func (t *Table) GetBool(off UOffsetT) bool {
69 return GetBool(t.Bytes[off:])
70 }
71
72
73 func (t *Table) GetByte(off UOffsetT) byte {
74 return GetByte(t.Bytes[off:])
75 }
76
77
78 func (t *Table) GetUint8(off UOffsetT) uint8 {
79 return GetUint8(t.Bytes[off:])
80 }
81
82
83 func (t *Table) GetUint16(off UOffsetT) uint16 {
84 return GetUint16(t.Bytes[off:])
85 }
86
87
88 func (t *Table) GetUint32(off UOffsetT) uint32 {
89 return GetUint32(t.Bytes[off:])
90 }
91
92
93 func (t *Table) GetUint64(off UOffsetT) uint64 {
94 return GetUint64(t.Bytes[off:])
95 }
96
97
98 func (t *Table) GetInt8(off UOffsetT) int8 {
99 return GetInt8(t.Bytes[off:])
100 }
101
102
103 func (t *Table) GetInt16(off UOffsetT) int16 {
104 return GetInt16(t.Bytes[off:])
105 }
106
107
108 func (t *Table) GetInt32(off UOffsetT) int32 {
109 return GetInt32(t.Bytes[off:])
110 }
111
112
113 func (t *Table) GetInt64(off UOffsetT) int64 {
114 return GetInt64(t.Bytes[off:])
115 }
116
117
118 func (t *Table) GetFloat32(off UOffsetT) float32 {
119 return GetFloat32(t.Bytes[off:])
120 }
121
122
123 func (t *Table) GetFloat64(off UOffsetT) float64 {
124 return GetFloat64(t.Bytes[off:])
125 }
126
127
128 func (t *Table) GetUOffsetT(off UOffsetT) UOffsetT {
129 return GetUOffsetT(t.Bytes[off:])
130 }
131
132
133 func (t *Table) GetVOffsetT(off UOffsetT) VOffsetT {
134 return GetVOffsetT(t.Bytes[off:])
135 }
136
137
138 func (t *Table) GetSOffsetT(off UOffsetT) SOffsetT {
139 return GetSOffsetT(t.Bytes[off:])
140 }
141
142
143
144
145 func (t *Table) GetBoolSlot(slot VOffsetT, d bool) bool {
146 off := t.Offset(slot)
147 if off == 0 {
148 return d
149 }
150
151 return t.GetBool(t.Pos + UOffsetT(off))
152 }
153
154
155
156
157 func (t *Table) GetByteSlot(slot VOffsetT, d byte) byte {
158 off := t.Offset(slot)
159 if off == 0 {
160 return d
161 }
162
163 return t.GetByte(t.Pos + UOffsetT(off))
164 }
165
166
167
168
169 func (t *Table) GetInt8Slot(slot VOffsetT, d int8) int8 {
170 off := t.Offset(slot)
171 if off == 0 {
172 return d
173 }
174
175 return t.GetInt8(t.Pos + UOffsetT(off))
176 }
177
178
179
180
181 func (t *Table) GetUint8Slot(slot VOffsetT, d uint8) uint8 {
182 off := t.Offset(slot)
183 if off == 0 {
184 return d
185 }
186
187 return t.GetUint8(t.Pos + UOffsetT(off))
188 }
189
190
191
192
193 func (t *Table) GetInt16Slot(slot VOffsetT, d int16) int16 {
194 off := t.Offset(slot)
195 if off == 0 {
196 return d
197 }
198
199 return t.GetInt16(t.Pos + UOffsetT(off))
200 }
201
202
203
204
205 func (t *Table) GetUint16Slot(slot VOffsetT, d uint16) uint16 {
206 off := t.Offset(slot)
207 if off == 0 {
208 return d
209 }
210
211 return t.GetUint16(t.Pos + UOffsetT(off))
212 }
213
214
215
216
217 func (t *Table) GetInt32Slot(slot VOffsetT, d int32) int32 {
218 off := t.Offset(slot)
219 if off == 0 {
220 return d
221 }
222
223 return t.GetInt32(t.Pos + UOffsetT(off))
224 }
225
226
227
228
229 func (t *Table) GetUint32Slot(slot VOffsetT, d uint32) uint32 {
230 off := t.Offset(slot)
231 if off == 0 {
232 return d
233 }
234
235 return t.GetUint32(t.Pos + UOffsetT(off))
236 }
237
238
239
240
241 func (t *Table) GetInt64Slot(slot VOffsetT, d int64) int64 {
242 off := t.Offset(slot)
243 if off == 0 {
244 return d
245 }
246
247 return t.GetInt64(t.Pos + UOffsetT(off))
248 }
249
250
251
252
253 func (t *Table) GetUint64Slot(slot VOffsetT, d uint64) uint64 {
254 off := t.Offset(slot)
255 if off == 0 {
256 return d
257 }
258
259 return t.GetUint64(t.Pos + UOffsetT(off))
260 }
261
262
263
264
265 func (t *Table) GetFloat32Slot(slot VOffsetT, d float32) float32 {
266 off := t.Offset(slot)
267 if off == 0 {
268 return d
269 }
270
271 return t.GetFloat32(t.Pos + UOffsetT(off))
272 }
273
274
275
276
277 func (t *Table) GetFloat64Slot(slot VOffsetT, d float64) float64 {
278 off := t.Offset(slot)
279 if off == 0 {
280 return d
281 }
282
283 return t.GetFloat64(t.Pos + UOffsetT(off))
284 }
285
286
287
288
289 func (t *Table) GetVOffsetTSlot(slot VOffsetT, d VOffsetT) VOffsetT {
290 off := t.Offset(slot)
291 if off == 0 {
292 return d
293 }
294 return VOffsetT(off)
295 }
296
297
298 func (t *Table) MutateBool(off UOffsetT, n bool) bool {
299 WriteBool(t.Bytes[off:], n)
300 return true
301 }
302
303
304 func (t *Table) MutateByte(off UOffsetT, n byte) bool {
305 WriteByte(t.Bytes[off:], n)
306 return true
307 }
308
309
310 func (t *Table) MutateUint8(off UOffsetT, n uint8) bool {
311 WriteUint8(t.Bytes[off:], n)
312 return true
313 }
314
315
316 func (t *Table) MutateUint16(off UOffsetT, n uint16) bool {
317 WriteUint16(t.Bytes[off:], n)
318 return true
319 }
320
321
322 func (t *Table) MutateUint32(off UOffsetT, n uint32) bool {
323 WriteUint32(t.Bytes[off:], n)
324 return true
325 }
326
327
328 func (t *Table) MutateUint64(off UOffsetT, n uint64) bool {
329 WriteUint64(t.Bytes[off:], n)
330 return true
331 }
332
333
334 func (t *Table) MutateInt8(off UOffsetT, n int8) bool {
335 WriteInt8(t.Bytes[off:], n)
336 return true
337 }
338
339
340 func (t *Table) MutateInt16(off UOffsetT, n int16) bool {
341 WriteInt16(t.Bytes[off:], n)
342 return true
343 }
344
345
346 func (t *Table) MutateInt32(off UOffsetT, n int32) bool {
347 WriteInt32(t.Bytes[off:], n)
348 return true
349 }
350
351
352 func (t *Table) MutateInt64(off UOffsetT, n int64) bool {
353 WriteInt64(t.Bytes[off:], n)
354 return true
355 }
356
357
358 func (t *Table) MutateFloat32(off UOffsetT, n float32) bool {
359 WriteFloat32(t.Bytes[off:], n)
360 return true
361 }
362
363
364 func (t *Table) MutateFloat64(off UOffsetT, n float64) bool {
365 WriteFloat64(t.Bytes[off:], n)
366 return true
367 }
368
369
370 func (t *Table) MutateUOffsetT(off UOffsetT, n UOffsetT) bool {
371 WriteUOffsetT(t.Bytes[off:], n)
372 return true
373 }
374
375
376 func (t *Table) MutateVOffsetT(off UOffsetT, n VOffsetT) bool {
377 WriteVOffsetT(t.Bytes[off:], n)
378 return true
379 }
380
381
382 func (t *Table) MutateSOffsetT(off UOffsetT, n SOffsetT) bool {
383 WriteSOffsetT(t.Bytes[off:], n)
384 return true
385 }
386
387
388 func (t *Table) MutateBoolSlot(slot VOffsetT, n bool) bool {
389 if off := t.Offset(slot); off != 0 {
390 t.MutateBool(t.Pos+UOffsetT(off), n)
391 return true
392 }
393
394 return false
395 }
396
397
398 func (t *Table) MutateByteSlot(slot VOffsetT, n byte) bool {
399 if off := t.Offset(slot); off != 0 {
400 t.MutateByte(t.Pos+UOffsetT(off), n)
401 return true
402 }
403
404 return false
405 }
406
407
408 func (t *Table) MutateInt8Slot(slot VOffsetT, n int8) bool {
409 if off := t.Offset(slot); off != 0 {
410 t.MutateInt8(t.Pos+UOffsetT(off), n)
411 return true
412 }
413
414 return false
415 }
416
417
418 func (t *Table) MutateUint8Slot(slot VOffsetT, n uint8) bool {
419 if off := t.Offset(slot); off != 0 {
420 t.MutateUint8(t.Pos+UOffsetT(off), n)
421 return true
422 }
423
424 return false
425 }
426
427
428 func (t *Table) MutateInt16Slot(slot VOffsetT, n int16) bool {
429 if off := t.Offset(slot); off != 0 {
430 t.MutateInt16(t.Pos+UOffsetT(off), n)
431 return true
432 }
433
434 return false
435 }
436
437
438 func (t *Table) MutateUint16Slot(slot VOffsetT, n uint16) bool {
439 if off := t.Offset(slot); off != 0 {
440 t.MutateUint16(t.Pos+UOffsetT(off), n)
441 return true
442 }
443
444 return false
445 }
446
447
448 func (t *Table) MutateInt32Slot(slot VOffsetT, n int32) bool {
449 if off := t.Offset(slot); off != 0 {
450 t.MutateInt32(t.Pos+UOffsetT(off), n)
451 return true
452 }
453
454 return false
455 }
456
457
458 func (t *Table) MutateUint32Slot(slot VOffsetT, n uint32) bool {
459 if off := t.Offset(slot); off != 0 {
460 t.MutateUint32(t.Pos+UOffsetT(off), n)
461 return true
462 }
463
464 return false
465 }
466
467
468 func (t *Table) MutateInt64Slot(slot VOffsetT, n int64) bool {
469 if off := t.Offset(slot); off != 0 {
470 t.MutateInt64(t.Pos+UOffsetT(off), n)
471 return true
472 }
473
474 return false
475 }
476
477
478 func (t *Table) MutateUint64Slot(slot VOffsetT, n uint64) bool {
479 if off := t.Offset(slot); off != 0 {
480 t.MutateUint64(t.Pos+UOffsetT(off), n)
481 return true
482 }
483
484 return false
485 }
486
487
488 func (t *Table) MutateFloat32Slot(slot VOffsetT, n float32) bool {
489 if off := t.Offset(slot); off != 0 {
490 t.MutateFloat32(t.Pos+UOffsetT(off), n)
491 return true
492 }
493
494 return false
495 }
496
497
498 func (t *Table) MutateFloat64Slot(slot VOffsetT, n float64) bool {
499 if off := t.Offset(slot); off != 0 {
500 t.MutateFloat64(t.Pos+UOffsetT(off), n)
501 return true
502 }
503
504 return false
505 }
506
View as plain text