[Nim] Bfbs Nim Generator (#7534)

* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* remove unused variables

* added tests to ci

* added tests to ci

* fixes

* Added reflection type Field, Variable to namer

* Moved reflection namer impl to bfbsnamer

* Remove whitespace at end of line

* Added nim to generated code

* Revert whitespace removal

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Dan Lapid 2022-10-21 21:30:04 +03:00 committed by GitHub
parent e301702964
commit 872a497464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 3344 additions and 34 deletions

10
.github/labeler.yml vendored
View File

@ -18,6 +18,12 @@ swift:
- tests/swift/**
- src/idl_gen_swift.cpp
nim:
- '**/*.nim'
- nim/**/*
- src/idl_gen_nim.cpp
- src/bfbs_gen_nim.cpp
javascript:
- '**/*.js'
- src/idl_gen_ts.cpp
@ -61,7 +67,7 @@ rust:
- '**/*.rs'
- rust/**/*
- src/idl_gen_rust.cpp
dart:
- '**/*.dart'
- src/idl_gen_dart.cpp
@ -88,4 +94,4 @@ CI:
grpc:
- grpc/**/*
- src/idl_gen_grpc.cpp
- src/idl_gen_grpc.cpp

View File

@ -477,6 +477,22 @@ jobs:
working-directory: tests
run: bash DartTest.sh
build-nim:
name: Build Nim
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: flatc
# FIXME: make test script not rely on flatc
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
- uses: jiro4989/setup-nim-action@v1
- name: install library
working-directory: nim
run: nimble -y develop
- name: test
working-directory: tests/nim
run: python3 testnim.py
release-digests:
if: startsWith(github.ref, 'refs/tags/')
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]

View File

@ -182,6 +182,7 @@ set(FlatBuffers_Compiler_SRCS
src/flatc_main.cpp
src/bfbs_gen.h
src/bfbs_gen_lua.h
src/bfbs_gen_nim.h
src/bfbs_namer.h
include/flatbuffers/code_generators.h
src/binary_annotator.h
@ -189,6 +190,7 @@ set(FlatBuffers_Compiler_SRCS
src/annotated_binary_text_gen.h
src/annotated_binary_text_gen.cpp
src/bfbs_gen_lua.cpp
src/bfbs_gen_nim.cpp
src/code_generators.cpp
grpc/src/compiler/schema_interface.h
grpc/src/compiler/cpp_generator.h

View File

@ -661,6 +661,7 @@ struct IDLOptions {
kRust = 1 << 14,
kKotlin = 1 << 15,
kSwift = 1 << 16,
kNim = 1 << 17,
kMAX
};

7
nim/flatbuffers.nimble Normal file
View File

@ -0,0 +1,7 @@
version = "2.0.8"
author = "flatbuffers"
description = "Flatbuffers"
license = "Apache 2.0"
srcDir = "flatbuffers"
requires "nim >= 1.4.0"

View File

@ -0,0 +1,7 @@
import
src/[
builder,
struct,
table
]
export flatbuffers.builder, flatbuffers.table, flatbuffers.struct

View File

@ -0,0 +1,262 @@
import math
import table
const MAX_BUFFER_SIZE* = 2^31
type Builder* = ref object of RootObj
bytes*: seq[byte]
minalign*: int
current_vtable*: seq[uoffset]
objectEnd*: uoffset
vtables*: seq[uoffset] #?
head*: uoffset
nested*: bool
finished*: bool
vectorNumElems*: uoffset
using this: var Builder
func newBuilder*(size: int): Builder =
result = new Builder
result.bytes.setLen(size)
result.minalign = 1
result.head = size.uoffset
result.nested = false
result.finished = false
result.vectorNumElems = 0
proc FinishedBytes*(this): seq[byte] =
if not this.finished:
quit("Builder not finished, Incorrect use of FinishedBytes(): must call 'Finish' first.")
result = this.bytes[this.head..^1]
proc Output*(this): seq[byte] =
if not this.finished:
quit("Builder not finished, Incorrect use of Output(): must call 'Finish' first.")
result = this.bytes[this.head..^1]
func Offset*(this): uoffset =
result = this.bytes.len.uoffset - this.head
proc StartObject*(this; numfields: int) =
if this.nested:
quit("builder is nested")
this.current_vtable.setLen(numfields)
for i in this.current_vtable.mitems():
i = 0
this.objectEnd = this.Offset()
this.nested = true
proc GrowByteBuffer*(this) =
if this.bytes.len == MAX_BUFFER_SIZE:
quit("flatbuffers: cannot grow buffer beyond 2 gigabytes")
let oldLen = this.bytes.len
var newLen = min(this.bytes.len * 2, MAX_BUFFER_SIZE)
if newLen == 0:
newLen = 1
this.bytes.setLen(newLen)
var j = this.bytes.len - 1
while j >= 0:
if j >= newLen - oldLen:
this.bytes[j] = this.bytes[j - (newLen - oldLen)]
else:
this.bytes[j] = 0
dec(j)
proc Place*[T](this; x: T) =
this.head -= uoffset x.sizeof
WriteVal(this.bytes, this.head, x)
func Pad*(this; n: int) =
for i in 0..<n:
this.Place(0.byte)
proc Prep*(this; size: int; additionalBytes: int) =
if size > this.minalign:
this.minalign = size
var alignsize = (not (this.bytes.len - this.head.int + additionalBytes)) + 1
alignsize = alignsize and (size - 1)
while this.head.int < alignsize + size + additionalBytes:
let oldbufSize = this.bytes.len
this.GrowByteBuffer()
this.head = (this.head.int + this.bytes.len - oldbufSize).uoffset
this.Pad(alignsize)
proc PrependOffsetRelative*[T: Offsets](this; off: T) =
when T is voffset:
this.Prep(T.sizeof, 0)
if not off.uoffset <= this.Offset:
quit("flatbuffers: Offset arithmetic error.")
this.Place(off)
else:
this.Prep(T.sizeof, 0)
if not off.uoffset <= this.Offset:
quit("flatbuffers: Offset arithmetic error.")
let off2: T = this.Offset.T - off + sizeof(T).T
this.Place(off2)
proc Prepend*[T](this; x: T) =
this.Prep(x.sizeof, 0)
this.Place(x)
proc Slot*(this; slotnum: int) =
this.current_vtable[slotnum] = this.Offset
proc PrependSlot*[T](this; o: int; x, d: T) =
if x != d:
when T is uoffset or T is soffset or T is voffset:
this.PrependOffsetRelative(x)
else:
this.Prepend(x)
this.Slot(o)
proc AssertStuctInline(this; obj: uoffset) =
if obj != this.Offset:
quit("flatbuffers: Tried to write a Struct at an Offset that is different from the current Offset of the Builder.")
proc PrependStructSlot*(this; o: int; x: uoffset; d: uoffset) =
if x != d:
this.AssertStuctInline(x)
this.Slot(o)
proc Add*[T](this; n: T) =
this.Prep(T.sizeof, 0)
WriteVal(this.bytes, this.head, n)
proc VtableEqual*(a: seq[uoffset]; objectStart: uoffset; b: seq[byte]): bool =
if a.len * voffset.sizeof != b.len:
return false
var i = 0
while i < a.len:
var seq = b[i * voffset.sizeof..<(i + 1) * voffset.sizeof]
let x = GetVal[voffset](addr seq)
if x == 0 and a[i] == 0:
inc i
continue
let y = objectStart.soffset - a[i].soffset
if x.soffset != y:
return false
inc i
return true
proc WriteVtable*(this): uoffset =
this.PrependOffsetRelative(0.soffset)
let objectOffset = this.Offset
var existingVtable = uoffset 0
var i = this.current_vtable.len - 1
while i >= 0 and this.current_vtable[i] == 0: dec i
this.current_vtable = this.current_vtable[0..i]
for i in countdown(this.vtables.len - 1, 0):
let
vt2Offset: uoffset = this.vtables[i]
vt2Start: int = this.bytes.len - int vt2Offset
var seq = this.bytes[vt2Start..<this.bytes.len]
let
vt2Len = GetVal[voffset](addr seq)
metadata = 2 * voffset.sizeof # VtableMetadataFields * SizeVOffsetT
vt2End = vt2Start + vt2Len.int
vt2 = this.bytes[this.bytes.len - vt2Offset.int + metadata..<vt2End]
if VtableEqual(this.current_vtable, objectOffset, vt2):
existingVtable = vt2Offset
break
if existingVtable == 0:
for i in countdown(this.current_vtable.len - 1, 0):
var off: uoffset
if this.current_vtable[i] != 0:
off = objectOffset - this.current_vtable[i]
this.PrependOffsetRelative(off.voffset)
let objectSize = objectOffset - this.objectEnd
this.PrependOffsetRelative(objectSize.voffset)
let vBytes = (this.current_vtable.len + 2) * voffset.sizeof
this.PrependOffsetRelative(vBytes.voffset)
let objectStart: uoffset = (this.bytes.len.uoffset - objectOffset)
WriteVal(this.bytes, objectStart, (this.Offset - objectOffset).soffset)
this.vtables.add this.Offset
else:
let objectStart: uoffset = this.bytes.len.uoffset - objectOffset
this.head = objectStart
WriteVal(this.bytes, this.head,
(existingVtable.soffset - objectOffset.soffset))
this.current_vtable = @[]
result = objectOffset
proc EndObject*(this): uoffset =
if not this.nested:
quit("builder is not nested")
result = this.WriteVtable()
this.nested = false
proc End*(this: var Builder): uoffset =
result = this.EndObject()
proc StartVector*(this; elemSize: int; numElems: uoffset;
alignment: int) =
if this.nested:
quit("builder is nested")
this.nested = true
this.vectorNumElems = numElems
this.Prep(sizeof(uint32), elemSize * numElems.int)
this.Prep(alignment, elemSize * numElems.int)
proc EndVector*(this): uoffset =
if not this.nested:
quit("builder is not nested")
this.nested = false
this.Place(this.vectorNumElems)
this.vectorNumElems = 0
result = this.Offset
proc getChars*(str: seq[byte]): string =
var bytes = str
result = GetVal[string](addr bytes)
proc getBytes*(str: string | cstring): seq[byte] =
for chr in str:
result.add byte chr
result.add byte 0
proc Create*[T](this; s: T): uoffset = # Both CreateString and CreateByteVector functionality
if this.nested:
quit("builder is nested")
this.nested = true
when T is cstring or T is string:
let x = s.getBytes()
let l = x.len.uoffset
this.vectorNumElems = l-1
else:
let x = s
let l = x.len.uoffset
this.vectorNumElems = l
this.Prep(uoffset.sizeof, l.int * byte.sizeof)
this.head -= l
this.bytes[this.head..<this.head+l] = x
result = this.EndVector()
proc Finish*(this; rootTable: uoffset) =
if this.nested:
quit("builder is nested")
this.nested = true
this.Prep(this.minalign, uoffset.sizeof)
this.PrependOffsetRelative(rootTable)
this.finished = true

View File

@ -0,0 +1,12 @@
template swapEndian*(outp, inp: pointer, size: int) =
var i = cast[cstring](inp)
var o = cast[cstring](outp)
for x in 0..<size:
o[x] = i[(0..<size).len - x - 1]
when system.cpuEndian == bigEndian:
func littleEndianX*(outp, inp: pointer, size: int) {.inline.} = swapEndian(outp, inp, size)
func bigEndianX*(outp, inp: pointer, size: int) {.inline.} = copyMem(outp, inp, size)
else:
func littleEndianX*(outp, inp: pointer, size: int) {.inline.} = copyMem(outp, inp, size)
func bigEndianX*(outp, inp: pointer, size: int) {.inline.} = swapEndian(outp, inp, size)

View File

@ -0,0 +1,24 @@
import table
type FlatObj* {.inheritable.} = object
tab*: Vtable
func Table*(this: var FlatObj): Vtable = this.tab
func Init*(this: var FlatObj; buf: seq[byte]; i: uoffset) =
this.tab.Bytes = buf
this.tab.Pos = i
# Cant define it in table.nim since it needs FlatObj and Init
func GetUnion*[T: FlatObj](this: var Vtable; off: uoffset): T =
result.Init(this.Bytes, this.Indirect(off))
func GetRootAs*(result: var FlatObj; buf: seq[byte]; offset: uoffset) =
var
vtable = Vtable(Bytes: buf[offset..^1], Pos: offset)
n = Get[uoffset](vtable, offset)
result.Init(buf, n+offset)
func GetRootAs*(result: var FlatObj; buf: string; offset: uoffset) =
result.GetRootAs(cast[seq[byte]](buf), offset)

View File

@ -0,0 +1,149 @@
import endian
type
uoffset* = uint32 ## offset in to the buffer
soffset* = int32 ## offset from start of table, to a vtable
voffset* = uint16 ## offset from start of table to value
type Offsets* = uoffset | soffset | voffset
type Vtable* = object
Bytes*: seq[byte]
Pos*: uoffset
using this: Vtable
func GetVal*[T](b: ptr seq[byte]): T {.inline.} =
when T is float64:
result = cast[T](GetVal[uint64](b))
elif T is float32:
result = cast[T](GetVal[uint32](b))
elif T is string:
result = cast[T](b[])
else:
if b[].len < T.sizeof:
b[].setLen T.sizeof
result = cast[ptr T](unsafeAddr b[][0])[]
template Get*[T](this; off: uoffset): T =
var seq = this.Bytes[off..^1]
GetVal[T](addr seq)
template Get*[T](this; off: soffset): T =
var seq = this.Bytes[off..^1]
GetVal[T](addr seq)
template Get*[T](this; off: voffset): T =
var seq = this.Bytes[off..^1]
GetVal[T](addr seq)
func WriteVal*[T: not SomeFloat](b: var openArray[byte]; off: uoffset;
n: T) {.inline.} =
when sizeof(T) == 8:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 4:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 2:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 1:
b[off] = n.uint8
else:
discard
#littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
#{.error:"shouldnt appear".}
func WriteVal*[T: not SomeFloat](b: var seq[byte]; off: uoffset;
n: T) {.inline.} =
when sizeof(T) == 8:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 4:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 2:
littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
elif sizeof(T) == 1:
b[off] = n.uint8
else:
discard
#littleEndianX(addr b[off], unsafeAddr n, T.sizeof)
#{.error:"shouldnt appear".}
func WriteVal*[T: SomeFloat](b: var openArray[byte]; off: uoffset;
n: T) {.inline.} =
when T is float64:
WriteVal(b, off, cast[uint64](n))
elif T is float32:
WriteVal(b, off, cast[uint32](n))
func WriteVal*[T: SomeFloat](b: var seq[byte]; off: uoffset; n: T) {.inline.} =
when T is float64:
WriteVal(b, off, cast[uint64](n))
elif T is float32:
WriteVal(b, off, cast[uint32](n))
func Offset*(this; off: voffset): voffset =
let vtable = (this.Pos - this.Get[:uoffset](this.Pos)).voffset
let vtableEnd = this.Get[:voffset](vtable)
if off < vtableEnd:
return this.Get[:voffset](vtable + off)
return 0
func Indirect*(this; off: uoffset): uoffset =
result = off + this.Get[:uoffset](off)
func VectorLen*(this; off: uoffset): int =
var newoff: uoffset = off + this.Pos
newoff += this.Get[:uoffset](newoff)
return this.Get[:uoffset](newoff).int
func Vector*(this; off: uoffset): uoffset =
let newoff: uoffset = off + this.Pos
var x: uoffset = newoff + this.Get[:uoffset](newoff)
x += (uoffset.sizeof).uoffset
result = x
func Union*(this; off: uoffset): Vtable =
let newoff: uoffset = off + this.Pos
result.Pos = newoff + this.Get[:uoffset](newoff)
result.Bytes = this.Bytes
func GetSlot*[T](this; slot: voffset; d: T): T =
let off = this.Offset(slot)
if off == 0:
return d
return this.Get[T](this.Pos + off)
func GetOffsetSlot*[T: Offsets](this; slot: voffset; d: T): T =
let off = this.Offset(slot)
if off == 0:
return d
return off
func ByteVector*(this; off: uoffset): seq[byte] =
let
newoff: uoffset = off + this.Get[:uoffset](off)
start = newoff + (uoffset.sizeof).uoffset
var newseq = this.Bytes[newoff..^1]
let
length = GetVal[uoffset](addr newseq)
result = this.Bytes[start..<start+length]
func String*(this; off: uoffset): string =
var byte_seq = this.ByteVector(off)
result = GetVal[string](addr byte_seq)
using this: var Vtable
proc Mutate*[T](this; off: uoffset; n: T): bool =
WriteVal(this.Bytes, off, n)
return true
func MutateSlot*[T](this; slot: voffset; n: T): bool =
let off: voffset = this.Offset(slot)
if off != 0:
return this.Mutate(this.Pos + off.uoffset, n)
return false

Binary file not shown.

View File

@ -449,6 +449,13 @@ flatc(
cwd=swift_code_gen
)
# Nim Tests
NIM_OPTS = BASE_OPTS + ["--nim"]
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
flatc(NIM_OPTS, schema="optional_scalars.fbs")
flatc(NIM_OPTS, schema="more_defaults.fbs")
flatc(NIM_OPTS, schema="MutatingBool.fbs")
# --filename-suffix and --filename-ext tests
flatc(
CPP_OPTS + NO_INCL_OPTS + ["--grpc", "--filename-ext", "hpp"],

View File

@ -39,6 +39,8 @@ cc_library(
"bfbs_gen.h",
"bfbs_gen_lua.cpp",
"bfbs_gen_lua.h",
"bfbs_gen_nim.cpp",
"bfbs_gen_nim.h",
"bfbs_namer.h",
"binary_annotator.cpp",
"binary_annotator.h",
@ -62,6 +64,8 @@ cc_library(
"bfbs_gen.h",
"bfbs_gen_lua.cpp",
"bfbs_gen_lua.h",
"bfbs_gen_nim.cpp",
"bfbs_gen_nim.h",
"bfbs_namer.h",
"flatc_main.cpp",
"idl_gen_cpp.cpp",

View File

@ -38,8 +38,9 @@ static void ForAllObjects(
for (auto it = objects->cbegin(); it != objects->cend(); ++it) { func(*it); }
}
static void ForAllEnumValues(const reflection::Enum *enum_def,
std::function<void(const reflection::EnumVal *)> func) {
static void ForAllEnumValues(
const reflection::Enum *enum_def,
std::function<void(const reflection::EnumVal *)> func) {
for (auto it = enum_def->values()->cbegin(); it != enum_def->values()->cend();
++it) {
func(*it);
@ -91,7 +92,7 @@ static bool IsVector(const reflection::BaseType base_type) {
return base_type == reflection::Vector;
}
} // namespace
} // namespace
// A concrete base Flatbuffer Generator that specific language generators can
// derive from.
@ -130,17 +131,29 @@ class BaseBfbsGenerator : public BfbsGenerator {
}
protected:
const reflection::Object *GetObject(const reflection::Type *type) const {
if (type->index() >= 0 && IsStructOrTable(type->base_type())) {
// GetObject returns the underlying object struct of the given type
// if element_type is true and GetObject is a list of objects then
// GetObject will correctly return the object struct of the vector's elements
const reflection::Object *GetObject(const reflection::Type *type,
bool element_type = false) const {
const reflection::BaseType base_type =
element_type ? type->element() : type->base_type();
if (type->index() >= 0 && IsStructOrTable(base_type)) {
return GetObjectByIndex(type->index());
}
return nullptr;
}
const reflection::Enum *GetEnum(const reflection::Type *type) const {
// GetEnum returns the underlying enum struct of the given type
// if element_type is true and GetEnum is a list of enums then
// GetEnum will correctly return the enum struct of the vector's elements
const reflection::Enum *GetEnum(const reflection::Type *type,
bool element_type = false) const {
const reflection::BaseType base_type =
element_type ? type->element() : type->base_type();
// TODO(derekbailey): it would be better to have a explicit list of allowed
// base types, instead of negating Obj types.
if (type->index() >= 0 && !IsStructOrTable(type->base_type())) {
if (type->index() >= 0 && !IsStructOrTable(base_type)) {
return GetEnumByIndex(type->index());
}
return nullptr;

View File

@ -175,7 +175,7 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
// Skip writing deprecated fields altogether.
if (field->deprecated()) { return; }
const std::string field_name = namer_.Field(field->name()->str());
const std::string field_name = namer_.Field(*field);
const r::BaseType base_type = field->type()->base_type();
// Generate some fixed strings so we don't repeat outselves later.
@ -367,9 +367,8 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
if (field->deprecated()) { return; }
const std::string field_name = namer_.Field(field->name()->str());
const std::string variable_name =
namer_.Variable(field->name()->str());
const std::string field_name = namer_.Field(*field);
const std::string variable_name = namer_.Variable(*field);
code += "function " + object_name + ".Add" + field_name +
"(builder, " + variable_name + ")\n";
@ -428,9 +427,9 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
if (IsStructOrTable(field->type()->base_type())) {
const r::Object *field_object = GetObject(field->type());
signature += GenerateStructBuilderArgs(
field_object, prefix + namer_.Variable(field->name()->str()) + "_");
field_object, prefix + namer_.Variable(*field) + "_");
} else {
signature += ", " + prefix + namer_.Variable(field->name()->str());
signature += ", " + prefix + namer_.Variable(*field);
}
});
return signature;
@ -451,11 +450,11 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
}
if (IsStructOrTable(field->type()->base_type())) {
const r::Object *field_object = GetObject(field->type());
code += AppendStructBuilderBody(
field_object, prefix + namer_.Variable(field->name()->str()) + "_");
code += AppendStructBuilderBody(field_object,
prefix + namer_.Variable(*field) + "_");
} else {
code += " builder:Prepend" + GenerateMethod(field) + "(" + prefix +
namer_.Variable(field->name()->str()) + ")\n";
namer_.Variable(*field) + ")\n";
}
});

640
src/bfbs_gen_nim.cpp Normal file
View File

@ -0,0 +1,640 @@
/*
* Copyright 2021 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bfbs_gen_nim.h"
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>
// Ensure no includes to flatc internals. bfbs_gen.h and generator.h are OK.
#include "bfbs_gen.h"
#include "bfbs_namer.h"
#include "flatbuffers/bfbs_generator.h"
// The intermediate representation schema.
#include "flatbuffers/reflection.h"
#include "flatbuffers/reflection_generated.h"
namespace flatbuffers {
namespace {
// To reduce typing
namespace r = ::reflection;
std::set<std::string> NimKeywords() {
return {
"addr", "and", "as", "asm", "bind", "block",
"break", "case", "cast", "concept", "const", "continue",
"converter", "defer", "discard", "distinct", "div", "do",
"elif", "else", "end", "enum", "except", "export",
"finally", "for", "from", "func", "if", "import",
"in", "include", "interface", "is", "isnot", "iterator",
"let", "macro", "method", "mixin", "mod", "nil",
"not", "notin", "object", "of", "or", "out",
"proc", "ptr", "raise", "ref", "return", "shl",
"shr", "static", "template", "try", "tuple", "type",
"using", "var", "when", "while", "xor", "yield",
};
}
Namer::Config NimDefaultConfig() {
return { /*types=*/Case::kUpperCamel,
/*constants=*/Case::kUpperCamel,
/*methods=*/Case::kLowerCamel,
/*functions=*/Case::kUpperCamel,
/*fields=*/Case::kLowerCamel,
/*variable=*/Case::kLowerCamel,
/*variants=*/Case::kUpperCamel,
/*enum_variant_seperator=*/".",
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
/*namespaces=*/Case::kKeep,
/*namespace_seperator=*/"/",
/*object_prefix=*/"",
/*object_suffix=*/"T",
/*keyword_prefix=*/"",
/*keyword_suffix=*/"_",
/*filenames=*/Case::kKeep,
/*directories=*/Case::kKeep,
/*output_path=*/"",
/*filename_suffix=*/"",
/*filename_extension=*/".nim" };
}
const std::string Indent = " ";
const std::string Export = "*";
const std::set<std::string> builtin_types = {
"uint8", "uint8", "bool", "int8", "uint8", "int16",
"uint16", "int32", "uint32", "int64", "uint64", "float32",
"float64", "string", "int", "uint", "uoffset", "Builder"
};
class NimBfbsGenerator : public BaseBfbsGenerator {
public:
explicit NimBfbsGenerator(const std::string &flatc_version)
: BaseBfbsGenerator(),
keywords_(),
imports_(),
current_obj_(nullptr),
current_enum_(nullptr),
flatc_version_(flatc_version),
namer_(NimDefaultConfig(), NimKeywords()) {}
GeneratorStatus GenerateFromSchema(const r::Schema *schema)
FLATBUFFERS_OVERRIDE {
ForAllEnums(schema->enums(), [&](const r::Enum *enum_def) {
StartCodeBlock(enum_def);
GenerateEnum(enum_def);
});
ForAllObjects(schema->objects(), [&](const r::Object *object) {
StartCodeBlock(object);
GenerateObject(object);
});
return OK;
}
uint64_t SupportedAdvancedFeatures() const FLATBUFFERS_OVERRIDE {
return r::AdvancedArrayFeatures | r::AdvancedUnionFeatures |
r::OptionalScalars | r::DefaultVectorsAndStrings;
}
protected:
void GenerateEnum(const r::Enum *enum_def) {
std::string code;
std::string ns;
const std::string enum_name = namer_.Type(namer_.Denamespace(enum_def, ns));
const std::string enum_type =
GenerateTypeBasic(enum_def->underlying_type());
GenerateDocumentation(enum_def->documentation(), "", code);
code += "type " + enum_name + Export + "{.pure.} = enum\n";
ForAllEnumValues(enum_def, [&](const reflection::EnumVal *enum_val) {
GenerateDocumentation(enum_val->documentation(), " ", code);
code += " " + namer_.Variant(enum_val->name()->str()) + " = " +
NumToString(enum_val->value()) + "." + enum_type + ",\n";
});
EmitCodeBlock(code, enum_name, ns, enum_def->declaration_file()->str());
}
void GenerateObject(const r::Object *object) {
// Register the main flatbuffers module.
RegisterImports("flatbuffers", "");
std::string code;
std::string ns;
const std::string object_name = namer_.Type(namer_.Denamespace(object, ns));
GenerateDocumentation(object->documentation(), "", code);
code += "type " + object_name + "* = object of FlatObj\n";
// Create all the field accessors.
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
// Skip writing deprecated fields altogether.
if (field->deprecated()) { return; }
const std::string field_name = namer_.Field(*field);
const r::BaseType base_type = field->type()->base_type();
std::string field_type = GenerateType(field->type());
if (field->optional() && !object->is_struct()) {
RegisterImports("std/options", "");
field_type = "Option[" + field_type + "]";
}
const std::string offset_prefix =
"let o = self.tab.Offset(" + NumToString(field->offset()) + ")\n";
const std::string offset_prefix_2 = "if o != 0:\n";
if (IsScalar(base_type) || base_type == r::String ||
base_type == r::Obj || base_type == r::Union) {
GenerateDocumentation(field->documentation(), "", code);
std::string getter_signature = "func " + namer_.Method(field_name) +
"*(self: " + object_name +
"): " + field_type + " =\n";
std::string getter_code;
std::string setter_signature =
"func `" + namer_.Method(field_name + "=") + "`*(self: var " +
object_name + ", n: " + field_type + "): bool =\n";
std::string setter_code;
if (base_type == r::Obj || base_type == r::Union ||
field->type()->index() >= 0) {
RegisterImports(object, field);
}
if (object->is_struct()) {
std::string field_getter =
GenerateGetter(field->type(), NumToString(field->offset()));
getter_code += " return " + field_getter + "\n";
if (IsScalar(base_type)) {
setter_code += " return self.tab.Mutate(self.tab.Pos + " +
NumToString(field->offset()) + ", n)\n";
}
} else {
// Table accessors
getter_code += " " + offset_prefix;
getter_code += " " + offset_prefix_2;
std::string field_getter = GenerateGetter(field->type(), "o");
if (field->optional()) {
field_getter = "some(" + field_getter + ")";
}
getter_code += " return " + field_getter + "\n";
if (!field->optional()) {
getter_code += " return " + DefaultValue(field) + "\n";
}
if (IsScalar(base_type)) {
setter_code += " return self.tab.MutateSlot(" +
NumToString(field->offset()) + ", n)\n";
}
}
code += getter_signature + getter_code;
if (IsScalar(base_type)) { code += setter_signature + setter_code; }
} else if (base_type == r::Array || base_type == r::Vector) {
const r::BaseType vector_base_type = field->type()->element();
uint32_t element_size = field->type()->element_size();
if (vector_base_type == r::Obj || vector_base_type == r::Union ||
field->type()->index() >= 0) {
RegisterImports(object, field, true);
}
// Get vector length:
code += "func " + namer_.Method(field_name + "Length") +
"*(self: " + object_name + "): int = \n";
code += " " + offset_prefix;
code += " " + offset_prefix_2;
code += " return self.tab.VectorLen(o)\n";
// Get single vector field:
code += "func " + namer_.Method(field_name) + "*(self: " + object_name +
", j: int): " + GenerateType(field->type(), true) + " = \n";
code += " " + offset_prefix;
code += " " + offset_prefix_2;
code += " var x = self.tab.Vector(o)\n";
code +=
" x += j.uoffset * " + NumToString(element_size) + ".uoffset\n";
code += " return " + GenerateGetter(field->type(), "x", true) + "\n";
// Get entire vector:
code += "func " + namer_.Method(field_name) + "*(self: " + object_name +
"): " + GenerateType(field->type()) + " = \n";
code += " let len = self." + field_name + "Length\n";
code += " for i in countup(0, len - 1):\n";
code += " result.add(self." + field_name + "(i))\n";
(void)IsSingleByte(vector_base_type); // unnused function warning
}
});
// Create all the builders
if (object->is_struct()) {
code += "proc " + namer_.Function(object_name + "Create") +
"*(self: var Builder";
code += GenerateStructBuilderArgs(object);
code += "): uoffset =\n";
code += AppendStructBuilderBody(object);
code += " return self.Offset()\n";
} else {
// Table builders
code += "proc " + namer_.Function(object_name + "Start") +
"*(builder: var Builder) =\n";
code += " builder.StartObject(" + NumToString(object->fields()->size()) +
")\n";
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
if (field->deprecated()) { return; }
const std::string field_name = namer_.Field(*field);
const std::string variable_name = namer_.Variable(*field);
const std::string variable_type = GenerateTypeBasic(field->type());
code += "proc " + namer_.Function(object_name + "Add" + field_name) +
"*(builder: var Builder, " + variable_name + ": " +
variable_type + ") =\n";
code += " builder.Prepend" + GenerateMethod(field) + "Slot(" +
NumToString(field->id()) + ", " + variable_name + ", default(" +
variable_type + "))\n";
if (IsVector(field->type()->base_type())) {
code += "proc " +
namer_.Function(object_name + "Start" + field_name) +
"Vector*(builder: var Builder, numElems: uoffset) =\n";
const int32_t element_size = field->type()->element_size();
int32_t alignment = element_size;
if (IsStruct(field->type(), /*use_element=*/true)) {
alignment = GetObjectByIndex(field->type()->index())->minalign();
}
code += " builder.StartVector(" + NumToString(element_size) +
", numElems, " + NumToString(alignment) + ")\n";
}
});
code += "proc " + namer_.Function(object_name + "End") +
"*(builder: var Builder): uoffset =\n";
code += " return builder.EndObject()\n";
}
EmitCodeBlock(code, object_name, ns, object->declaration_file()->str());
}
private:
void GenerateDocumentation(
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>
*documentation,
std::string indent, std::string &code) const {
flatbuffers::ForAllDocumentation(
documentation, [&](const flatbuffers::String *str) {
code += indent + "# " + str->str() + "\n";
});
}
std::string GenerateStructBuilderArgs(const r::Object *object,
std::string prefix = "") const {
std::string signature;
ForAllFields(object, /*reverse=*/false, [&](const r::Field *field) {
if (IsStructOrTable(field->type()->base_type())) {
const r::Object *field_object = GetObject(field->type());
signature += GenerateStructBuilderArgs(
field_object, prefix + namer_.Variable(*field) + "_");
} else {
signature += ", " + prefix + namer_.Variable(*field) + ": " +
GenerateType(field->type());
}
});
return signature;
}
std::string AppendStructBuilderBody(const r::Object *object,
std::string prefix = "") const {
std::string code;
code += " self.Prep(" + NumToString(object->minalign()) + ", " +
NumToString(object->bytesize()) + ")\n";
// We need to reverse the order we iterate over, since we build the
// buffer backwards.
ForAllFields(object, /*reverse=*/true, [&](const r::Field *field) {
const int32_t num_padding_bytes = field->padding();
if (num_padding_bytes) {
code += " self.Pad(" + NumToString(num_padding_bytes) + ")\n";
}
if (IsStructOrTable(field->type()->base_type())) {
const r::Object *field_object = GetObject(field->type());
code += AppendStructBuilderBody(field_object,
prefix + namer_.Variable(*field) + "_");
} else {
code += " self.Prepend(" + prefix + namer_.Variable(*field) + ")\n";
}
});
return code;
}
std::string GenerateMethod(const r::Field *field) const {
const r::BaseType base_type = field->type()->base_type();
if (IsStructOrTable(base_type)) { return "Struct"; }
return "";
}
std::string GenerateGetter(const r::Type *type, const std::string &offsetval,
bool element_type = false) const {
const r::BaseType base_type =
element_type ? type->element() : type->base_type();
std::string offset = offsetval;
if (!element_type) { offset = "self.tab.Pos + " + offset; }
switch (base_type) {
case r::String: return "self.tab.String(" + offset + ")";
case r::Union: return "self.tab.Union(" + offsetval + ")";
case r::Obj: {
return GenerateType(type, element_type) +
"(tab: Vtable(Bytes: self.tab.Bytes, Pos: " + offset + "))";
}
case r::Vector: return GenerateGetter(type, offsetval, true);
default:
const r::Enum *type_enum = GetEnum(type, element_type);
if (type_enum != nullptr) {
return GenerateType(type, element_type) + "(" + "Get[" +
GenerateType(base_type) + "](self.tab, " + offset + ")" + ")";
} else {
return "Get[" + GenerateType(base_type) + "](self.tab, " + offset +
")";
}
}
}
std::string Denamespace(const std::string &s, std::string &importns,
std::string &ns) const {
if (builtin_types.find(s) != builtin_types.end()) { return s; }
std::string type = namer_.Type(namer_.Denamespace(s, ns));
importns = ns.empty() ? type : ns + "." + type;
std::replace(importns.begin(), importns.end(), '.', '_');
return type;
}
std::string Denamespace(const std::string &s, std::string &importns) const {
std::string ns;
return Denamespace(s, importns, ns);
}
std::string Denamespace(const std::string &s) const {
std::string importns;
return Denamespace(s, importns);
}
std::string GenerateType(const r::Type *type, bool element_type = false,
bool enum_inner = false) const {
const r::BaseType base_type =
element_type ? type->element() : type->base_type();
if (IsScalar(base_type) && !enum_inner) {
const r::Enum *type_enum = GetEnum(type, element_type);
if (type_enum != nullptr) {
std::string importns;
std::string type_name = Denamespace(type_enum->name()->str(), importns);
return importns + "." + type_name;
}
}
if (IsScalar(base_type)) { return Denamespace(GenerateType(base_type)); }
switch (base_type) {
case r::String: return "string";
case r::Vector: {
return "seq[" + GenerateType(type, true) + "]";
}
case r::Union: return "Vtable";
case r::Obj: {
const r::Object *type_obj = GetObject(type, element_type);
std::string importns;
std::string type_name = Denamespace(type_obj->name()->str(), importns);
if (type_obj == current_obj_) {
return type_name;
} else {
return importns + "." + type_name;
}
}
default: return "uoffset";
}
}
std::string GenerateTypeBasic(const r::Type *type,
bool element_type = false) const {
const r::BaseType base_type =
element_type ? type->element() : type->base_type();
if (IsScalar(base_type)) {
return GenerateType(base_type);
} else {
return "uoffset";
}
}
std::string GenerateType(const r::BaseType base_type) const {
switch (base_type) {
case r::None: return "uint8";
case r::UType: return "uint8";
case r::Bool: return "bool";
case r::Byte: return "int8";
case r::UByte: return "uint8";
case r::Short: return "int16";
case r::UShort: return "uint16";
case r::Int: return "int32";
case r::UInt: return "uint32";
case r::Long: return "int64";
case r::ULong: return "uint64";
case r::Float: return "float32";
case r::Double: return "float64";
case r::String: return "string";
default: return r::EnumNameBaseType(base_type);
}
}
std::string DefaultValue(const r::Field *field) const {
const r::BaseType base_type = field->type()->base_type();
if (IsFloatingPoint(base_type)) {
return NumToString(field->default_real());
}
if (IsBool(base_type)) {
return field->default_integer() ? "true" : "false";
}
if (IsScalar(base_type)) {
const r::Enum *type_enum = GetEnum(field->type());
if (type_enum != nullptr) {
return "type(result)(" + NumToString((field->default_integer())) + ")";
}
return NumToString((field->default_integer()));
}
if (base_type == r::String) { return "\"\""; }
// represents offsets
return "0";
}
void StartCodeBlock(const reflection::Enum *enum_def) {
current_enum_ = enum_def;
current_obj_ = nullptr;
imports_.clear();
}
void StartCodeBlock(const reflection::Object *object) {
current_enum_ = nullptr;
current_obj_ = object;
imports_.clear();
}
std::vector<std::string> StringSplit(const std::string orig_str,
const std::string token) {
std::vector<std::string> result;
std::string str = orig_str;
while (str.size()) {
size_t index = str.find(token);
if (index != std::string::npos) {
result.push_back(str.substr(0, index));
str = str.substr(index + token.size());
if (str.size() == 0) result.push_back(str);
} else {
result.push_back(str);
str = "";
}
}
return result;
}
std::string GetRelativePathFromNamespace(const std::string &relative_to,
const std::string &str2) {
std::vector<std::string> relative_to_vec = StringSplit(relative_to, ".");
std::vector<std::string> str2_vec = StringSplit(str2, ".");
while (relative_to_vec.size() > 0 && str2_vec.size() > 0) {
if (relative_to_vec[0] == str2_vec[0]) {
relative_to_vec.erase(relative_to_vec.begin());
str2_vec.erase(str2_vec.begin());
} else {
break;
}
}
relative_to_vec.pop_back();
for (size_t i = 0; i < relative_to_vec.size(); ++i) {
str2_vec.insert(str2_vec.begin(), std::string(".."));
}
std::string new_path;
for (size_t i = 0; i < str2_vec.size(); ++i) {
new_path += str2_vec[i];
if (i != str2_vec.size() - 1) { new_path += "/"; }
}
return new_path;
}
void RegisterImports(const r::Object *object, const r::Field *field,
bool use_element = false) {
std::string importns;
std::string type_name;
const r::BaseType type =
use_element ? field->type()->element() : field->type()->base_type();
if (IsStructOrTable(type)) {
const r::Object *object_def = GetObjectByIndex(field->type()->index());
if (object_def == current_obj_) { return; }
std::string ns;
type_name = Denamespace(object_def->name()->str(), importns, ns);
type_name = ns.empty() ? type_name : ns + "." + type_name;
} else {
const r::Enum *enum_def = GetEnumByIndex(field->type()->index());
if (enum_def == current_enum_) { return; }
std::string ns;
type_name = Denamespace(enum_def->name()->str(), importns, ns);
type_name = ns.empty() ? type_name : ns + "." + type_name;
}
std::string import_path =
GetRelativePathFromNamespace(object->name()->str(), type_name);
std::replace(type_name.begin(), type_name.end(), '.', '_');
RegisterImports(import_path, importns);
}
void RegisterImports(const std::string &local_name,
const std::string &imports_name) {
imports_[local_name] = imports_name;
}
void EmitCodeBlock(const std::string &code_block, const std::string &name,
const std::string &ns, const std::string &declaring_file) {
const std::string full_qualified_name = ns.empty() ? name : ns + "." + name;
std::string code = "#[ " + full_qualified_name + "\n";
code +=
" Automatically generated by the FlatBuffers compiler, do not "
"modify.\n";
code += " Or modify. I'm a message, not a cop.\n";
code += "\n";
code += " flatc version: " + flatc_version_ + "\n";
code += "\n";
code += " Declared by : " + declaring_file + "\n";
if (schema_->root_table() != nullptr) {
const std::string root_type = schema_->root_table()->name()->str();
const std::string root_file =
schema_->root_table()->declaration_file()->str();
code += " Rooting type : " + root_type + " (" + root_file + ")\n";
}
code += "]#\n\n";
if (!imports_.empty()) {
for (auto it = imports_.cbegin(); it != imports_.cend(); ++it) {
if (it->second.empty()) {
code += "import " + it->first + "\n";
} else {
code += "import " + it->first + " as " + it->second + "\n";
}
}
code += "\n";
}
code += code_block;
// Namespaces are '.' deliminted, so replace it with the path separator.
std::string path = ns;
if (ns.empty()) {
path = ".";
} else {
std::replace(path.begin(), path.end(), '.', '/');
}
// TODO(derekbailey): figure out a save file without depending on util.h
EnsureDirExists(path);
const std::string file_name = path + "/" + namer_.File(name);
SaveFile(file_name.c_str(), code, false);
}
std::unordered_set<std::string> keywords_;
std::map<std::string, std::string> imports_;
const r::Object *current_obj_;
const r::Enum *current_enum_;
const std::string flatc_version_;
const BfbsNamer namer_;
};
} // namespace
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
const std::string &flatc_version) {
return std::unique_ptr<NimBfbsGenerator>(new NimBfbsGenerator(flatc_version));
}
} // namespace flatbuffers

33
src/bfbs_gen_nim.h Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright 2021 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FLATBUFFERS_BFBS_GEN_NIM_H_
#define FLATBUFFERS_BFBS_GEN_NIM_H_
#include <memory>
#include <string>
#include "flatbuffers/bfbs_generator.h"
namespace flatbuffers {
// Constructs a new Nim Code generator.
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
const std::string &flatc_version);
} // namespace flatbuffers
#endif // FLATBUFFERS_BFBS_GEN_NIM_H_

View File

@ -36,6 +36,14 @@ class BfbsNamer : public Namer {
std::string Denamespace(T t, const char delimiter = '.') const {
return Namer::Denamespace(t->name()->c_str(), delimiter);
}
virtual std::string Field(const ::reflection::Field &f) const {
return Field(f.name()->str());
}
virtual std::string Variable(const ::reflection::Field &f) const {
return Variable(f.name()->str());
}
};
} // namespace flatbuffers

View File

@ -18,6 +18,7 @@
#include <memory>
#include "bfbs_gen_lua.h"
#include "bfbs_gen_nim.h"
#include "flatbuffers/base.h"
#include "flatbuffers/flatc.h"
#include "flatbuffers/util.h"
@ -56,6 +57,8 @@ int main(int argc, const char *argv[]) {
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_lua =
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version);
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_nim =
flatbuffers::NewNimBfbsGenerator(flatbuffers_version);
g_program_name = argv[0];
@ -142,6 +145,10 @@ int main(int argc, const char *argv[]) {
flatbuffers::FlatCOption{ "", "swift", "",
"Generate Swift files for tables/structs" },
nullptr, nullptr, nullptr },
{ nullptr, "Nim", true, nullptr, flatbuffers::IDLOptions::kNim,
flatbuffers::FlatCOption{ "", "nim", "",
"Generate Nim files for tables/structs" },
nullptr, bfbs_gen_nim.get(), nullptr },
};
flatbuffers::FlatCompiler::InitParams params;

View File

@ -1584,7 +1584,6 @@ CheckedError Parser::ParseVectorDelimiters(uoffset_t &count, F body) {
return NoError();
}
CheckedError Parser::ParseAlignAttribute(const std::string &align_constant,
size_t min_align, size_t *align) {
// Use uint8_t to avoid problems with size_t==`unsigned long` on LP64.
@ -2555,7 +2554,8 @@ bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions &opts) {
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
IDLOptions::kKotlin | IDLOptions::kCpp | IDLOptions::kJava |
IDLOptions::kCSharp | IDLOptions::kTs | IDLOptions::kBinary |
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson;
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson |
IDLOptions::kNim;
unsigned long langs = opts.lang_to_generate;
return (langs > 0 && langs < IDLOptions::kMAX) && !(langs & ~supported_langs);
}
@ -2566,7 +2566,7 @@ bool Parser::SupportsOptionalScalars() const {
bool Parser::SupportsDefaultVectorsAndStrings() const {
static FLATBUFFERS_CONSTEXPR unsigned long supported_langs =
IDLOptions::kRust | IDLOptions::kSwift;
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kNim;
return !(opts.lang_to_generate & ~supported_langs);
}
@ -2574,7 +2574,7 @@ bool Parser::SupportsAdvancedUnionFeatures() const {
return (opts.lang_to_generate &
~(IDLOptions::kCpp | IDLOptions::kTs | IDLOptions::kPhp |
IDLOptions::kJava | IDLOptions::kCSharp | IDLOptions::kKotlin |
IDLOptions::kBinary | IDLOptions::kSwift)) == 0;
IDLOptions::kBinary | IDLOptions::kSwift | IDLOptions::kNim)) == 0;
}
bool Parser::SupportsAdvancedArrayFeatures() const {
@ -3418,7 +3418,6 @@ CheckedError Parser::CheckPrivatelyLeakedFields(const Definition &def,
return NoError();
}
CheckedError Parser::DoParse(const char *source, const char **include_paths,
const char *source_filename,
const char *include_filename) {
@ -3993,12 +3992,18 @@ bool EnumVal::Deserialize(Parser &parser, const reflection::EnumVal *val) {
}
Offset<reflection::Type> Type::Serialize(FlatBufferBuilder *builder) const {
size_t element_size = SizeOf(element);
if (base_type == BASE_TYPE_VECTOR && element == BASE_TYPE_STRUCT &&
struct_def->bytesize != 0) {
// struct_def->bytesize==0 means struct is table
element_size = struct_def->bytesize;
}
return reflection::CreateType(
*builder, static_cast<reflection::BaseType>(base_type),
static_cast<reflection::BaseType>(element),
struct_def ? struct_def->index : (enum_def ? enum_def->index : -1),
fixed_length, static_cast<uint32_t>(SizeOf(base_type)),
static_cast<uint32_t>(SizeOf(element)));
static_cast<uint32_t>(element_size));
}
bool Type::Deserialize(const Parser &parser, const reflection::Type *type) {
@ -4152,7 +4157,7 @@ std::string Parser::ConformTo(const Parser &base) {
struct_def.defined_namespace->GetFullyQualifiedName(struct_def.name);
auto struct_def_base = base.LookupStruct(qualified_name);
if (!struct_def_base) continue;
std::set<FieldDef*> renamed_fields;
std::set<FieldDef *> renamed_fields;
for (auto fit = struct_def.fields.vec.begin();
fit != struct_def.fields.vec.end(); ++fit) {
auto &field = **fit;
@ -4181,15 +4186,15 @@ std::string Parser::ConformTo(const Parser &base) {
}
}
}
//deletion of trailing fields are not allowed
// deletion of trailing fields are not allowed
for (auto fit = struct_def_base->fields.vec.begin();
fit != struct_def_base->fields.vec.end(); ++fit ) {
fit != struct_def_base->fields.vec.end(); ++fit) {
auto &field_base = **fit;
//not a renamed field
// not a renamed field
if (renamed_fields.find(&field_base) == renamed_fields.end()) {
auto field = struct_def.fields.Lookup(field_base.name);
if (!field) {
return "field deleted: " + qualified_name + "." + field_base.name;
if (!field) {
return "field deleted: " + qualified_name + "." + field_base.name;
}
}
}

13
tests/Abc.nim Normal file
View File

@ -0,0 +1,13 @@
#[ Abc
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
]#
type Abc*{.pure.} = enum
A = 0.int32,
B = 1.int32,
C = 2.int32,

103
tests/MoreDefaults.nim Normal file
View File

@ -0,0 +1,103 @@
#[ MoreDefaults
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
]#
import Abc as Abc
import flatbuffers
type MoreDefaults* = object of FlatObj
func intsLength*(self: MoreDefaults): int =
let o = self.tab.Offset(4)
if o != 0:
return self.tab.VectorLen(o)
func ints*(self: MoreDefaults, j: int): int32 =
let o = self.tab.Offset(4)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return Get[int32](self.tab, x)
func ints*(self: MoreDefaults): seq[int32] =
let len = self.intsLength
for i in countup(0, len - 1):
result.add(self.ints(i))
func floatsLength*(self: MoreDefaults): int =
let o = self.tab.Offset(6)
if o != 0:
return self.tab.VectorLen(o)
func floats*(self: MoreDefaults, j: int): float32 =
let o = self.tab.Offset(6)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return Get[float32](self.tab, x)
func floats*(self: MoreDefaults): seq[float32] =
let len = self.floatsLength
for i in countup(0, len - 1):
result.add(self.floats(i))
func emptyString*(self: MoreDefaults): string =
let o = self.tab.Offset(8)
if o != 0:
return self.tab.String(self.tab.Pos + o)
return ""
func someString*(self: MoreDefaults): string =
let o = self.tab.Offset(10)
if o != 0:
return self.tab.String(self.tab.Pos + o)
return ""
func abcsLength*(self: MoreDefaults): int =
let o = self.tab.Offset(12)
if o != 0:
return self.tab.VectorLen(o)
func abcs*(self: MoreDefaults, j: int): Abc.Abc =
let o = self.tab.Offset(12)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return Abc.Abc(Get[int32](self.tab, x))
func abcs*(self: MoreDefaults): seq[Abc.Abc] =
let len = self.abcsLength
for i in countup(0, len - 1):
result.add(self.abcs(i))
func boolsLength*(self: MoreDefaults): int =
let o = self.tab.Offset(14)
if o != 0:
return self.tab.VectorLen(o)
func bools*(self: MoreDefaults, j: int): bool =
let o = self.tab.Offset(14)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[bool](self.tab, x)
func bools*(self: MoreDefaults): seq[bool] =
let len = self.boolsLength
for i in countup(0, len - 1):
result.add(self.bools(i))
proc MoreDefaultsStart*(builder: var Builder) =
builder.StartObject(6)
proc MoreDefaultsAddints*(builder: var Builder, ints: uoffset) =
builder.PrependSlot(0, ints, default(uoffset))
proc MoreDefaultsStartintsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MoreDefaultsAddfloats*(builder: var Builder, floats: uoffset) =
builder.PrependSlot(1, floats, default(uoffset))
proc MoreDefaultsStartfloatsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MoreDefaultsAddemptyString*(builder: var Builder, emptyString: uoffset) =
builder.PrependSlot(2, emptyString, default(uoffset))
proc MoreDefaultsAddsomeString*(builder: var Builder, someString: uoffset) =
builder.PrependSlot(3, someString, default(uoffset))
proc MoreDefaultsAddabcs*(builder: var Builder, abcs: uoffset) =
builder.PrependSlot(4, abcs, default(uoffset))
proc MoreDefaultsStartabcsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MoreDefaultsAddbools*(builder: var Builder, bools: uoffset) =
builder.PrependSlot(5, bools, default(uoffset))
proc MoreDefaultsStartboolsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MoreDefaultsEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,26 @@
#[ MyGame.Example.Ability
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type Ability* = object of FlatObj
func id*(self: Ability): uint32 =
return Get[uint32](self.tab, self.tab.Pos + 0)
func `id=`*(self: var Ability, n: uint32): bool =
return self.tab.Mutate(self.tab.Pos + 0, n)
func distance*(self: Ability): uint32 =
return Get[uint32](self.tab, self.tab.Pos + 4)
func `distance=`*(self: var Ability, n: uint32): bool =
return self.tab.Mutate(self.tab.Pos + 4, n)
proc AbilityCreate*(self: var Builder, id: uint32, distance: uint32): uoffset =
self.Prep(4, 8)
self.Prepend(distance)
self.Prepend(id)
return self.Offset()

View File

@ -0,0 +1,15 @@
#[ MyGame.Example.Any
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type Any*{.pure.} = enum
None = 0.uint8,
Monster = 1.uint8,
TestSimpleTableWithEnum = 2.uint8,
MyGameExample2Monster = 3.uint8,

View File

@ -0,0 +1,15 @@
#[ MyGame.Example.AnyAmbiguousAliases
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type AnyAmbiguousAliases*{.pure.} = enum
None = 0.uint8,
M1 = 1.uint8,
M2 = 2.uint8,
M3 = 3.uint8,

View File

@ -0,0 +1,15 @@
#[ MyGame.Example.AnyUniqueAliases
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type AnyUniqueAliases*{.pure.} = enum
None = 0.uint8,
M = 1.uint8,
Ts = 2.uint8,
M2 = 3.uint8,

View File

@ -0,0 +1,18 @@
#[ MyGame.Example.Color
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
# Composite components of Monster color.
type Color*{.pure.} = enum
Red = 1.uint8,
# \brief color Green
# Green is bit_flag with value (1u << 1)
Green = 2.uint8,
# \brief color Blue (1u << 3)
Blue = 8.uint8,

View File

@ -0,0 +1,14 @@
#[ MyGame.Example.LongEnum
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type LongEnum*{.pure.} = enum
LongOne = 2.uint64,
LongTwo = 4.uint64,
LongBig = 1099511627776.uint64,

View File

@ -359,7 +359,7 @@ function mt:Testarrayofsortedstruct(j)
local o = self.view:Offset(62)
if o ~= 0 then
local x = self.view:Vector(o)
x = x + ((j-1) * 4)
x = x + ((j-1) * 8)
local obj = __MyGame_Example_Ability.New()
obj:Init(self.view.bytes, x)
return obj
@ -852,7 +852,7 @@ function Monster.AddTestarrayofsortedstruct(builder, testarrayofsortedstruct)
end
function Monster.StartTestarrayofsortedstructVector(builder, numElems)
return builder:StartVector(4, numElems, 4)
return builder:StartVector(8, numElems, 4)
end
function Monster.AddFlex(builder, flex)

View File

@ -0,0 +1,662 @@
#[ MyGame.Example.Monster
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import ../InParentNamespace as MyGame_InParentNamespace
import Ability as MyGame_Example_Ability
import Any as MyGame_Example_Any
import AnyAmbiguousAliases as MyGame_Example_AnyAmbiguousAliases
import AnyUniqueAliases as MyGame_Example_AnyUniqueAliases
import Color as MyGame_Example_Color
import LongEnum as MyGame_Example_LongEnum
import Race as MyGame_Example_Race
import Referrable as MyGame_Example_Referrable
import Stat as MyGame_Example_Stat
import Test as MyGame_Example_Test
import Vec3 as MyGame_Example_Vec3
import flatbuffers
import std/options
# an example documentation comment: "monster object"
type Monster* = object of FlatObj
func pos*(self: Monster): Option[MyGame_Example_Vec3.Vec3] =
let o = self.tab.Offset(4)
if o != 0:
return some(MyGame_Example_Vec3.Vec3(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
func mana*(self: Monster): int16 =
let o = self.tab.Offset(6)
if o != 0:
return Get[int16](self.tab, self.tab.Pos + o)
return 150
func `mana=`*(self: var Monster, n: int16): bool =
return self.tab.MutateSlot(6, n)
func hp*(self: Monster): int16 =
let o = self.tab.Offset(8)
if o != 0:
return Get[int16](self.tab, self.tab.Pos + o)
return 100
func `hp=`*(self: var Monster, n: int16): bool =
return self.tab.MutateSlot(8, n)
func name*(self: Monster): string =
let o = self.tab.Offset(10)
if o != 0:
return self.tab.String(self.tab.Pos + o)
return ""
func inventoryLength*(self: Monster): int =
let o = self.tab.Offset(14)
if o != 0:
return self.tab.VectorLen(o)
func inventory*(self: Monster, j: int): uint8 =
let o = self.tab.Offset(14)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[uint8](self.tab, x)
func inventory*(self: Monster): seq[uint8] =
let len = self.inventoryLength
for i in countup(0, len - 1):
result.add(self.inventory(i))
func color*(self: Monster): MyGame_Example_Color.Color =
let o = self.tab.Offset(16)
if o != 0:
return MyGame_Example_Color.Color(Get[uint8](self.tab, self.tab.Pos + o))
return type(result)(8)
func `color=`*(self: var Monster, n: MyGame_Example_Color.Color): bool =
return self.tab.MutateSlot(16, n)
func testType*(self: Monster): MyGame_Example_Any.Any =
let o = self.tab.Offset(18)
if o != 0:
return MyGame_Example_Any.Any(Get[uint8](self.tab, self.tab.Pos + o))
return type(result)(0)
func `testType=`*(self: var Monster, n: MyGame_Example_Any.Any): bool =
return self.tab.MutateSlot(18, n)
func test*(self: Monster): Option[Vtable] =
let o = self.tab.Offset(20)
if o != 0:
return some(self.tab.Union(o))
func test4Length*(self: Monster): int =
let o = self.tab.Offset(22)
if o != 0:
return self.tab.VectorLen(o)
func test4*(self: Monster, j: int): MyGame_Example_Test.Test =
let o = self.tab.Offset(22)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func test4*(self: Monster): seq[MyGame_Example_Test.Test] =
let len = self.test4Length
for i in countup(0, len - 1):
result.add(self.test4(i))
func testarrayofstringLength*(self: Monster): int =
let o = self.tab.Offset(24)
if o != 0:
return self.tab.VectorLen(o)
func testarrayofstring*(self: Monster, j: int): string =
let o = self.tab.Offset(24)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return self.tab.String(x)
func testarrayofstring*(self: Monster): seq[string] =
let len = self.testarrayofstringLength
for i in countup(0, len - 1):
result.add(self.testarrayofstring(i))
func testarrayoftablesLength*(self: Monster): int =
let o = self.tab.Offset(26)
if o != 0:
return self.tab.VectorLen(o)
func testarrayoftables*(self: Monster, j: int): Monster =
let o = self.tab.Offset(26)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return Monster(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func testarrayoftables*(self: Monster): seq[Monster] =
let len = self.testarrayoftablesLength
for i in countup(0, len - 1):
result.add(self.testarrayoftables(i))
func enemy*(self: Monster): Option[Monster] =
let o = self.tab.Offset(28)
if o != 0:
return some(Monster(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
func testnestedflatbufferLength*(self: Monster): int =
let o = self.tab.Offset(30)
if o != 0:
return self.tab.VectorLen(o)
func testnestedflatbuffer*(self: Monster, j: int): uint8 =
let o = self.tab.Offset(30)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[uint8](self.tab, x)
func testnestedflatbuffer*(self: Monster): seq[uint8] =
let len = self.testnestedflatbufferLength
for i in countup(0, len - 1):
result.add(self.testnestedflatbuffer(i))
func testempty*(self: Monster): Option[MyGame_Example_Stat.Stat] =
let o = self.tab.Offset(32)
if o != 0:
return some(MyGame_Example_Stat.Stat(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
func testbool*(self: Monster): bool =
let o = self.tab.Offset(34)
if o != 0:
return Get[bool](self.tab, self.tab.Pos + o)
return false
func `testbool=`*(self: var Monster, n: bool): bool =
return self.tab.MutateSlot(34, n)
func testhashs32Fnv1*(self: Monster): int32 =
let o = self.tab.Offset(36)
if o != 0:
return Get[int32](self.tab, self.tab.Pos + o)
return 0
func `testhashs32Fnv1=`*(self: var Monster, n: int32): bool =
return self.tab.MutateSlot(36, n)
func testhashu32Fnv1*(self: Monster): uint32 =
let o = self.tab.Offset(38)
if o != 0:
return Get[uint32](self.tab, self.tab.Pos + o)
return 0
func `testhashu32Fnv1=`*(self: var Monster, n: uint32): bool =
return self.tab.MutateSlot(38, n)
func testhashs64Fnv1*(self: Monster): int64 =
let o = self.tab.Offset(40)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 0
func `testhashs64Fnv1=`*(self: var Monster, n: int64): bool =
return self.tab.MutateSlot(40, n)
func testhashu64Fnv1*(self: Monster): uint64 =
let o = self.tab.Offset(42)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `testhashu64Fnv1=`*(self: var Monster, n: uint64): bool =
return self.tab.MutateSlot(42, n)
func testhashs32Fnv1a*(self: Monster): int32 =
let o = self.tab.Offset(44)
if o != 0:
return Get[int32](self.tab, self.tab.Pos + o)
return 0
func `testhashs32Fnv1a=`*(self: var Monster, n: int32): bool =
return self.tab.MutateSlot(44, n)
func testhashu32Fnv1a*(self: Monster): uint32 =
let o = self.tab.Offset(46)
if o != 0:
return Get[uint32](self.tab, self.tab.Pos + o)
return 0
func `testhashu32Fnv1a=`*(self: var Monster, n: uint32): bool =
return self.tab.MutateSlot(46, n)
func testhashs64Fnv1a*(self: Monster): int64 =
let o = self.tab.Offset(48)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 0
func `testhashs64Fnv1a=`*(self: var Monster, n: int64): bool =
return self.tab.MutateSlot(48, n)
func testhashu64Fnv1a*(self: Monster): uint64 =
let o = self.tab.Offset(50)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `testhashu64Fnv1a=`*(self: var Monster, n: uint64): bool =
return self.tab.MutateSlot(50, n)
func testarrayofboolsLength*(self: Monster): int =
let o = self.tab.Offset(52)
if o != 0:
return self.tab.VectorLen(o)
func testarrayofbools*(self: Monster, j: int): bool =
let o = self.tab.Offset(52)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[bool](self.tab, x)
func testarrayofbools*(self: Monster): seq[bool] =
let len = self.testarrayofboolsLength
for i in countup(0, len - 1):
result.add(self.testarrayofbools(i))
func testf*(self: Monster): float32 =
let o = self.tab.Offset(54)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 3.14159
func `testf=`*(self: var Monster, n: float32): bool =
return self.tab.MutateSlot(54, n)
func testf2*(self: Monster): float32 =
let o = self.tab.Offset(56)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 3.0
func `testf2=`*(self: var Monster, n: float32): bool =
return self.tab.MutateSlot(56, n)
func testf3*(self: Monster): float32 =
let o = self.tab.Offset(58)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 0.0
func `testf3=`*(self: var Monster, n: float32): bool =
return self.tab.MutateSlot(58, n)
func testarrayofstring2Length*(self: Monster): int =
let o = self.tab.Offset(60)
if o != 0:
return self.tab.VectorLen(o)
func testarrayofstring2*(self: Monster, j: int): string =
let o = self.tab.Offset(60)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return self.tab.String(x)
func testarrayofstring2*(self: Monster): seq[string] =
let len = self.testarrayofstring2Length
for i in countup(0, len - 1):
result.add(self.testarrayofstring2(i))
func testarrayofsortedstructLength*(self: Monster): int =
let o = self.tab.Offset(62)
if o != 0:
return self.tab.VectorLen(o)
func testarrayofsortedstruct*(self: Monster, j: int): MyGame_Example_Ability.Ability =
let o = self.tab.Offset(62)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return MyGame_Example_Ability.Ability(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func testarrayofsortedstruct*(self: Monster): seq[MyGame_Example_Ability.Ability] =
let len = self.testarrayofsortedstructLength
for i in countup(0, len - 1):
result.add(self.testarrayofsortedstruct(i))
func flexLength*(self: Monster): int =
let o = self.tab.Offset(64)
if o != 0:
return self.tab.VectorLen(o)
func flex*(self: Monster, j: int): uint8 =
let o = self.tab.Offset(64)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[uint8](self.tab, x)
func flex*(self: Monster): seq[uint8] =
let len = self.flexLength
for i in countup(0, len - 1):
result.add(self.flex(i))
func test5Length*(self: Monster): int =
let o = self.tab.Offset(66)
if o != 0:
return self.tab.VectorLen(o)
func test5*(self: Monster, j: int): MyGame_Example_Test.Test =
let o = self.tab.Offset(66)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func test5*(self: Monster): seq[MyGame_Example_Test.Test] =
let len = self.test5Length
for i in countup(0, len - 1):
result.add(self.test5(i))
func vectorOfLongsLength*(self: Monster): int =
let o = self.tab.Offset(68)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfLongs*(self: Monster, j: int): int64 =
let o = self.tab.Offset(68)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[int64](self.tab, x)
func vectorOfLongs*(self: Monster): seq[int64] =
let len = self.vectorOfLongsLength
for i in countup(0, len - 1):
result.add(self.vectorOfLongs(i))
func vectorOfDoublesLength*(self: Monster): int =
let o = self.tab.Offset(70)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfDoubles*(self: Monster, j: int): float64 =
let o = self.tab.Offset(70)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[float64](self.tab, x)
func vectorOfDoubles*(self: Monster): seq[float64] =
let len = self.vectorOfDoublesLength
for i in countup(0, len - 1):
result.add(self.vectorOfDoubles(i))
func parentNamespaceTest*(self: Monster): Option[MyGame_InParentNamespace.InParentNamespace] =
let o = self.tab.Offset(72)
if o != 0:
return some(MyGame_InParentNamespace.InParentNamespace(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
func vectorOfReferrablesLength*(self: Monster): int =
let o = self.tab.Offset(74)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfReferrables*(self: Monster, j: int): MyGame_Example_Referrable.Referrable =
let o = self.tab.Offset(74)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return MyGame_Example_Referrable.Referrable(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func vectorOfReferrables*(self: Monster): seq[MyGame_Example_Referrable.Referrable] =
let len = self.vectorOfReferrablesLength
for i in countup(0, len - 1):
result.add(self.vectorOfReferrables(i))
func singleWeakReference*(self: Monster): uint64 =
let o = self.tab.Offset(76)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `singleWeakReference=`*(self: var Monster, n: uint64): bool =
return self.tab.MutateSlot(76, n)
func vectorOfWeakReferencesLength*(self: Monster): int =
let o = self.tab.Offset(78)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfWeakReferences*(self: Monster, j: int): uint64 =
let o = self.tab.Offset(78)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[uint64](self.tab, x)
func vectorOfWeakReferences*(self: Monster): seq[uint64] =
let len = self.vectorOfWeakReferencesLength
for i in countup(0, len - 1):
result.add(self.vectorOfWeakReferences(i))
func vectorOfStrongReferrablesLength*(self: Monster): int =
let o = self.tab.Offset(80)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfStrongReferrables*(self: Monster, j: int): MyGame_Example_Referrable.Referrable =
let o = self.tab.Offset(80)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return MyGame_Example_Referrable.Referrable(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func vectorOfStrongReferrables*(self: Monster): seq[MyGame_Example_Referrable.Referrable] =
let len = self.vectorOfStrongReferrablesLength
for i in countup(0, len - 1):
result.add(self.vectorOfStrongReferrables(i))
func coOwningReference*(self: Monster): uint64 =
let o = self.tab.Offset(82)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `coOwningReference=`*(self: var Monster, n: uint64): bool =
return self.tab.MutateSlot(82, n)
func vectorOfCoOwningReferencesLength*(self: Monster): int =
let o = self.tab.Offset(84)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfCoOwningReferences*(self: Monster, j: int): uint64 =
let o = self.tab.Offset(84)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[uint64](self.tab, x)
func vectorOfCoOwningReferences*(self: Monster): seq[uint64] =
let len = self.vectorOfCoOwningReferencesLength
for i in countup(0, len - 1):
result.add(self.vectorOfCoOwningReferences(i))
func nonOwningReference*(self: Monster): uint64 =
let o = self.tab.Offset(86)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `nonOwningReference=`*(self: var Monster, n: uint64): bool =
return self.tab.MutateSlot(86, n)
func vectorOfNonOwningReferencesLength*(self: Monster): int =
let o = self.tab.Offset(88)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfNonOwningReferences*(self: Monster, j: int): uint64 =
let o = self.tab.Offset(88)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[uint64](self.tab, x)
func vectorOfNonOwningReferences*(self: Monster): seq[uint64] =
let len = self.vectorOfNonOwningReferencesLength
for i in countup(0, len - 1):
result.add(self.vectorOfNonOwningReferences(i))
func anyUniqueType*(self: Monster): MyGame_Example_AnyUniqueAliases.AnyUniqueAliases =
let o = self.tab.Offset(90)
if o != 0:
return MyGame_Example_AnyUniqueAliases.AnyUniqueAliases(Get[uint8](self.tab, self.tab.Pos + o))
return type(result)(0)
func `anyUniqueType=`*(self: var Monster, n: MyGame_Example_AnyUniqueAliases.AnyUniqueAliases): bool =
return self.tab.MutateSlot(90, n)
func anyUnique*(self: Monster): Option[Vtable] =
let o = self.tab.Offset(92)
if o != 0:
return some(self.tab.Union(o))
func anyAmbiguousType*(self: Monster): MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases =
let o = self.tab.Offset(94)
if o != 0:
return MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases(Get[uint8](self.tab, self.tab.Pos + o))
return type(result)(0)
func `anyAmbiguousType=`*(self: var Monster, n: MyGame_Example_AnyAmbiguousAliases.AnyAmbiguousAliases): bool =
return self.tab.MutateSlot(94, n)
func anyAmbiguous*(self: Monster): Option[Vtable] =
let o = self.tab.Offset(96)
if o != 0:
return some(self.tab.Union(o))
func vectorOfEnumsLength*(self: Monster): int =
let o = self.tab.Offset(98)
if o != 0:
return self.tab.VectorLen(o)
func vectorOfEnums*(self: Monster, j: int): MyGame_Example_Color.Color =
let o = self.tab.Offset(98)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return MyGame_Example_Color.Color(Get[uint8](self.tab, x))
func vectorOfEnums*(self: Monster): seq[MyGame_Example_Color.Color] =
let len = self.vectorOfEnumsLength
for i in countup(0, len - 1):
result.add(self.vectorOfEnums(i))
func signedEnum*(self: Monster): MyGame_Example_Race.Race =
let o = self.tab.Offset(100)
if o != 0:
return MyGame_Example_Race.Race(Get[int8](self.tab, self.tab.Pos + o))
return type(result)(-1)
func `signedEnum=`*(self: var Monster, n: MyGame_Example_Race.Race): bool =
return self.tab.MutateSlot(100, n)
func testrequirednestedflatbufferLength*(self: Monster): int =
let o = self.tab.Offset(102)
if o != 0:
return self.tab.VectorLen(o)
func testrequirednestedflatbuffer*(self: Monster, j: int): uint8 =
let o = self.tab.Offset(102)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[uint8](self.tab, x)
func testrequirednestedflatbuffer*(self: Monster): seq[uint8] =
let len = self.testrequirednestedflatbufferLength
for i in countup(0, len - 1):
result.add(self.testrequirednestedflatbuffer(i))
func scalarKeySortedTablesLength*(self: Monster): int =
let o = self.tab.Offset(104)
if o != 0:
return self.tab.VectorLen(o)
func scalarKeySortedTables*(self: Monster, j: int): MyGame_Example_Stat.Stat =
let o = self.tab.Offset(104)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 4.uoffset
return MyGame_Example_Stat.Stat(tab: Vtable(Bytes: self.tab.Bytes, Pos: x))
func scalarKeySortedTables*(self: Monster): seq[MyGame_Example_Stat.Stat] =
let len = self.scalarKeySortedTablesLength
for i in countup(0, len - 1):
result.add(self.scalarKeySortedTables(i))
func nativeInline*(self: Monster): Option[MyGame_Example_Test.Test] =
let o = self.tab.Offset(106)
if o != 0:
return some(MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
func longEnumNonEnumDefault*(self: Monster): MyGame_Example_LongEnum.LongEnum =
let o = self.tab.Offset(108)
if o != 0:
return MyGame_Example_LongEnum.LongEnum(Get[uint64](self.tab, self.tab.Pos + o))
return type(result)(0)
func `longEnumNonEnumDefault=`*(self: var Monster, n: MyGame_Example_LongEnum.LongEnum): bool =
return self.tab.MutateSlot(108, n)
func longEnumNormalDefault*(self: Monster): MyGame_Example_LongEnum.LongEnum =
let o = self.tab.Offset(110)
if o != 0:
return MyGame_Example_LongEnum.LongEnum(Get[uint64](self.tab, self.tab.Pos + o))
return type(result)(2)
func `longEnumNormalDefault=`*(self: var Monster, n: MyGame_Example_LongEnum.LongEnum): bool =
return self.tab.MutateSlot(110, n)
proc MonsterStart*(builder: var Builder) =
builder.StartObject(54)
proc MonsterAddpos*(builder: var Builder, pos: uoffset) =
builder.PrependStructSlot(0, pos, default(uoffset))
proc MonsterAddmana*(builder: var Builder, mana: int16) =
builder.PrependSlot(1, mana, default(int16))
proc MonsterAddhp*(builder: var Builder, hp: int16) =
builder.PrependSlot(2, hp, default(int16))
proc MonsterAddname*(builder: var Builder, name: uoffset) =
builder.PrependSlot(3, name, default(uoffset))
proc MonsterAddinventory*(builder: var Builder, inventory: uoffset) =
builder.PrependSlot(5, inventory, default(uoffset))
proc MonsterStartinventoryVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddcolor*(builder: var Builder, color: uint8) =
builder.PrependSlot(6, color, default(uint8))
proc MonsterAddtestType*(builder: var Builder, testType: uint8) =
builder.PrependSlot(7, testType, default(uint8))
proc MonsterAddtest*(builder: var Builder, test: uoffset) =
builder.PrependSlot(8, test, default(uoffset))
proc MonsterAddtest4*(builder: var Builder, test4: uoffset) =
builder.PrependSlot(9, test4, default(uoffset))
proc MonsterStarttest4Vector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 2)
proc MonsterAddtestarrayofstring*(builder: var Builder, testarrayofstring: uoffset) =
builder.PrependSlot(10, testarrayofstring, default(uoffset))
proc MonsterStarttestarrayofstringVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddtestarrayoftables*(builder: var Builder, testarrayoftables: uoffset) =
builder.PrependSlot(11, testarrayoftables, default(uoffset))
proc MonsterStarttestarrayoftablesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddenemy*(builder: var Builder, enemy: uoffset) =
builder.PrependStructSlot(12, enemy, default(uoffset))
proc MonsterAddtestnestedflatbuffer*(builder: var Builder, testnestedflatbuffer: uoffset) =
builder.PrependSlot(13, testnestedflatbuffer, default(uoffset))
proc MonsterStarttestnestedflatbufferVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddtestempty*(builder: var Builder, testempty: uoffset) =
builder.PrependStructSlot(14, testempty, default(uoffset))
proc MonsterAddtestbool*(builder: var Builder, testbool: bool) =
builder.PrependSlot(15, testbool, default(bool))
proc MonsterAddtesthashs32Fnv1*(builder: var Builder, testhashs32Fnv1: int32) =
builder.PrependSlot(16, testhashs32Fnv1, default(int32))
proc MonsterAddtesthashu32Fnv1*(builder: var Builder, testhashu32Fnv1: uint32) =
builder.PrependSlot(17, testhashu32Fnv1, default(uint32))
proc MonsterAddtesthashs64Fnv1*(builder: var Builder, testhashs64Fnv1: int64) =
builder.PrependSlot(18, testhashs64Fnv1, default(int64))
proc MonsterAddtesthashu64Fnv1*(builder: var Builder, testhashu64Fnv1: uint64) =
builder.PrependSlot(19, testhashu64Fnv1, default(uint64))
proc MonsterAddtesthashs32Fnv1a*(builder: var Builder, testhashs32Fnv1a: int32) =
builder.PrependSlot(20, testhashs32Fnv1a, default(int32))
proc MonsterAddtesthashu32Fnv1a*(builder: var Builder, testhashu32Fnv1a: uint32) =
builder.PrependSlot(21, testhashu32Fnv1a, default(uint32))
proc MonsterAddtesthashs64Fnv1a*(builder: var Builder, testhashs64Fnv1a: int64) =
builder.PrependSlot(22, testhashs64Fnv1a, default(int64))
proc MonsterAddtesthashu64Fnv1a*(builder: var Builder, testhashu64Fnv1a: uint64) =
builder.PrependSlot(23, testhashu64Fnv1a, default(uint64))
proc MonsterAddtestarrayofbools*(builder: var Builder, testarrayofbools: uoffset) =
builder.PrependSlot(24, testarrayofbools, default(uoffset))
proc MonsterStarttestarrayofboolsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddtestf*(builder: var Builder, testf: float32) =
builder.PrependSlot(25, testf, default(float32))
proc MonsterAddtestf2*(builder: var Builder, testf2: float32) =
builder.PrependSlot(26, testf2, default(float32))
proc MonsterAddtestf3*(builder: var Builder, testf3: float32) =
builder.PrependSlot(27, testf3, default(float32))
proc MonsterAddtestarrayofstring2*(builder: var Builder, testarrayofstring2: uoffset) =
builder.PrependSlot(28, testarrayofstring2, default(uoffset))
proc MonsterStarttestarrayofstring2Vector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddtestarrayofsortedstruct*(builder: var Builder, testarrayofsortedstruct: uoffset) =
builder.PrependSlot(29, testarrayofsortedstruct, default(uoffset))
proc MonsterStarttestarrayofsortedstructVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 4)
proc MonsterAddflex*(builder: var Builder, flex: uoffset) =
builder.PrependSlot(30, flex, default(uoffset))
proc MonsterStartflexVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddtest5*(builder: var Builder, test5: uoffset) =
builder.PrependSlot(31, test5, default(uoffset))
proc MonsterStarttest5Vector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 2)
proc MonsterAddvectorOfLongs*(builder: var Builder, vectorOfLongs: uoffset) =
builder.PrependSlot(32, vectorOfLongs, default(uoffset))
proc MonsterStartvectorOfLongsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc MonsterAddvectorOfDoubles*(builder: var Builder, vectorOfDoubles: uoffset) =
builder.PrependSlot(33, vectorOfDoubles, default(uoffset))
proc MonsterStartvectorOfDoublesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc MonsterAddparentNamespaceTest*(builder: var Builder, parentNamespaceTest: uoffset) =
builder.PrependStructSlot(34, parentNamespaceTest, default(uoffset))
proc MonsterAddvectorOfReferrables*(builder: var Builder, vectorOfReferrables: uoffset) =
builder.PrependSlot(35, vectorOfReferrables, default(uoffset))
proc MonsterStartvectorOfReferrablesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddsingleWeakReference*(builder: var Builder, singleWeakReference: uint64) =
builder.PrependSlot(36, singleWeakReference, default(uint64))
proc MonsterAddvectorOfWeakReferences*(builder: var Builder, vectorOfWeakReferences: uoffset) =
builder.PrependSlot(37, vectorOfWeakReferences, default(uoffset))
proc MonsterStartvectorOfWeakReferencesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc MonsterAddvectorOfStrongReferrables*(builder: var Builder, vectorOfStrongReferrables: uoffset) =
builder.PrependSlot(38, vectorOfStrongReferrables, default(uoffset))
proc MonsterStartvectorOfStrongReferrablesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddcoOwningReference*(builder: var Builder, coOwningReference: uint64) =
builder.PrependSlot(39, coOwningReference, default(uint64))
proc MonsterAddvectorOfCoOwningReferences*(builder: var Builder, vectorOfCoOwningReferences: uoffset) =
builder.PrependSlot(40, vectorOfCoOwningReferences, default(uoffset))
proc MonsterStartvectorOfCoOwningReferencesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc MonsterAddnonOwningReference*(builder: var Builder, nonOwningReference: uint64) =
builder.PrependSlot(41, nonOwningReference, default(uint64))
proc MonsterAddvectorOfNonOwningReferences*(builder: var Builder, vectorOfNonOwningReferences: uoffset) =
builder.PrependSlot(42, vectorOfNonOwningReferences, default(uoffset))
proc MonsterStartvectorOfNonOwningReferencesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc MonsterAddanyUniqueType*(builder: var Builder, anyUniqueType: uint8) =
builder.PrependSlot(43, anyUniqueType, default(uint8))
proc MonsterAddanyUnique*(builder: var Builder, anyUnique: uoffset) =
builder.PrependSlot(44, anyUnique, default(uoffset))
proc MonsterAddanyAmbiguousType*(builder: var Builder, anyAmbiguousType: uint8) =
builder.PrependSlot(45, anyAmbiguousType, default(uint8))
proc MonsterAddanyAmbiguous*(builder: var Builder, anyAmbiguous: uoffset) =
builder.PrependSlot(46, anyAmbiguous, default(uoffset))
proc MonsterAddvectorOfEnums*(builder: var Builder, vectorOfEnums: uoffset) =
builder.PrependSlot(47, vectorOfEnums, default(uoffset))
proc MonsterStartvectorOfEnumsVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddsignedEnum*(builder: var Builder, signedEnum: int8) =
builder.PrependSlot(48, signedEnum, default(int8))
proc MonsterAddtestrequirednestedflatbuffer*(builder: var Builder, testrequirednestedflatbuffer: uoffset) =
builder.PrependSlot(49, testrequirednestedflatbuffer, default(uoffset))
proc MonsterStarttestrequirednestedflatbufferVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc MonsterAddscalarKeySortedTables*(builder: var Builder, scalarKeySortedTables: uoffset) =
builder.PrependSlot(50, scalarKeySortedTables, default(uoffset))
proc MonsterStartscalarKeySortedTablesVector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(4, numElems, 4)
proc MonsterAddnativeInline*(builder: var Builder, nativeInline: uoffset) =
builder.PrependStructSlot(51, nativeInline, default(uoffset))
proc MonsterAddlongEnumNonEnumDefault*(builder: var Builder, longEnumNonEnumDefault: uint64) =
builder.PrependSlot(52, longEnumNonEnumDefault, default(uint64))
proc MonsterAddlongEnumNormalDefault*(builder: var Builder, longEnumNormalDefault: uint64) =
builder.PrependSlot(53, longEnumNormalDefault, default(uint64))
proc MonsterEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,15 @@
#[ MyGame.Example.Race
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type Race*{.pure.} = enum
None = -1.int8,
Human = 0.int8,
Dwarf = 1.int8,
Elf = 2.int8,

View File

@ -0,0 +1,26 @@
#[ MyGame.Example.Referrable
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type Referrable* = object of FlatObj
func id*(self: Referrable): uint64 =
let o = self.tab.Offset(4)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `id=`*(self: var Referrable, n: uint64): bool =
return self.tab.MutateSlot(4, n)
proc ReferrableStart*(builder: var Builder) =
builder.StartObject(1)
proc ReferrableAddid*(builder: var Builder, id: uint64) =
builder.PrependSlot(0, id, default(uint64))
proc ReferrableEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,42 @@
#[ MyGame.Example.Stat
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
import std/options
type Stat* = object of FlatObj
func id*(self: Stat): Option[string] =
let o = self.tab.Offset(4)
if o != 0:
return some(self.tab.String(self.tab.Pos + o))
func val*(self: Stat): int64 =
let o = self.tab.Offset(6)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 0
func `val=`*(self: var Stat, n: int64): bool =
return self.tab.MutateSlot(6, n)
func count*(self: Stat): uint16 =
let o = self.tab.Offset(8)
if o != 0:
return Get[uint16](self.tab, self.tab.Pos + o)
return 0
func `count=`*(self: var Stat, n: uint16): bool =
return self.tab.MutateSlot(8, n)
proc StatStart*(builder: var Builder) =
builder.StartObject(3)
proc StatAddid*(builder: var Builder, id: uoffset) =
builder.PrependSlot(0, id, default(uoffset))
proc StatAddval*(builder: var Builder, val: int64) =
builder.PrependSlot(1, val, default(int64))
proc StatAddcount*(builder: var Builder, count: uint16) =
builder.PrependSlot(2, count, default(uint16))
proc StatEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,34 @@
#[ MyGame.Example.StructOfStructs
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import Ability as MyGame_Example_Ability
import Test as MyGame_Example_Test
import flatbuffers
type StructOfStructs* = object of FlatObj
func a*(self: StructOfStructs): MyGame_Example_Ability.Ability =
return MyGame_Example_Ability.Ability(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + 0))
func b*(self: StructOfStructs): MyGame_Example_Test.Test =
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + 8))
func c*(self: StructOfStructs): MyGame_Example_Ability.Ability =
return MyGame_Example_Ability.Ability(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + 12))
proc StructOfStructsCreate*(self: var Builder, a_id: uint32, a_distance: uint32, b_a: int16, b_b: int8, c_id: uint32, c_distance: uint32): uoffset =
self.Prep(4, 20)
self.Prep(4, 8)
self.Prepend(c_distance)
self.Prepend(c_id)
self.Prep(2, 4)
self.Pad(1)
self.Prepend(b_b)
self.Prepend(b_a)
self.Prep(4, 8)
self.Prepend(a_distance)
self.Prepend(a_id)
return self.Offset()

View File

@ -0,0 +1,30 @@
#[ MyGame.Example.StructOfStructsOfStructs
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import StructOfStructs as MyGame_Example_StructOfStructs
import flatbuffers
type StructOfStructsOfStructs* = object of FlatObj
func a*(self: StructOfStructsOfStructs): MyGame_Example_StructOfStructs.StructOfStructs =
return MyGame_Example_StructOfStructs.StructOfStructs(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + 0))
proc StructOfStructsOfStructsCreate*(self: var Builder, a_a_id: uint32, a_a_distance: uint32, a_b_a: int16, a_b_b: int8, a_c_id: uint32, a_c_distance: uint32): uoffset =
self.Prep(4, 20)
self.Prep(4, 20)
self.Prep(4, 8)
self.Prepend(a_c_distance)
self.Prepend(a_c_id)
self.Prep(2, 4)
self.Pad(1)
self.Prepend(a_b_b)
self.Prepend(a_b_a)
self.Prep(4, 8)
self.Prepend(a_a_distance)
self.Prepend(a_a_id)
return self.Offset()

View File

@ -0,0 +1,27 @@
#[ MyGame.Example.Test
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type Test* = object of FlatObj
func a*(self: Test): int16 =
return Get[int16](self.tab, self.tab.Pos + 0)
func `a=`*(self: var Test, n: int16): bool =
return self.tab.Mutate(self.tab.Pos + 0, n)
func b*(self: Test): int8 =
return Get[int8](self.tab, self.tab.Pos + 2)
func `b=`*(self: var Test, n: int8): bool =
return self.tab.Mutate(self.tab.Pos + 2, n)
proc TestCreate*(self: var Builder, a: int16, b: int8): uoffset =
self.Prep(2, 4)
self.Pad(1)
self.Prepend(b)
self.Prepend(a)
return self.Offset()

View File

@ -0,0 +1,27 @@
#[ MyGame.Example.TestSimpleTableWithEnum
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import Color as MyGame_Example_Color
import flatbuffers
type TestSimpleTableWithEnum* = object of FlatObj
func color*(self: TestSimpleTableWithEnum): MyGame_Example_Color.Color =
let o = self.tab.Offset(4)
if o != 0:
return MyGame_Example_Color.Color(Get[uint8](self.tab, self.tab.Pos + o))
return type(result)(2)
func `color=`*(self: var TestSimpleTableWithEnum, n: MyGame_Example_Color.Color): bool =
return self.tab.MutateSlot(4, n)
proc TestSimpleTableWithEnumStart*(builder: var Builder) =
builder.StartObject(1)
proc TestSimpleTableWithEnumAddcolor*(builder: var Builder, color: uint8) =
builder.PrependSlot(0, color, default(uint8))
proc TestSimpleTableWithEnumEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,144 @@
#[ MyGame.Example.TypeAliases
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
import std/options
type TypeAliases* = object of FlatObj
func i8*(self: TypeAliases): int8 =
let o = self.tab.Offset(4)
if o != 0:
return Get[int8](self.tab, self.tab.Pos + o)
return 0
func `i8=`*(self: var TypeAliases, n: int8): bool =
return self.tab.MutateSlot(4, n)
func u8*(self: TypeAliases): uint8 =
let o = self.tab.Offset(6)
if o != 0:
return Get[uint8](self.tab, self.tab.Pos + o)
return 0
func `u8=`*(self: var TypeAliases, n: uint8): bool =
return self.tab.MutateSlot(6, n)
func i16*(self: TypeAliases): int16 =
let o = self.tab.Offset(8)
if o != 0:
return Get[int16](self.tab, self.tab.Pos + o)
return 0
func `i16=`*(self: var TypeAliases, n: int16): bool =
return self.tab.MutateSlot(8, n)
func u16*(self: TypeAliases): uint16 =
let o = self.tab.Offset(10)
if o != 0:
return Get[uint16](self.tab, self.tab.Pos + o)
return 0
func `u16=`*(self: var TypeAliases, n: uint16): bool =
return self.tab.MutateSlot(10, n)
func i32*(self: TypeAliases): int32 =
let o = self.tab.Offset(12)
if o != 0:
return Get[int32](self.tab, self.tab.Pos + o)
return 0
func `i32=`*(self: var TypeAliases, n: int32): bool =
return self.tab.MutateSlot(12, n)
func u32*(self: TypeAliases): uint32 =
let o = self.tab.Offset(14)
if o != 0:
return Get[uint32](self.tab, self.tab.Pos + o)
return 0
func `u32=`*(self: var TypeAliases, n: uint32): bool =
return self.tab.MutateSlot(14, n)
func i64*(self: TypeAliases): int64 =
let o = self.tab.Offset(16)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 0
func `i64=`*(self: var TypeAliases, n: int64): bool =
return self.tab.MutateSlot(16, n)
func u64*(self: TypeAliases): uint64 =
let o = self.tab.Offset(18)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `u64=`*(self: var TypeAliases, n: uint64): bool =
return self.tab.MutateSlot(18, n)
func f32*(self: TypeAliases): float32 =
let o = self.tab.Offset(20)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 0.0
func `f32=`*(self: var TypeAliases, n: float32): bool =
return self.tab.MutateSlot(20, n)
func f64*(self: TypeAliases): float64 =
let o = self.tab.Offset(22)
if o != 0:
return Get[float64](self.tab, self.tab.Pos + o)
return 0.0
func `f64=`*(self: var TypeAliases, n: float64): bool =
return self.tab.MutateSlot(22, n)
func v8Length*(self: TypeAliases): int =
let o = self.tab.Offset(24)
if o != 0:
return self.tab.VectorLen(o)
func v8*(self: TypeAliases, j: int): int8 =
let o = self.tab.Offset(24)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 1.uoffset
return Get[int8](self.tab, x)
func v8*(self: TypeAliases): seq[int8] =
let len = self.v8Length
for i in countup(0, len - 1):
result.add(self.v8(i))
func vf64Length*(self: TypeAliases): int =
let o = self.tab.Offset(26)
if o != 0:
return self.tab.VectorLen(o)
func vf64*(self: TypeAliases, j: int): float64 =
let o = self.tab.Offset(26)
if o != 0:
var x = self.tab.Vector(o)
x += j.uoffset * 8.uoffset
return Get[float64](self.tab, x)
func vf64*(self: TypeAliases): seq[float64] =
let len = self.vf64Length
for i in countup(0, len - 1):
result.add(self.vf64(i))
proc TypeAliasesStart*(builder: var Builder) =
builder.StartObject(12)
proc TypeAliasesAddi8*(builder: var Builder, i8: int8) =
builder.PrependSlot(0, i8, default(int8))
proc TypeAliasesAddu8*(builder: var Builder, u8: uint8) =
builder.PrependSlot(1, u8, default(uint8))
proc TypeAliasesAddi16*(builder: var Builder, i16: int16) =
builder.PrependSlot(2, i16, default(int16))
proc TypeAliasesAddu16*(builder: var Builder, u16: uint16) =
builder.PrependSlot(3, u16, default(uint16))
proc TypeAliasesAddi32*(builder: var Builder, i32: int32) =
builder.PrependSlot(4, i32, default(int32))
proc TypeAliasesAddu32*(builder: var Builder, u32: uint32) =
builder.PrependSlot(5, u32, default(uint32))
proc TypeAliasesAddi64*(builder: var Builder, i64: int64) =
builder.PrependSlot(6, i64, default(int64))
proc TypeAliasesAddu64*(builder: var Builder, u64: uint64) =
builder.PrependSlot(7, u64, default(uint64))
proc TypeAliasesAddf32*(builder: var Builder, f32: float32) =
builder.PrependSlot(8, f32, default(float32))
proc TypeAliasesAddf64*(builder: var Builder, f64: float64) =
builder.PrependSlot(9, f64, default(float64))
proc TypeAliasesAddv8*(builder: var Builder, v8: uoffset) =
builder.PrependSlot(10, v8, default(uoffset))
proc TypeAliasesStartv8Vector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(1, numElems, 1)
proc TypeAliasesAddvf64*(builder: var Builder, vf64: uoffset) =
builder.PrependSlot(11, vf64, default(uoffset))
proc TypeAliasesStartvf64Vector*(builder: var Builder, numElems: uoffset) =
builder.StartVector(8, numElems, 8)
proc TypeAliasesEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,52 @@
#[ MyGame.Example.Vec3
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import Color as MyGame_Example_Color
import Test as MyGame_Example_Test
import flatbuffers
type Vec3* = object of FlatObj
func x*(self: Vec3): float32 =
return Get[float32](self.tab, self.tab.Pos + 0)
func `x=`*(self: var Vec3, n: float32): bool =
return self.tab.Mutate(self.tab.Pos + 0, n)
func y*(self: Vec3): float32 =
return Get[float32](self.tab, self.tab.Pos + 4)
func `y=`*(self: var Vec3, n: float32): bool =
return self.tab.Mutate(self.tab.Pos + 4, n)
func z*(self: Vec3): float32 =
return Get[float32](self.tab, self.tab.Pos + 8)
func `z=`*(self: var Vec3, n: float32): bool =
return self.tab.Mutate(self.tab.Pos + 8, n)
func test1*(self: Vec3): float64 =
return Get[float64](self.tab, self.tab.Pos + 16)
func `test1=`*(self: var Vec3, n: float64): bool =
return self.tab.Mutate(self.tab.Pos + 16, n)
func test2*(self: Vec3): MyGame_Example_Color.Color =
return MyGame_Example_Color.Color(Get[uint8](self.tab, self.tab.Pos + 24))
func `test2=`*(self: var Vec3, n: MyGame_Example_Color.Color): bool =
return self.tab.Mutate(self.tab.Pos + 24, n)
func test3*(self: Vec3): MyGame_Example_Test.Test =
return MyGame_Example_Test.Test(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + 26))
proc Vec3Create*(self: var Builder, x: float32, y: float32, z: float32, test1: float64, test2: MyGame_Example_Color.Color, test3_a: int16, test3_b: int8): uoffset =
self.Prep(8, 32)
self.Pad(2)
self.Prep(2, 4)
self.Pad(1)
self.Prepend(test3_b)
self.Prepend(test3_a)
self.Pad(1)
self.Prepend(test2)
self.Prepend(test1)
self.Pad(4)
self.Prepend(z)
self.Prepend(y)
self.Prepend(x)
return self.Offset()

View File

@ -0,0 +1,17 @@
#[ MyGame.Example2.Monster
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type Monster* = object of FlatObj
proc MonsterStart*(builder: var Builder) =
builder.StartObject(0)
proc MonsterEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,17 @@
#[ MyGame.InParentNamespace
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type InParentNamespace* = object of FlatObj
proc InParentNamespaceStart*(builder: var Builder) =
builder.StartObject(0)
proc InParentNamespaceEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,12 @@
#[ MyGame.OtherNameSpace.FromInclude
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
type FromInclude*{.pure.} = enum
IncludeVal = 0.int64,

View File

@ -0,0 +1,25 @@
#[ MyGame.OtherNameSpace.TableB
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import ../../TableA as TableA
import flatbuffers
import std/options
type TableB* = object of FlatObj
func a*(self: TableB): Option[TableA.TableA] =
let o = self.tab.Offset(4)
if o != 0:
return some(TableA.TableA(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
proc TableBstart*(builder: var Builder) =
builder.StartObject(1)
proc TableBadda*(builder: var Builder, a: uoffset) =
builder.PrependStructSlot(0, a, default(uoffset))
proc TableBend*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,21 @@
#[ MyGame.OtherNameSpace.Unused
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import flatbuffers
type Unused* = object of FlatObj
func a*(self: Unused): int32 =
return Get[int32](self.tab, self.tab.Pos + 0)
func `a=`*(self: var Unused, n: int32): bool =
return self.tab.Mutate(self.tab.Pos + 0, n)
proc UnusedCreate*(self: var Builder, a: int32): uoffset =
self.Prep(4, 4)
self.Prepend(a)
return self.Offset()

20
tests/Property.nim Normal file
View File

@ -0,0 +1,20 @@
#[ Property
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
]#
import flatbuffers
type Property* = object of FlatObj
func property*(self: Property): bool =
return Get[bool](self.tab, self.tab.Pos + 0)
func `property=`*(self: var Property, n: bool): bool =
return self.tab.Mutate(self.tab.Pos + 0, n)
proc PropertyCreate*(self: var Builder, property: bool): uoffset =
self.Prep(1, 1)
self.Prepend(property)
return self.Offset()

25
tests/TableA.nim Normal file
View File

@ -0,0 +1,25 @@
#[ TableA
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : MyGame.Example.Monster ()
]#
import MyGame/OtherNameSpace/TableB as MyGame_OtherNameSpace_TableB
import flatbuffers
import std/options
type TableA* = object of FlatObj
func b*(self: TableA): Option[MyGame_OtherNameSpace_TableB.TableB] =
let o = self.tab.Offset(4)
if o != 0:
return some(MyGame_OtherNameSpace_TableB.TableB(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
proc TableAstart*(builder: var Builder) =
builder.StartObject(1)
proc TableAaddb*(builder: var Builder, b: uoffset) =
builder.PrependStructSlot(0, b, default(uoffset))
proc TableAend*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -0,0 +1,24 @@
#[ TestMutatingBool
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
]#
import Property as Property
import flatbuffers
import std/options
type TestMutatingBool* = object of FlatObj
func b*(self: TestMutatingBool): Option[Property.Property] =
let o = self.tab.Offset(4)
if o != 0:
return some(Property.Property(tab: Vtable(Bytes: self.tab.Bytes, Pos: self.tab.Pos + o)))
proc TestMutatingBoolStart*(builder: var Builder) =
builder.StartObject(1)
proc TestMutatingBoolAddb*(builder: var Builder, b: uoffset) =
builder.PrependStructSlot(0, b, default(uoffset))
proc TestMutatingBoolEnd*(builder: var Builder): uoffset =
return builder.EndObject()

View File

@ -3438,7 +3438,7 @@ table (reflection.Type):
+0x1F5A | 0E | uint8_t | 0x0E (14) | table field `base_type` (Byte)
+0x1F5B | 0F | uint8_t | 0x0F (15) | table field `element` (Byte)
+0x1F5C | 00 00 00 00 | uint32_t | 0x00000000 (0) | table field `index` (Int)
+0x1F60 | 04 00 00 00 | uint32_t | 0x00000004 (4) | table field `element_size` (UInt)
+0x1F60 | 08 00 00 00 | uint32_t | 0x00000008 (8) | table field `element_size` (UInt)
string (reflection.Field.name):
+0x1F64 | 17 00 00 00 | uint32_t | 0x00000017 (23) | length of string

Binary file not shown.

View File

@ -421,7 +421,7 @@ struct MonsterBinarySchema {
0x1D,0x00,0x3E,0x00,0x48,0x00,0x00,0x00,0x34,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xD4,0xE9,0xFF,0xFF,0x10,0x00,0x00,0x00,
0x04,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x32,0x39,0x00,0x00,0x02,0x00,0x00,0x00,0x69,0x64,0x00,0x00,
0xA4,0xF5,0xFF,0xFF,0x00,0x00,0x0E,0x0F,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
0xA4,0xF5,0xFF,0xFF,0x00,0x00,0x0E,0x0F,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x17,0x00,0x00,0x00,
0x74,0x65,0x73,0x74,0x61,0x72,0x72,0x61,0x79,0x6F,0x66,0x73,0x6F,0x72,0x74,0x65,0x64,0x73,0x74,0x72,
0x75,0x63,0x74,0x00,0x5C,0xF4,0xFF,0xFF,0x00,0x00,0x00,0x01,0x1C,0x00,0x3C,0x00,0x44,0x00,0x00,0x00,
0x34,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,

22
tests/nim/testnim.py Normal file
View File

@ -0,0 +1,22 @@
import glob
import os
import shutil
import subprocess
from pathlib import Path
test_nim_dir = Path(__file__).absolute().parent
test_dir = test_nim_dir.parent
def main():
try:
subprocess.check_call("testament --megatest:off all".split())
finally:
shutil.rmtree(test_nim_dir / "nimcache")
shutil.rmtree(test_nim_dir / "testresults")
for f in glob.glob(str(test_nim_dir / "tests" / "*" / "test")):
os.remove(f)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,27 @@
discard """
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/unittest
import flatbuffers
import ../../../MoreDefaults
suite "TestMoreDefaults":
test "testFlatbuffersObject":
var fbb = newBuilder(0)
fbb.MoreDefaultsStart()
let root = fbb.MoreDefaultsEnd()
fbb.Finish(root)
var defaults: MoreDefaults
defaults.GetRootAs(fbb.FinishedBytes(), 0)
check(defaults.emptyString == "")
check(defaults.ints == [])
check(defaults.floats == [])
check(defaults.bools == [])
check(defaults.intsLength == 0)
check(defaults.floatsLength == 0)
check(defaults.abcsLength == 0)
check(defaults.boolsLength == 0)

View File

@ -0,0 +1,39 @@
discard """
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/unittest
import std/options
import flatbuffers
import ../../../TestMutatingBool
import ../../../Property
suite "TestMutatingBool":
test "MutatingBool":
var builder = newBuilder(1024)
builder.TestMutatingBoolStart()
builder.TestMutatingBoolAddB(builder.PropertyCreate(false))
let root = builder.TestMutatingBoolEnd()
builder.Finish(root)
var test_mutating_bool: TestMutatingBool
GetRootAs(test_mutating_bool, builder.FinishedBytes(), 0)
check(test_mutating_bool.b.isSome)
var prop2 = test_mutating_bool.b.get()
check(prop2.property == false)
discard (prop2.property = false)
check(prop2.property == false)
discard (prop2.property = true)
check(prop2.property == true)
test "EmptyBool":
var builder = newBuilder(1024)
builder.TestMutatingBoolStart()
let root = builder.TestMutatingBoolEnd()
builder.Finish(root)
var test_mutating_bool: TestMutatingBool
GetRootAs(test_mutating_bool, builder.FinishedBytes(), 0)
check(test_mutating_bool.b.isNone)

View File

@ -0,0 +1,207 @@
discard """
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/unittest
import std/options
import flatbuffers
import ../../../MyGame/Example/Test
import ../../../MyGame/Example/Monster
import ../../../MyGame/Example/Vec3
import ../../../MyGame/Example/Color as ColorMod
import ../../../MyGame/Example/Any as AnyMod
proc verifyMonster(monster: var Monster) =
check(monster.hp == 80)
check(monster.mana == 150)
check(monster.name == "MyMonster")
check(monster.pos.isSome)
let pos = monster.pos.get()
check(pos.x == 1)
check(pos.y == 2)
check(pos.z == 3)
check(pos.test1 == 3)
check(pos.test2 == Color.Green)
check(pos.test3.a == 5)
check(pos.test3.b == 6)
check(monster.testType == Any.Monster)
check(monster.test.isSome)
let monster2 = Monster(tab: monster.test.get())
check(monster2.name == "Fred")
check((monster.mana = 10) == false)
check(monster.mana == 150)
check(monster.inventoryLength == 5)
var sum: uint8 = 0
for item in monster.inventory:
sum += item
check(sum == 10)
check(monster.test4Length == 2)
let test0 = monster.test4(0)
let test1 = monster.test4(1)
var sum0 = test0.a + test0.b
var sum1 = test1.a + test1.b
check(sum0 + sum1 == 100)
check(monster.testarrayofstringLength == 2)
check(monster.testarrayofstring(0) == "test1")
check(monster.testarrayofstring(1) == "test2")
check(monster.testbool == true)
suite "TestMyGame":
test "testData":
let data: seq[byte] = @[byte(48), 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36,
0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0,
16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0,
0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0,
0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0,
64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152,
255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5,
0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0,
0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121,
77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36,
0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255,
255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28,
0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97,
114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]
var monster: Monster
GetRootAs(monster, data, 0)
verifyMonster(monster)
test "testCreateString":
var fbb = newBuilder(0)
let name = fbb.Create("Frodo")
fbb.Finish(name)
check(fbb.FinishedBytes() == @[byte(4), 0, 0, 0, 5, 0, 0, 0, 70, 114, 111,
100, 111, 0, 0, 0])
test "testCreateVector":
var fbb = newBuilder(0)
let vec = fbb.Create(@[byte(0), 1, 2, 3, 4])
fbb.Finish(vec)
check(fbb.FinishedBytes() == @[byte(4), 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4,
0, 0, 0])
test "createSimpleMonster":
var fbb = newBuilder(0)
let names = [
fbb.Create("Frodo"),
fbb.Create("Barney"),
fbb.Create("Wilma"),
]
fbb.MonsterStart()
fbb.MonsterAddName(names[0])
let monster = fbb.MonsterEnd()
fbb.Finish(monster)
check(fbb.FinishedBytes() == @[byte(16), 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0,
0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97,
0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70,
114, 111, 100, 111, 0, 0, 0])
test "testCreateTestVector":
var fbb = newBuilder(0)
fbb.MonsterStartTest4Vector(2)
discard fbb.TestCreate(a = 30, b = 40)
discard fbb.TestCreate(a = 10, b = 20)
let test4 = fbb.EndVector()
fbb.Finish(test4)
check(fbb.FinishedBytes() == @[byte(4), 0, 0, 0, 2, 0, 0, 0, 10, 0, 20, 0,
30, 0, 40, 0])
test "testTableWithStruct":
var fbb = newBuilder(0)
fbb.MonsterStart()
fbb.MonsterAddPos(fbb.Vec3Create(x = 1,
y = 2,
z = 3,
test1 = 3,
test2 = Color.Green,
test3_a = 5, test3_b = 6))
let monster_end = fbb.MonsterEnd()
fbb.Finish(monster_end)
check(fbb.FinishedBytes() == @[byte(12), 0, 0, 0, 0, 0, 6, 0, 36, 0, 4, 0,
6, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0])
test "testCreateMonster":
var fbb = newBuilder(0)
let names = [
fbb.Create("Frodo"),
fbb.Create("Barney"),
fbb.Create("Wilma"),
]
var offsets: seq[uoffset] = @[]
fbb.MonsterStart()
fbb.MonsterAddName(names[0])
offsets.add(fbb.MonsterEnd())
fbb.MonsterStart()
fbb.MonsterAddName(names[1])
offsets.add(fbb.MonsterEnd())
fbb.MonsterStart()
fbb.MonsterAddName(names[2])
offsets.add(fbb.MonsterEnd())
let str = fbb.Create("MyMonster")
let test1 = fbb.Create("test1")
let test2 = fbb.Create("test2")
let inv = fbb.Create(@[byte(0), 1, 2, 3, 4])
let fred = fbb.Create("Fred")
fbb.MonsterStart()
fbb.MonsterAddName(fred)
let mon2 = fbb.MonsterEnd()
fbb.MonsterStartTest4Vector(2)
discard fbb.TestCreate(a = 30, b = 40)
discard fbb.TestCreate(a = 10, b = 20)
let test4 = fbb.EndVector()
fbb.MonsterStartTestarrayofstringVector(2)
fbb.PrependOffsetRelative(test1)
fbb.PrependOffsetRelative(test2)
let stringTestVector = fbb.EndVector()
fbb.MonsterStartTestarrayoftablesVector(3)
fbb.PrependOffsetRelative(offsets[0])
fbb.PrependOffsetRelative(offsets[1])
fbb.PrependOffsetRelative(offsets[2])
let tableTestVector = fbb.EndVector()
fbb.MonsterStart()
fbb.MonsterAddPos(fbb.Vec3Create(x = 1,
y = 2,
z = 3,
test1 = 3,
test2 = Color.Green,
test3_a = 5, test3_b = 6))
fbb.MonsterAddHp(80)
fbb.MonsterAddName(str)
fbb.MonsterAddInventory(inv)
fbb.MonsterAddTestType(Any.Monster.uint8)
fbb.MonsterAddTest(mon2)
fbb.MonsterAddTest4(test4)
fbb.MonsterAddTestarrayofstring(stringTestVector)
fbb.MonsterAddTestbool(true)
fbb.MonsterAddTestarrayoftables(tableTestVector)
let monster_end = fbb.MonsterEnd()
fbb.Finish(monster_end)
check(fbb.FinishedBytes() == @[byte(40), 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0,
38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0,
0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 1, 76, 0, 0, 0,
84, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 1, 104, 0, 0, 0, 136, 0, 0, 0, 0, 0,
80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 3, 0, 0, 0, 108, 0, 0, 0, 112, 0,
0, 0, 128, 0, 0, 0, 2, 0, 0, 0, 52, 0, 0, 0, 60, 0, 0, 0, 2, 0, 0, 0,
10, 0, 20, 0, 30, 0, 40, 0, 168, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0,
70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0,
0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116,
49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0,
0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0,
12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0,
0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101,
121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])

View File

@ -0,0 +1,29 @@
discard """
action: "run"
exitcode: 0
timeout: 60.0
"""
import std/unittest
import std/options
import flatbuffers
import ../../../optional_scalars/ScalarStuff
suite "TestOptionalScalars":
test "OptionalScalars":
var builder = newBuilder(1024)
builder.ScalarStuffStart()
let root = builder.ScalarStuffEnd()
builder.Finish(root)
var optionals: ScalarStuff
optionals.GetRootAs(builder.FinishedBytes(), 0)
# Creates a flatbuffer with optional values.
check(optionals.justI8 == 0)
check(optionals.maybeF32.isNone)
check(optionals.defaultBool == true)
check(optionals.justU16 == 0)
check(optionals.maybeEnum.isNone)
check(optionals.defaultU64 == 42)

View File

@ -0,0 +1,14 @@
#[ optional_scalars.OptionalByte
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : optional_scalars.ScalarStuff ()
]#
type OptionalByte*{.pure.} = enum
None = 0.int8,
One = 1.int8,
Two = 2.int8,

View File

@ -0,0 +1,331 @@
#[ optional_scalars.ScalarStuff
Automatically generated by the FlatBuffers compiler, do not modify.
Or modify. I'm a message, not a cop.
flatc version: 22.9.29
Declared by :
Rooting type : optional_scalars.ScalarStuff ()
]#
import OptionalByte as optional_scalars_OptionalByte
import flatbuffers
import std/options
type ScalarStuff* = object of FlatObj
func justI8*(self: ScalarStuff): int8 =
let o = self.tab.Offset(4)
if o != 0:
return Get[int8](self.tab, self.tab.Pos + o)
return 0
func `justI8=`*(self: var ScalarStuff, n: int8): bool =
return self.tab.MutateSlot(4, n)
func maybeI8*(self: ScalarStuff): Option[int8] =
let o = self.tab.Offset(6)
if o != 0:
return some(Get[int8](self.tab, self.tab.Pos + o))
func `maybeI8=`*(self: var ScalarStuff, n: Option[int8]): bool =
return self.tab.MutateSlot(6, n)
func defaultI8*(self: ScalarStuff): int8 =
let o = self.tab.Offset(8)
if o != 0:
return Get[int8](self.tab, self.tab.Pos + o)
return 42
func `defaultI8=`*(self: var ScalarStuff, n: int8): bool =
return self.tab.MutateSlot(8, n)
func justU8*(self: ScalarStuff): uint8 =
let o = self.tab.Offset(10)
if o != 0:
return Get[uint8](self.tab, self.tab.Pos + o)
return 0
func `justU8=`*(self: var ScalarStuff, n: uint8): bool =
return self.tab.MutateSlot(10, n)
func maybeU8*(self: ScalarStuff): Option[uint8] =
let o = self.tab.Offset(12)
if o != 0:
return some(Get[uint8](self.tab, self.tab.Pos + o))
func `maybeU8=`*(self: var ScalarStuff, n: Option[uint8]): bool =
return self.tab.MutateSlot(12, n)
func defaultU8*(self: ScalarStuff): uint8 =
let o = self.tab.Offset(14)
if o != 0:
return Get[uint8](self.tab, self.tab.Pos + o)
return 42
func `defaultU8=`*(self: var ScalarStuff, n: uint8): bool =
return self.tab.MutateSlot(14, n)
func justI16*(self: ScalarStuff): int16 =
let o = self.tab.Offset(16)
if o != 0:
return Get[int16](self.tab, self.tab.Pos + o)
return 0
func `justI16=`*(self: var ScalarStuff, n: int16): bool =
return self.tab.MutateSlot(16, n)
func maybeI16*(self: ScalarStuff): Option[int16] =
let o = self.tab.Offset(18)
if o != 0:
return some(Get[int16](self.tab, self.tab.Pos + o))
func `maybeI16=`*(self: var ScalarStuff, n: Option[int16]): bool =
return self.tab.MutateSlot(18, n)
func defaultI16*(self: ScalarStuff): int16 =
let o = self.tab.Offset(20)
if o != 0:
return Get[int16](self.tab, self.tab.Pos + o)
return 42
func `defaultI16=`*(self: var ScalarStuff, n: int16): bool =
return self.tab.MutateSlot(20, n)
func justU16*(self: ScalarStuff): uint16 =
let o = self.tab.Offset(22)
if o != 0:
return Get[uint16](self.tab, self.tab.Pos + o)
return 0
func `justU16=`*(self: var ScalarStuff, n: uint16): bool =
return self.tab.MutateSlot(22, n)
func maybeU16*(self: ScalarStuff): Option[uint16] =
let o = self.tab.Offset(24)
if o != 0:
return some(Get[uint16](self.tab, self.tab.Pos + o))
func `maybeU16=`*(self: var ScalarStuff, n: Option[uint16]): bool =
return self.tab.MutateSlot(24, n)
func defaultU16*(self: ScalarStuff): uint16 =
let o = self.tab.Offset(26)
if o != 0:
return Get[uint16](self.tab, self.tab.Pos + o)
return 42
func `defaultU16=`*(self: var ScalarStuff, n: uint16): bool =
return self.tab.MutateSlot(26, n)
func justI32*(self: ScalarStuff): int32 =
let o = self.tab.Offset(28)
if o != 0:
return Get[int32](self.tab, self.tab.Pos + o)
return 0
func `justI32=`*(self: var ScalarStuff, n: int32): bool =
return self.tab.MutateSlot(28, n)
func maybeI32*(self: ScalarStuff): Option[int32] =
let o = self.tab.Offset(30)
if o != 0:
return some(Get[int32](self.tab, self.tab.Pos + o))
func `maybeI32=`*(self: var ScalarStuff, n: Option[int32]): bool =
return self.tab.MutateSlot(30, n)
func defaultI32*(self: ScalarStuff): int32 =
let o = self.tab.Offset(32)
if o != 0:
return Get[int32](self.tab, self.tab.Pos + o)
return 42
func `defaultI32=`*(self: var ScalarStuff, n: int32): bool =
return self.tab.MutateSlot(32, n)
func justU32*(self: ScalarStuff): uint32 =
let o = self.tab.Offset(34)
if o != 0:
return Get[uint32](self.tab, self.tab.Pos + o)
return 0
func `justU32=`*(self: var ScalarStuff, n: uint32): bool =
return self.tab.MutateSlot(34, n)
func maybeU32*(self: ScalarStuff): Option[uint32] =
let o = self.tab.Offset(36)
if o != 0:
return some(Get[uint32](self.tab, self.tab.Pos + o))
func `maybeU32=`*(self: var ScalarStuff, n: Option[uint32]): bool =
return self.tab.MutateSlot(36, n)
func defaultU32*(self: ScalarStuff): uint32 =
let o = self.tab.Offset(38)
if o != 0:
return Get[uint32](self.tab, self.tab.Pos + o)
return 42
func `defaultU32=`*(self: var ScalarStuff, n: uint32): bool =
return self.tab.MutateSlot(38, n)
func justI64*(self: ScalarStuff): int64 =
let o = self.tab.Offset(40)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 0
func `justI64=`*(self: var ScalarStuff, n: int64): bool =
return self.tab.MutateSlot(40, n)
func maybeI64*(self: ScalarStuff): Option[int64] =
let o = self.tab.Offset(42)
if o != 0:
return some(Get[int64](self.tab, self.tab.Pos + o))
func `maybeI64=`*(self: var ScalarStuff, n: Option[int64]): bool =
return self.tab.MutateSlot(42, n)
func defaultI64*(self: ScalarStuff): int64 =
let o = self.tab.Offset(44)
if o != 0:
return Get[int64](self.tab, self.tab.Pos + o)
return 42
func `defaultI64=`*(self: var ScalarStuff, n: int64): bool =
return self.tab.MutateSlot(44, n)
func justU64*(self: ScalarStuff): uint64 =
let o = self.tab.Offset(46)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 0
func `justU64=`*(self: var ScalarStuff, n: uint64): bool =
return self.tab.MutateSlot(46, n)
func maybeU64*(self: ScalarStuff): Option[uint64] =
let o = self.tab.Offset(48)
if o != 0:
return some(Get[uint64](self.tab, self.tab.Pos + o))
func `maybeU64=`*(self: var ScalarStuff, n: Option[uint64]): bool =
return self.tab.MutateSlot(48, n)
func defaultU64*(self: ScalarStuff): uint64 =
let o = self.tab.Offset(50)
if o != 0:
return Get[uint64](self.tab, self.tab.Pos + o)
return 42
func `defaultU64=`*(self: var ScalarStuff, n: uint64): bool =
return self.tab.MutateSlot(50, n)
func justF32*(self: ScalarStuff): float32 =
let o = self.tab.Offset(52)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 0.0
func `justF32=`*(self: var ScalarStuff, n: float32): bool =
return self.tab.MutateSlot(52, n)
func maybeF32*(self: ScalarStuff): Option[float32] =
let o = self.tab.Offset(54)
if o != 0:
return some(Get[float32](self.tab, self.tab.Pos + o))
func `maybeF32=`*(self: var ScalarStuff, n: Option[float32]): bool =
return self.tab.MutateSlot(54, n)
func defaultF32*(self: ScalarStuff): float32 =
let o = self.tab.Offset(56)
if o != 0:
return Get[float32](self.tab, self.tab.Pos + o)
return 42.0
func `defaultF32=`*(self: var ScalarStuff, n: float32): bool =
return self.tab.MutateSlot(56, n)
func justF64*(self: ScalarStuff): float64 =
let o = self.tab.Offset(58)
if o != 0:
return Get[float64](self.tab, self.tab.Pos + o)
return 0.0
func `justF64=`*(self: var ScalarStuff, n: float64): bool =
return self.tab.MutateSlot(58, n)
func maybeF64*(self: ScalarStuff): Option[float64] =
let o = self.tab.Offset(60)
if o != 0:
return some(Get[float64](self.tab, self.tab.Pos + o))
func `maybeF64=`*(self: var ScalarStuff, n: Option[float64]): bool =
return self.tab.MutateSlot(60, n)
func defaultF64*(self: ScalarStuff): float64 =
let o = self.tab.Offset(62)
if o != 0:
return Get[float64](self.tab, self.tab.Pos + o)
return 42.0
func `defaultF64=`*(self: var ScalarStuff, n: float64): bool =
return self.tab.MutateSlot(62, n)
func justBool*(self: ScalarStuff): bool =
let o = self.tab.Offset(64)
if o != 0:
return Get[bool](self.tab, self.tab.Pos + o)
return false
func `justBool=`*(self: var ScalarStuff, n: bool): bool =
return self.tab.MutateSlot(64, n)
func maybeBool*(self: ScalarStuff): Option[bool] =
let o = self.tab.Offset(66)
if o != 0:
return some(Get[bool](self.tab, self.tab.Pos + o))
func `maybeBool=`*(self: var ScalarStuff, n: Option[bool]): bool =
return self.tab.MutateSlot(66, n)
func defaultBool*(self: ScalarStuff): bool =
let o = self.tab.Offset(68)
if o != 0:
return Get[bool](self.tab, self.tab.Pos + o)
return true
func `defaultBool=`*(self: var ScalarStuff, n: bool): bool =
return self.tab.MutateSlot(68, n)
func justEnum*(self: ScalarStuff): optional_scalars_OptionalByte.OptionalByte =
let o = self.tab.Offset(70)
if o != 0:
return optional_scalars_OptionalByte.OptionalByte(Get[int8](self.tab, self.tab.Pos + o))
return type(result)(0)
func `justEnum=`*(self: var ScalarStuff, n: optional_scalars_OptionalByte.OptionalByte): bool =
return self.tab.MutateSlot(70, n)
func maybeEnum*(self: ScalarStuff): Option[optional_scalars_OptionalByte.OptionalByte] =
let o = self.tab.Offset(72)
if o != 0:
return some(optional_scalars_OptionalByte.OptionalByte(Get[int8](self.tab, self.tab.Pos + o)))
func `maybeEnum=`*(self: var ScalarStuff, n: Option[optional_scalars_OptionalByte.OptionalByte]): bool =
return self.tab.MutateSlot(72, n)
func defaultEnum*(self: ScalarStuff): optional_scalars_OptionalByte.OptionalByte =
let o = self.tab.Offset(74)
if o != 0:
return optional_scalars_OptionalByte.OptionalByte(Get[int8](self.tab, self.tab.Pos + o))
return type(result)(1)
func `defaultEnum=`*(self: var ScalarStuff, n: optional_scalars_OptionalByte.OptionalByte): bool =
return self.tab.MutateSlot(74, n)
proc ScalarStuffStart*(builder: var Builder) =
builder.StartObject(36)
proc ScalarStuffAddjustI8*(builder: var Builder, justI8: int8) =
builder.PrependSlot(0, justI8, default(int8))
proc ScalarStuffAddmaybeI8*(builder: var Builder, maybeI8: int8) =
builder.PrependSlot(1, maybeI8, default(int8))
proc ScalarStuffAdddefaultI8*(builder: var Builder, defaultI8: int8) =
builder.PrependSlot(2, defaultI8, default(int8))
proc ScalarStuffAddjustU8*(builder: var Builder, justU8: uint8) =
builder.PrependSlot(3, justU8, default(uint8))
proc ScalarStuffAddmaybeU8*(builder: var Builder, maybeU8: uint8) =
builder.PrependSlot(4, maybeU8, default(uint8))
proc ScalarStuffAdddefaultU8*(builder: var Builder, defaultU8: uint8) =
builder.PrependSlot(5, defaultU8, default(uint8))
proc ScalarStuffAddjustI16*(builder: var Builder, justI16: int16) =
builder.PrependSlot(6, justI16, default(int16))
proc ScalarStuffAddmaybeI16*(builder: var Builder, maybeI16: int16) =
builder.PrependSlot(7, maybeI16, default(int16))
proc ScalarStuffAdddefaultI16*(builder: var Builder, defaultI16: int16) =
builder.PrependSlot(8, defaultI16, default(int16))
proc ScalarStuffAddjustU16*(builder: var Builder, justU16: uint16) =
builder.PrependSlot(9, justU16, default(uint16))
proc ScalarStuffAddmaybeU16*(builder: var Builder, maybeU16: uint16) =
builder.PrependSlot(10, maybeU16, default(uint16))
proc ScalarStuffAdddefaultU16*(builder: var Builder, defaultU16: uint16) =
builder.PrependSlot(11, defaultU16, default(uint16))
proc ScalarStuffAddjustI32*(builder: var Builder, justI32: int32) =
builder.PrependSlot(12, justI32, default(int32))
proc ScalarStuffAddmaybeI32*(builder: var Builder, maybeI32: int32) =
builder.PrependSlot(13, maybeI32, default(int32))
proc ScalarStuffAdddefaultI32*(builder: var Builder, defaultI32: int32) =
builder.PrependSlot(14, defaultI32, default(int32))
proc ScalarStuffAddjustU32*(builder: var Builder, justU32: uint32) =
builder.PrependSlot(15, justU32, default(uint32))
proc ScalarStuffAddmaybeU32*(builder: var Builder, maybeU32: uint32) =
builder.PrependSlot(16, maybeU32, default(uint32))
proc ScalarStuffAdddefaultU32*(builder: var Builder, defaultU32: uint32) =
builder.PrependSlot(17, defaultU32, default(uint32))
proc ScalarStuffAddjustI64*(builder: var Builder, justI64: int64) =
builder.PrependSlot(18, justI64, default(int64))
proc ScalarStuffAddmaybeI64*(builder: var Builder, maybeI64: int64) =
builder.PrependSlot(19, maybeI64, default(int64))
proc ScalarStuffAdddefaultI64*(builder: var Builder, defaultI64: int64) =
builder.PrependSlot(20, defaultI64, default(int64))
proc ScalarStuffAddjustU64*(builder: var Builder, justU64: uint64) =
builder.PrependSlot(21, justU64, default(uint64))
proc ScalarStuffAddmaybeU64*(builder: var Builder, maybeU64: uint64) =
builder.PrependSlot(22, maybeU64, default(uint64))
proc ScalarStuffAdddefaultU64*(builder: var Builder, defaultU64: uint64) =
builder.PrependSlot(23, defaultU64, default(uint64))
proc ScalarStuffAddjustF32*(builder: var Builder, justF32: float32) =
builder.PrependSlot(24, justF32, default(float32))
proc ScalarStuffAddmaybeF32*(builder: var Builder, maybeF32: float32) =
builder.PrependSlot(25, maybeF32, default(float32))
proc ScalarStuffAdddefaultF32*(builder: var Builder, defaultF32: float32) =
builder.PrependSlot(26, defaultF32, default(float32))
proc ScalarStuffAddjustF64*(builder: var Builder, justF64: float64) =
builder.PrependSlot(27, justF64, default(float64))
proc ScalarStuffAddmaybeF64*(builder: var Builder, maybeF64: float64) =
builder.PrependSlot(28, maybeF64, default(float64))
proc ScalarStuffAdddefaultF64*(builder: var Builder, defaultF64: float64) =
builder.PrependSlot(29, defaultF64, default(float64))
proc ScalarStuffAddjustBool*(builder: var Builder, justBool: bool) =
builder.PrependSlot(30, justBool, default(bool))
proc ScalarStuffAddmaybeBool*(builder: var Builder, maybeBool: bool) =
builder.PrependSlot(31, maybeBool, default(bool))
proc ScalarStuffAdddefaultBool*(builder: var Builder, defaultBool: bool) =
builder.PrependSlot(32, defaultBool, default(bool))
proc ScalarStuffAddjustEnum*(builder: var Builder, justEnum: int8) =
builder.PrependSlot(33, justEnum, default(int8))
proc ScalarStuffAddmaybeEnum*(builder: var Builder, maybeEnum: int8) =
builder.PrependSlot(34, maybeEnum, default(int8))
proc ScalarStuffAdddefaultEnum*(builder: var Builder, defaultEnum: int8) =
builder.PrependSlot(35, defaultEnum, default(int8))
proc ScalarStuffEnd*(builder: var Builder): uoffset =
return builder.EndObject()