From 56ecc1f548f4bb4143b7a01db9b01d331e468977 Mon Sep 17 00:00:00 2001 From: Max Burke Date: Tue, 25 Apr 2023 21:38:16 -0700 Subject: [PATCH] Optionally generate type prefixes and suffixes for python code (#7857) * optionally generate type prefixes and suffixes for python code * fix codegen error when qualified name is empty * generated code updated --- .../python/greeter/models/HelloReply.py | 16 +- .../python/greeter/models/HelloRequest.py | 16 +- include/flatbuffers/idl.h | 2 + python/flatbuffers/reflection/Enum.py | 61 ++- python/flatbuffers/reflection/EnumVal.py | 46 +- python/flatbuffers/reflection/Field.py | 86 +++- python/flatbuffers/reflection/KeyValue.py | 21 +- python/flatbuffers/reflection/Object.py | 66 ++- python/flatbuffers/reflection/RPCCall.py | 46 +- python/flatbuffers/reflection/Schema.py | 71 ++- python/flatbuffers/reflection/SchemaFile.py | 26 +- python/flatbuffers/reflection/Service.py | 51 +- python/flatbuffers/reflection/Type.py | 41 +- src/flatc.cpp | 6 +- src/idl_gen_python.cpp | 71 +-- tests/MyGame/Example/ArrayTable.py | 15 +- tests/MyGame/Example/Monster.py | 419 ++++++++++++---- .../Example/NestedUnion/NestedUnionTest.py | 30 +- .../NestedUnion/TestSimpleTableWithEnum.py | 15 +- tests/MyGame/Example/NestedUnion/Vec3.py | 40 +- tests/MyGame/Example/Referrable.py | 15 +- tests/MyGame/Example/Stat.py | 25 +- .../MyGame/Example/TestSimpleTableWithEnum.py | 15 +- tests/MyGame/Example/TypeAliases.py | 80 ++- tests/MyGame/Example2/Monster.py | 10 +- tests/MyGame/InParentNamespace.py | 10 +- tests/MyGame/MonsterExtra.py | 70 ++- tests/monster_test_generated.py | 460 +++++++++++++----- tests/optional_scalars/ScalarStuff.py | 190 ++++++-- 29 files changed, 1567 insertions(+), 453 deletions(-) diff --git a/grpc/examples/python/greeter/models/HelloReply.py b/grpc/examples/python/greeter/models/HelloReply.py index 301c84d9c526..f1082fa23e78 100644 --- a/grpc/examples/python/greeter/models/HelloReply.py +++ b/grpc/examples/python/greeter/models/HelloReply.py @@ -31,12 +31,20 @@ def Message(self): return self._tab.String(o + self._tab.Pos) return None -def HelloReplyStart(builder): builder.StartObject(1) +def HelloReplyStart(builder): + return builder.StartObject(1) + def Start(builder): return HelloReplyStart(builder) -def HelloReplyAddMessage(builder, message): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0) + +def HelloReplyAddMessage(builder, message): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0) + def AddMessage(builder, message): return HelloReplyAddMessage(builder, message) -def HelloReplyEnd(builder): return builder.EndObject() + +def HelloReplyEnd(builder): + return builder.EndObject() + def End(builder): - return HelloReplyEnd(builder) \ No newline at end of file + return HelloReplyEnd(builder) diff --git a/grpc/examples/python/greeter/models/HelloRequest.py b/grpc/examples/python/greeter/models/HelloRequest.py index 122568fd21e1..b295369e6481 100644 --- a/grpc/examples/python/greeter/models/HelloRequest.py +++ b/grpc/examples/python/greeter/models/HelloRequest.py @@ -31,12 +31,20 @@ def Name(self): return self._tab.String(o + self._tab.Pos) return None -def HelloRequestStart(builder): builder.StartObject(1) +def HelloRequestStart(builder): + return builder.StartObject(1) + def Start(builder): return HelloRequestStart(builder) -def HelloRequestAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def HelloRequestAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return HelloRequestAddName(builder, name) -def HelloRequestEnd(builder): return builder.EndObject() + +def HelloRequestEnd(builder): + return builder.EndObject() + def End(builder): - return HelloRequestEnd(builder) \ No newline at end of file + return HelloRequestEnd(builder) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 8f08003d2c0b..bee67274048f 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -697,6 +697,7 @@ struct IDLOptions { bool no_leak_private_annotations; bool require_json_eof; bool keep_proto_id; + bool python_no_type_prefix_suffix; ProtoIdGapAction proto_id_gap_action; // Possible options for the more general generator below. @@ -806,6 +807,7 @@ struct IDLOptions { no_leak_private_annotations(false), require_json_eof(true), keep_proto_id(false), + python_no_type_prefix_suffix(false), proto_id_gap_action(ProtoIdGapAction::WARNING), mini_reflect(IDLOptions::kNone), require_explicit_ids(false), diff --git a/python/flatbuffers/reflection/Enum.py b/python/flatbuffers/reflection/Enum.py index b27e4102c21b..bd2a7b336378 100644 --- a/python/flatbuffers/reflection/Enum.py +++ b/python/flatbuffers/reflection/Enum.py @@ -131,39 +131,74 @@ def DeclarationFile(self): return self._tab.String(o + self._tab.Pos) return None -def EnumStart(builder): builder.StartObject(7) +def EnumStart(builder): + return builder.StartObject(7) + def Start(builder): return EnumStart(builder) -def EnumAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def EnumAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return EnumAddName(builder, name) -def EnumAddValues(builder, values): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(values), 0) + +def EnumAddValues(builder, values): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(values), 0) + def AddValues(builder, values): return EnumAddValues(builder, values) -def EnumStartValuesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def EnumStartValuesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartValuesVector(builder, numElems): return EnumStartValuesVector(builder, numElems) -def EnumAddIsUnion(builder, isUnion): builder.PrependBoolSlot(2, isUnion, 0) + +def EnumAddIsUnion(builder, isUnion): + return builder.PrependBoolSlot(2, isUnion, 0) + def AddIsUnion(builder, isUnion): return EnumAddIsUnion(builder, isUnion) -def EnumAddUnderlyingType(builder, underlyingType): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(underlyingType), 0) + +def EnumAddUnderlyingType(builder, underlyingType): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(underlyingType), 0) + def AddUnderlyingType(builder, underlyingType): return EnumAddUnderlyingType(builder, underlyingType) -def EnumAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def EnumAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return EnumAddAttributes(builder, attributes) -def EnumStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def EnumStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return EnumStartAttributesVector(builder, numElems) -def EnumAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def EnumAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return EnumAddDocumentation(builder, documentation) -def EnumStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def EnumStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return EnumStartDocumentationVector(builder, numElems) -def EnumAddDeclarationFile(builder, declarationFile): builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + +def EnumAddDeclarationFile(builder, declarationFile): + return builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + def AddDeclarationFile(builder, declarationFile): return EnumAddDeclarationFile(builder, declarationFile) -def EnumEnd(builder): return builder.EndObject() + +def EnumEnd(builder): + return builder.EndObject() + def End(builder): - return EnumEnd(builder) \ No newline at end of file + return EnumEnd(builder) diff --git a/python/flatbuffers/reflection/EnumVal.py b/python/flatbuffers/reflection/EnumVal.py index 3592de08c437..7019ec46d5b9 100644 --- a/python/flatbuffers/reflection/EnumVal.py +++ b/python/flatbuffers/reflection/EnumVal.py @@ -98,30 +98,56 @@ def AttributesIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) return o == 0 -def EnumValStart(builder): builder.StartObject(6) +def EnumValStart(builder): + return builder.StartObject(6) + def Start(builder): return EnumValStart(builder) -def EnumValAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def EnumValAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return EnumValAddName(builder, name) -def EnumValAddValue(builder, value): builder.PrependInt64Slot(1, value, 0) + +def EnumValAddValue(builder, value): + return builder.PrependInt64Slot(1, value, 0) + def AddValue(builder, value): return EnumValAddValue(builder, value) -def EnumValAddUnionType(builder, unionType): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(unionType), 0) + +def EnumValAddUnionType(builder, unionType): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(unionType), 0) + def AddUnionType(builder, unionType): return EnumValAddUnionType(builder, unionType) -def EnumValAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def EnumValAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return EnumValAddDocumentation(builder, documentation) -def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def EnumValStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return EnumValStartDocumentationVector(builder, numElems) -def EnumValAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def EnumValAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return EnumValAddAttributes(builder, attributes) -def EnumValStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def EnumValStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return EnumValStartAttributesVector(builder, numElems) -def EnumValEnd(builder): return builder.EndObject() + +def EnumValEnd(builder): + return builder.EndObject() + def End(builder): - return EnumValEnd(builder) \ No newline at end of file + return EnumValEnd(builder) diff --git a/python/flatbuffers/reflection/Field.py b/python/flatbuffers/reflection/Field.py index 01b52808a1fa..a0e660fd666a 100644 --- a/python/flatbuffers/reflection/Field.py +++ b/python/flatbuffers/reflection/Field.py @@ -155,54 +155,104 @@ def Padding(self): return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) return 0 -def FieldStart(builder): builder.StartObject(13) +def FieldStart(builder): + return builder.StartObject(13) + def Start(builder): return FieldStart(builder) -def FieldAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def FieldAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return FieldAddName(builder, name) -def FieldAddType(builder, type): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(type), 0) + +def FieldAddType(builder, type): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(type), 0) + def AddType(builder, type): return FieldAddType(builder, type) -def FieldAddId(builder, id): builder.PrependUint16Slot(2, id, 0) + +def FieldAddId(builder, id): + return builder.PrependUint16Slot(2, id, 0) + def AddId(builder, id): return FieldAddId(builder, id) -def FieldAddOffset(builder, offset): builder.PrependUint16Slot(3, offset, 0) + +def FieldAddOffset(builder, offset): + return builder.PrependUint16Slot(3, offset, 0) + def AddOffset(builder, offset): return FieldAddOffset(builder, offset) -def FieldAddDefaultInteger(builder, defaultInteger): builder.PrependInt64Slot(4, defaultInteger, 0) + +def FieldAddDefaultInteger(builder, defaultInteger): + return builder.PrependInt64Slot(4, defaultInteger, 0) + def AddDefaultInteger(builder, defaultInteger): return FieldAddDefaultInteger(builder, defaultInteger) -def FieldAddDefaultReal(builder, defaultReal): builder.PrependFloat64Slot(5, defaultReal, 0.0) + +def FieldAddDefaultReal(builder, defaultReal): + return builder.PrependFloat64Slot(5, defaultReal, 0.0) + def AddDefaultReal(builder, defaultReal): return FieldAddDefaultReal(builder, defaultReal) -def FieldAddDeprecated(builder, deprecated): builder.PrependBoolSlot(6, deprecated, 0) + +def FieldAddDeprecated(builder, deprecated): + return builder.PrependBoolSlot(6, deprecated, 0) + def AddDeprecated(builder, deprecated): return FieldAddDeprecated(builder, deprecated) -def FieldAddRequired(builder, required): builder.PrependBoolSlot(7, required, 0) + +def FieldAddRequired(builder, required): + return builder.PrependBoolSlot(7, required, 0) + def AddRequired(builder, required): return FieldAddRequired(builder, required) -def FieldAddKey(builder, key): builder.PrependBoolSlot(8, key, 0) + +def FieldAddKey(builder, key): + return builder.PrependBoolSlot(8, key, 0) + def AddKey(builder, key): return FieldAddKey(builder, key) -def FieldAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def FieldAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return FieldAddAttributes(builder, attributes) -def FieldStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def FieldStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return FieldStartAttributesVector(builder, numElems) -def FieldAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def FieldAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return FieldAddDocumentation(builder, documentation) -def FieldStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def FieldStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return FieldStartDocumentationVector(builder, numElems) -def FieldAddOptional(builder, optional): builder.PrependBoolSlot(11, optional, 0) + +def FieldAddOptional(builder, optional): + return builder.PrependBoolSlot(11, optional, 0) + def AddOptional(builder, optional): return FieldAddOptional(builder, optional) -def FieldAddPadding(builder, padding): builder.PrependUint16Slot(12, padding, 0) + +def FieldAddPadding(builder, padding): + return builder.PrependUint16Slot(12, padding, 0) + def AddPadding(builder, padding): return FieldAddPadding(builder, padding) -def FieldEnd(builder): return builder.EndObject() + +def FieldEnd(builder): + return builder.EndObject() + def End(builder): - return FieldEnd(builder) \ No newline at end of file + return FieldEnd(builder) diff --git a/python/flatbuffers/reflection/KeyValue.py b/python/flatbuffers/reflection/KeyValue.py index dde37dff8a68..7b24a76e5197 100644 --- a/python/flatbuffers/reflection/KeyValue.py +++ b/python/flatbuffers/reflection/KeyValue.py @@ -42,15 +42,26 @@ def Value(self): return self._tab.String(o + self._tab.Pos) return None -def KeyValueStart(builder): builder.StartObject(2) +def KeyValueStart(builder): + return builder.StartObject(2) + def Start(builder): return KeyValueStart(builder) -def KeyValueAddKey(builder, key): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) + +def KeyValueAddKey(builder, key): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) + def AddKey(builder, key): return KeyValueAddKey(builder, key) -def KeyValueAddValue(builder, value): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) + +def KeyValueAddValue(builder, value): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) + def AddValue(builder, value): return KeyValueAddValue(builder, value) -def KeyValueEnd(builder): return builder.EndObject() + +def KeyValueEnd(builder): + return builder.EndObject() + def End(builder): - return KeyValueEnd(builder) \ No newline at end of file + return KeyValueEnd(builder) diff --git a/python/flatbuffers/reflection/Object.py b/python/flatbuffers/reflection/Object.py index 598927c8af61..f890ffbc1ee8 100644 --- a/python/flatbuffers/reflection/Object.py +++ b/python/flatbuffers/reflection/Object.py @@ -134,42 +134,80 @@ def DeclarationFile(self): return self._tab.String(o + self._tab.Pos) return None -def ObjectStart(builder): builder.StartObject(8) +def ObjectStart(builder): + return builder.StartObject(8) + def Start(builder): return ObjectStart(builder) -def ObjectAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def ObjectAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return ObjectAddName(builder, name) -def ObjectAddFields(builder, fields): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(fields), 0) + +def ObjectAddFields(builder, fields): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(fields), 0) + def AddFields(builder, fields): return ObjectAddFields(builder, fields) -def ObjectStartFieldsVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ObjectStartFieldsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartFieldsVector(builder, numElems): return ObjectStartFieldsVector(builder, numElems) -def ObjectAddIsStruct(builder, isStruct): builder.PrependBoolSlot(2, isStruct, 0) + +def ObjectAddIsStruct(builder, isStruct): + return builder.PrependBoolSlot(2, isStruct, 0) + def AddIsStruct(builder, isStruct): return ObjectAddIsStruct(builder, isStruct) -def ObjectAddMinalign(builder, minalign): builder.PrependInt32Slot(3, minalign, 0) + +def ObjectAddMinalign(builder, minalign): + return builder.PrependInt32Slot(3, minalign, 0) + def AddMinalign(builder, minalign): return ObjectAddMinalign(builder, minalign) -def ObjectAddBytesize(builder, bytesize): builder.PrependInt32Slot(4, bytesize, 0) + +def ObjectAddBytesize(builder, bytesize): + return builder.PrependInt32Slot(4, bytesize, 0) + def AddBytesize(builder, bytesize): return ObjectAddBytesize(builder, bytesize) -def ObjectAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def ObjectAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return ObjectAddAttributes(builder, attributes) -def ObjectStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ObjectStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return ObjectStartAttributesVector(builder, numElems) -def ObjectAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def ObjectAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return ObjectAddDocumentation(builder, documentation) -def ObjectStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ObjectStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return ObjectStartDocumentationVector(builder, numElems) -def ObjectAddDeclarationFile(builder, declarationFile): builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + +def ObjectAddDeclarationFile(builder, declarationFile): + return builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + def AddDeclarationFile(builder, declarationFile): return ObjectAddDeclarationFile(builder, declarationFile) -def ObjectEnd(builder): return builder.EndObject() + +def ObjectEnd(builder): + return builder.EndObject() + def End(builder): - return ObjectEnd(builder) \ No newline at end of file + return ObjectEnd(builder) diff --git a/python/flatbuffers/reflection/RPCCall.py b/python/flatbuffers/reflection/RPCCall.py index 9fdbf468b8ff..b126f04e43ee 100644 --- a/python/flatbuffers/reflection/RPCCall.py +++ b/python/flatbuffers/reflection/RPCCall.py @@ -102,30 +102,56 @@ def DocumentationIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) return o == 0 -def RPCCallStart(builder): builder.StartObject(5) +def RPCCallStart(builder): + return builder.StartObject(5) + def Start(builder): return RPCCallStart(builder) -def RPCCallAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def RPCCallAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return RPCCallAddName(builder, name) -def RPCCallAddRequest(builder, request): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(request), 0) + +def RPCCallAddRequest(builder, request): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(request), 0) + def AddRequest(builder, request): return RPCCallAddRequest(builder, request) -def RPCCallAddResponse(builder, response): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(response), 0) + +def RPCCallAddResponse(builder, response): + return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(response), 0) + def AddResponse(builder, response): return RPCCallAddResponse(builder, response) -def RPCCallAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def RPCCallAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return RPCCallAddAttributes(builder, attributes) -def RPCCallStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def RPCCallStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return RPCCallStartAttributesVector(builder, numElems) -def RPCCallAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def RPCCallAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return RPCCallAddDocumentation(builder, documentation) -def RPCCallStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def RPCCallStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return RPCCallStartDocumentationVector(builder, numElems) -def RPCCallEnd(builder): return builder.EndObject() + +def RPCCallEnd(builder): + return builder.EndObject() + def End(builder): - return RPCCallEnd(builder) \ No newline at end of file + return RPCCallEnd(builder) diff --git a/python/flatbuffers/reflection/Schema.py b/python/flatbuffers/reflection/Schema.py index df2f072f9856..d7929a49b6d9 100644 --- a/python/flatbuffers/reflection/Schema.py +++ b/python/flatbuffers/reflection/Schema.py @@ -162,45 +162,86 @@ def FbsFilesIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) return o == 0 -def SchemaStart(builder): builder.StartObject(8) +def SchemaStart(builder): + return builder.StartObject(8) + def Start(builder): return SchemaStart(builder) -def SchemaAddObjects(builder, objects): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(objects), 0) + +def SchemaAddObjects(builder, objects): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(objects), 0) + def AddObjects(builder, objects): return SchemaAddObjects(builder, objects) -def SchemaStartObjectsVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def SchemaStartObjectsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartObjectsVector(builder, numElems): return SchemaStartObjectsVector(builder, numElems) -def SchemaAddEnums(builder, enums): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(enums), 0) + +def SchemaAddEnums(builder, enums): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(enums), 0) + def AddEnums(builder, enums): return SchemaAddEnums(builder, enums) -def SchemaStartEnumsVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def SchemaStartEnumsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartEnumsVector(builder, numElems): return SchemaStartEnumsVector(builder, numElems) -def SchemaAddFileIdent(builder, fileIdent): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fileIdent), 0) + +def SchemaAddFileIdent(builder, fileIdent): + return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fileIdent), 0) + def AddFileIdent(builder, fileIdent): return SchemaAddFileIdent(builder, fileIdent) -def SchemaAddFileExt(builder, fileExt): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fileExt), 0) + +def SchemaAddFileExt(builder, fileExt): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fileExt), 0) + def AddFileExt(builder, fileExt): return SchemaAddFileExt(builder, fileExt) -def SchemaAddRootTable(builder, rootTable): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(rootTable), 0) + +def SchemaAddRootTable(builder, rootTable): + return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(rootTable), 0) + def AddRootTable(builder, rootTable): return SchemaAddRootTable(builder, rootTable) -def SchemaAddServices(builder, services): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(services), 0) + +def SchemaAddServices(builder, services): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(services), 0) + def AddServices(builder, services): return SchemaAddServices(builder, services) -def SchemaStartServicesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def SchemaStartServicesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartServicesVector(builder, numElems): return SchemaStartServicesVector(builder, numElems) -def SchemaAddAdvancedFeatures(builder, advancedFeatures): builder.PrependUint64Slot(6, advancedFeatures, 0) + +def SchemaAddAdvancedFeatures(builder, advancedFeatures): + return builder.PrependUint64Slot(6, advancedFeatures, 0) + def AddAdvancedFeatures(builder, advancedFeatures): return SchemaAddAdvancedFeatures(builder, advancedFeatures) -def SchemaAddFbsFiles(builder, fbsFiles): builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(fbsFiles), 0) + +def SchemaAddFbsFiles(builder, fbsFiles): + return builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(fbsFiles), 0) + def AddFbsFiles(builder, fbsFiles): return SchemaAddFbsFiles(builder, fbsFiles) -def SchemaStartFbsFilesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def SchemaStartFbsFilesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartFbsFilesVector(builder, numElems): return SchemaStartFbsFilesVector(builder, numElems) -def SchemaEnd(builder): return builder.EndObject() + +def SchemaEnd(builder): + return builder.EndObject() + def End(builder): - return SchemaEnd(builder) \ No newline at end of file + return SchemaEnd(builder) diff --git a/python/flatbuffers/reflection/SchemaFile.py b/python/flatbuffers/reflection/SchemaFile.py index 890fd3b53086..d4c817862112 100644 --- a/python/flatbuffers/reflection/SchemaFile.py +++ b/python/flatbuffers/reflection/SchemaFile.py @@ -60,18 +60,32 @@ def IncludedFilenamesIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) return o == 0 -def SchemaFileStart(builder): builder.StartObject(2) +def SchemaFileStart(builder): + return builder.StartObject(2) + def Start(builder): return SchemaFileStart(builder) -def SchemaFileAddFilename(builder, filename): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(filename), 0) + +def SchemaFileAddFilename(builder, filename): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(filename), 0) + def AddFilename(builder, filename): return SchemaFileAddFilename(builder, filename) -def SchemaFileAddIncludedFilenames(builder, includedFilenames): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(includedFilenames), 0) + +def SchemaFileAddIncludedFilenames(builder, includedFilenames): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(includedFilenames), 0) + def AddIncludedFilenames(builder, includedFilenames): return SchemaFileAddIncludedFilenames(builder, includedFilenames) -def SchemaFileStartIncludedFilenamesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def SchemaFileStartIncludedFilenamesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartIncludedFilenamesVector(builder, numElems): return SchemaFileStartIncludedFilenamesVector(builder, numElems) -def SchemaFileEnd(builder): return builder.EndObject() + +def SchemaFileEnd(builder): + return builder.EndObject() + def End(builder): - return SchemaFileEnd(builder) \ No newline at end of file + return SchemaFileEnd(builder) diff --git a/python/flatbuffers/reflection/Service.py b/python/flatbuffers/reflection/Service.py index d4f1a6a8ea63..eaec60af1c32 100644 --- a/python/flatbuffers/reflection/Service.py +++ b/python/flatbuffers/reflection/Service.py @@ -113,33 +113,62 @@ def DeclarationFile(self): return self._tab.String(o + self._tab.Pos) return None -def ServiceStart(builder): builder.StartObject(5) +def ServiceStart(builder): + return builder.StartObject(5) + def Start(builder): return ServiceStart(builder) -def ServiceAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def ServiceAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return ServiceAddName(builder, name) -def ServiceAddCalls(builder, calls): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(calls), 0) + +def ServiceAddCalls(builder, calls): + return builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(calls), 0) + def AddCalls(builder, calls): return ServiceAddCalls(builder, calls) -def ServiceStartCallsVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ServiceStartCallsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartCallsVector(builder, numElems): return ServiceStartCallsVector(builder, numElems) -def ServiceAddAttributes(builder, attributes): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + +def ServiceAddAttributes(builder, attributes): + return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0) + def AddAttributes(builder, attributes): return ServiceAddAttributes(builder, attributes) -def ServiceStartAttributesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ServiceStartAttributesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartAttributesVector(builder, numElems): return ServiceStartAttributesVector(builder, numElems) -def ServiceAddDocumentation(builder, documentation): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + +def ServiceAddDocumentation(builder, documentation): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0) + def AddDocumentation(builder, documentation): return ServiceAddDocumentation(builder, documentation) -def ServiceStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def ServiceStartDocumentationVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartDocumentationVector(builder, numElems): return ServiceStartDocumentationVector(builder, numElems) -def ServiceAddDeclarationFile(builder, declarationFile): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + +def ServiceAddDeclarationFile(builder, declarationFile): + return builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0) + def AddDeclarationFile(builder, declarationFile): return ServiceAddDeclarationFile(builder, declarationFile) -def ServiceEnd(builder): return builder.EndObject() + +def ServiceEnd(builder): + return builder.EndObject() + def End(builder): - return ServiceEnd(builder) \ No newline at end of file + return ServiceEnd(builder) diff --git a/python/flatbuffers/reflection/Type.py b/python/flatbuffers/reflection/Type.py index d606ab9ac093..eb58dd8a0149 100644 --- a/python/flatbuffers/reflection/Type.py +++ b/python/flatbuffers/reflection/Type.py @@ -72,27 +72,50 @@ def ElementSize(self): return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) return 0 -def TypeStart(builder): builder.StartObject(6) +def TypeStart(builder): + return builder.StartObject(6) + def Start(builder): return TypeStart(builder) -def TypeAddBaseType(builder, baseType): builder.PrependInt8Slot(0, baseType, 0) + +def TypeAddBaseType(builder, baseType): + return builder.PrependInt8Slot(0, baseType, 0) + def AddBaseType(builder, baseType): return TypeAddBaseType(builder, baseType) -def TypeAddElement(builder, element): builder.PrependInt8Slot(1, element, 0) + +def TypeAddElement(builder, element): + return builder.PrependInt8Slot(1, element, 0) + def AddElement(builder, element): return TypeAddElement(builder, element) -def TypeAddIndex(builder, index): builder.PrependInt32Slot(2, index, -1) + +def TypeAddIndex(builder, index): + return builder.PrependInt32Slot(2, index, -1) + def AddIndex(builder, index): return TypeAddIndex(builder, index) -def TypeAddFixedLength(builder, fixedLength): builder.PrependUint16Slot(3, fixedLength, 0) + +def TypeAddFixedLength(builder, fixedLength): + return builder.PrependUint16Slot(3, fixedLength, 0) + def AddFixedLength(builder, fixedLength): return TypeAddFixedLength(builder, fixedLength) -def TypeAddBaseSize(builder, baseSize): builder.PrependUint32Slot(4, baseSize, 4) + +def TypeAddBaseSize(builder, baseSize): + return builder.PrependUint32Slot(4, baseSize, 4) + def AddBaseSize(builder, baseSize): return TypeAddBaseSize(builder, baseSize) -def TypeAddElementSize(builder, elementSize): builder.PrependUint32Slot(5, elementSize, 0) + +def TypeAddElementSize(builder, elementSize): + return builder.PrependUint32Slot(5, elementSize, 0) + def AddElementSize(builder, elementSize): return TypeAddElementSize(builder, elementSize) -def TypeEnd(builder): return builder.EndObject() + +def TypeEnd(builder): + return builder.EndObject() + def End(builder): - return TypeEnd(builder) \ No newline at end of file + return TypeEnd(builder) diff --git a/src/flatc.cpp b/src/flatc.cpp index a5dd0b1f3b4b..0e20a2f7da4b 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -250,6 +250,8 @@ const static FlatCOption flatc_options[] = { { "", "no-leak-private-annotation", "", "Prevents multiple type of annotations within a Fbs SCHEMA file. " "Currently this is required to generate private types in Rust" }, + { "", "python-no-type-prefix-suffix", "", + "Skip emission of Python functions that are prefixed with typenames" }, { "", "file-names-only", "", "Print out generated file names without writing to the files"}, }; @@ -650,7 +652,9 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc, opts.ts_no_import_ext = true; } else if (arg == "--no-leak-private-annotation") { opts.no_leak_private_annotations = true; - } else if (arg == "--annotate-sparse-vectors") { + } else if (arg == "--python-no-type-prefix-suffix") { + opts.python_no_type_prefix_suffix = true; + } else if (arg == "--annotate-sparse-vectors") { options.annotate_include_vector_contents = false; } else if (arg == "--annotate") { if (++argi >= argc) Error("missing path following: " + arg, true); diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 5b5ce353a011..6c93b9092dfd 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -139,13 +139,15 @@ class PythonGenerator : public BaseGenerator { code += Indent + Indent + "return x\n"; code += "\n"; - // Add an alias with the old name - code += Indent + "@classmethod\n"; - code += Indent + "def GetRootAs" + struct_type + "(cls, buf, offset=0):\n"; - code += - Indent + Indent + - "\"\"\"This method is deprecated. Please switch to GetRootAs.\"\"\"\n"; - code += Indent + Indent + "return cls.GetRootAs(buf, offset)\n"; + if (!parser_.opts.python_no_type_prefix_suffix) { + // Add an alias with the old name + code += Indent + "@classmethod\n"; + code += Indent + "def GetRootAs" + struct_type + "(cls, buf, offset=0):\n"; + code += + Indent + Indent + + "\"\"\"This method is deprecated. Please switch to GetRootAs.\"\"\"\n"; + code += Indent + Indent + "return cls.GetRootAs(buf, offset)\n"; + } } // Initialize an existing object with other data, to avoid an allocation. @@ -480,7 +482,10 @@ class PythonGenerator : public BaseGenerator { if (!nested) { return; } // There is no nested flatbuffer. const std::string unqualified_name = nested->constant; - const std::string qualified_name = NestedFlatbufferType(unqualified_name); + std::string qualified_name = NestedFlatbufferType(unqualified_name); + if (qualified_name.empty()) { + qualified_name = nested->constant; + } auto &code = *code_ptr; GenReceiver(struct_def, code_ptr); @@ -491,7 +496,7 @@ class PythonGenerator : public BaseGenerator { code += Indent + Indent + Indent; code += "from " + qualified_name + " import " + unqualified_name + "\n"; code += Indent + Indent + Indent + "return " + unqualified_name; - code += ".GetRootAs" + unqualified_name; + code += ".GetRootAs"; code += "(self._tab.Bytes, self._tab.Vector(o))\n"; code += Indent + Indent + "return 0\n"; code += "\n"; @@ -605,15 +610,18 @@ class PythonGenerator : public BaseGenerator { auto &code = *code_ptr; const auto struct_type = namer_.Type(struct_def); // Generate method with struct name. - code += "def " + struct_type + "Start(builder): "; - code += "builder.StartObject("; + + const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" : struct_type + "Start"; + + code += "def " + name + "(builder):\n"; + code += Indent + "return builder.StartObject("; code += NumToString(struct_def.fields.vec.size()); - code += ")\n"; + code += ")\n\n"; - if (!parser_.opts.one_file) { + if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. code += "def Start(builder):\n"; - code += Indent + "return " + struct_type + "Start(builder)\n"; + code += Indent + "return " + struct_type + "Start(builder)\n\n"; } } @@ -624,12 +632,14 @@ class PythonGenerator : public BaseGenerator { const std::string field_var = namer_.Variable(field); const std::string field_method = namer_.Method(field); + const auto name = parser_.opts.python_no_type_prefix_suffix ? "Add" + field_method : namer_.Type(struct_def) + "Add" + field_method; + // Generate method with struct name. - code += "def " + namer_.Type(struct_def) + "Add" + field_method; + code += "def " + name; code += "(builder, "; code += field_var; - code += "): "; - code += "builder.Prepend"; + code += "):\n"; + code += Indent + "return builder.Prepend"; code += GenMethod(field) + "Slot("; code += NumToString(offset) + ", "; if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) { @@ -646,16 +656,16 @@ class PythonGenerator : public BaseGenerator { } else { code += field.value.constant; } - code += ")\n"; + code += ")\n\n"; - if (!parser_.opts.one_file) { + if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. code += "def Add" + field_method + "(builder, " + field_var + "):\n"; code += Indent + "return " + namer_.Type(struct_def) + "Add" + field_method; code += "(builder, "; code += field_var; - code += ")\n"; + code += ")\n\n"; } } @@ -667,20 +677,22 @@ class PythonGenerator : public BaseGenerator { const std::string field_method = namer_.Method(field); // Generate method with struct name. - code += "def " + struct_type + "Start" + field_method; - code += "Vector(builder, numElems): return builder.StartVector("; + const auto name = parser_.opts.python_no_type_prefix_suffix ? "Start" + field_method : struct_type + "Start" + field_method; + code += "def " + name; + code += "Vector(builder, numElems):\n"; + code += Indent + "return builder.StartVector("; auto vector_type = field.value.type.VectorType(); auto alignment = InlineAlignment(vector_type); auto elem_size = InlineSize(vector_type); code += NumToString(elem_size); code += ", numElems, " + NumToString(alignment); - code += ")\n"; + code += ")\n\n"; - if (!parser_.opts.one_file) { + if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. code += "def Start" + field_method + "Vector(builder, numElems):\n"; code += Indent + "return " + struct_type + "Start"; - code += field_method + "Vector(builder, numElems)\n"; + code += field_method + "Vector(builder, numElems)\n\n"; } } @@ -725,15 +737,16 @@ class PythonGenerator : public BaseGenerator { std::string *code_ptr) const { auto &code = *code_ptr; + const auto name = parser_.opts.python_no_type_prefix_suffix ? "End" : namer_.Type(struct_def) + "End"; // Generate method with struct name. - code += "def " + namer_.Type(struct_def) + "End"; - code += "(builder): "; - code += "return builder.EndObject()\n"; + code += "def " + name + "(builder):\n"; + code += Indent + "return builder.EndObject()\n\n"; - if (!parser_.opts.one_file) { + if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) { // Generate method without struct name. code += "def End(builder):\n"; code += Indent + "return " + namer_.Type(struct_def) + "End(builder)"; + code += "\n"; } } diff --git a/tests/MyGame/Example/ArrayTable.py b/tests/MyGame/Example/ArrayTable.py index b7a3ac5b6763..7f4051f5efa0 100644 --- a/tests/MyGame/Example/ArrayTable.py +++ b/tests/MyGame/Example/ArrayTable.py @@ -39,15 +39,24 @@ def A(self): return obj return None -def ArrayTableStart(builder): builder.StartObject(1) +def ArrayTableStart(builder): + return builder.StartObject(1) + def Start(builder): return ArrayTableStart(builder) -def ArrayTableAddA(builder, a): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(a), 0) + +def ArrayTableAddA(builder, a): + return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(a), 0) + def AddA(builder, a): return ArrayTableAddA(builder, a) -def ArrayTableEnd(builder): return builder.EndObject() + +def ArrayTableEnd(builder): + return builder.EndObject() + def End(builder): return ArrayTableEnd(builder) + import MyGame.Example.ArrayStruct try: from typing import Optional diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index 03dda3b66d54..bde02b4ab534 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -214,7 +214,7 @@ def TestnestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(30)) if o != 0: from MyGame.Example.Monster import Monster - return Monster.GetRootAsMonster(self._tab.Bytes, self._tab.Vector(o)) + return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 # Monster @@ -751,7 +751,7 @@ def TestrequirednestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(102)) if o != 0: from MyGame.Example.Monster import Monster - return Monster.GetRootAsMonster(self._tab.Bytes, self._tab.Vector(o)) + return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 # Monster @@ -872,63 +872,120 @@ def DoubleInfDefault(self): return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos) return float('inf') -def MonsterStart(builder): builder.StartObject(62) +def MonsterStart(builder): + return builder.StartObject(62) + def Start(builder): return MonsterStart(builder) -def MonsterAddPos(builder, pos): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) + +def MonsterAddPos(builder, pos): + return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) + def AddPos(builder, pos): return MonsterAddPos(builder, pos) -def MonsterAddMana(builder, mana): builder.PrependInt16Slot(1, mana, 150) + +def MonsterAddMana(builder, mana): + return builder.PrependInt16Slot(1, mana, 150) + def AddMana(builder, mana): return MonsterAddMana(builder, mana) -def MonsterAddHp(builder, hp): builder.PrependInt16Slot(2, hp, 100) + +def MonsterAddHp(builder, hp): + return builder.PrependInt16Slot(2, hp, 100) + def AddHp(builder, hp): return MonsterAddHp(builder, hp) -def MonsterAddName(builder, name): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def MonsterAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return MonsterAddName(builder, name) -def MonsterAddInventory(builder, inventory): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) + +def MonsterAddInventory(builder, inventory): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) + def AddInventory(builder, inventory): return MonsterAddInventory(builder, inventory) -def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartInventoryVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartInventoryVector(builder, numElems): return MonsterStartInventoryVector(builder, numElems) -def MonsterAddColor(builder, color): builder.PrependUint8Slot(6, color, 8) + +def MonsterAddColor(builder, color): + return builder.PrependUint8Slot(6, color, 8) + def AddColor(builder, color): return MonsterAddColor(builder, color) -def MonsterAddTestType(builder, testType): builder.PrependUint8Slot(7, testType, 0) + +def MonsterAddTestType(builder, testType): + return builder.PrependUint8Slot(7, testType, 0) + def AddTestType(builder, testType): return MonsterAddTestType(builder, testType) -def MonsterAddTest(builder, test): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) + +def MonsterAddTest(builder, test): + return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) + def AddTest(builder, test): return MonsterAddTest(builder, test) -def MonsterAddTest4(builder, test4): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) + +def MonsterAddTest4(builder, test4): + return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) + def AddTest4(builder, test4): return MonsterAddTest4(builder, test4) -def MonsterStartTest4Vector(builder, numElems): return builder.StartVector(4, numElems, 2) + +def MonsterStartTest4Vector(builder, numElems): + return builder.StartVector(4, numElems, 2) + def StartTest4Vector(builder, numElems): return MonsterStartTest4Vector(builder, numElems) -def MonsterAddTestarrayofstring(builder, testarrayofstring): builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) + +def MonsterAddTestarrayofstring(builder, testarrayofstring): + return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) + def AddTestarrayofstring(builder, testarrayofstring): return MonsterAddTestarrayofstring(builder, testarrayofstring) -def MonsterStartTestarrayofstringVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartTestarrayofstringVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartTestarrayofstringVector(builder, numElems): return MonsterStartTestarrayofstringVector(builder, numElems) -def MonsterAddTestarrayoftables(builder, testarrayoftables): builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) + +def MonsterAddTestarrayoftables(builder, testarrayoftables): + return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) + def AddTestarrayoftables(builder, testarrayoftables): return MonsterAddTestarrayoftables(builder, testarrayoftables) -def MonsterStartTestarrayoftablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartTestarrayoftablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartTestarrayoftablesVector(builder, numElems): return MonsterStartTestarrayoftablesVector(builder, numElems) -def MonsterAddEnemy(builder, enemy): builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) + +def MonsterAddEnemy(builder, enemy): + return builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) + def AddEnemy(builder, enemy): return MonsterAddEnemy(builder, enemy) -def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) + +def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): + return builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) + def AddTestnestedflatbuffer(builder, testnestedflatbuffer): return MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer) -def MonsterStartTestnestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartTestnestedflatbufferVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartTestnestedflatbufferVector(builder, numElems): return MonsterStartTestnestedflatbufferVector(builder, numElems) + def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): builder.StartVector(1, len(bytes), 1) builder.head = builder.head - len(bytes) @@ -936,156 +993,306 @@ def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): return builder.EndVector() def MakeTestnestedflatbufferVectorFromBytes(builder, bytes): return MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes) -def MonsterAddTestempty(builder, testempty): builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) +def MonsterAddTestempty(builder, testempty): + return builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) + def AddTestempty(builder, testempty): return MonsterAddTestempty(builder, testempty) -def MonsterAddTestbool(builder, testbool): builder.PrependBoolSlot(15, testbool, 0) + +def MonsterAddTestbool(builder, testbool): + return builder.PrependBoolSlot(15, testbool, 0) + def AddTestbool(builder, testbool): return MonsterAddTestbool(builder, testbool) -def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): builder.PrependInt32Slot(16, testhashs32Fnv1, 0) + +def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): + return builder.PrependInt32Slot(16, testhashs32Fnv1, 0) + def AddTesthashs32Fnv1(builder, testhashs32Fnv1): return MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1) -def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): builder.PrependUint32Slot(17, testhashu32Fnv1, 0) + +def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): + return builder.PrependUint32Slot(17, testhashu32Fnv1, 0) + def AddTesthashu32Fnv1(builder, testhashu32Fnv1): return MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1) -def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): builder.PrependInt64Slot(18, testhashs64Fnv1, 0) + +def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): + return builder.PrependInt64Slot(18, testhashs64Fnv1, 0) + def AddTesthashs64Fnv1(builder, testhashs64Fnv1): return MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1) -def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): builder.PrependUint64Slot(19, testhashu64Fnv1, 0) + +def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): + return builder.PrependUint64Slot(19, testhashu64Fnv1, 0) + def AddTesthashu64Fnv1(builder, testhashu64Fnv1): return MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1) -def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) + +def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): + return builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) + def AddTesthashs32Fnv1a(builder, testhashs32Fnv1a): return MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a) -def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) + +def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): + return builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) + def AddTesthashu32Fnv1a(builder, testhashu32Fnv1a): return MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a) -def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) + +def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): + return builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) + def AddTesthashs64Fnv1a(builder, testhashs64Fnv1a): return MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a) -def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) + +def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): + return builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) + def AddTesthashu64Fnv1a(builder, testhashu64Fnv1a): return MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a) -def MonsterAddTestarrayofbools(builder, testarrayofbools): builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) + +def MonsterAddTestarrayofbools(builder, testarrayofbools): + return builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) + def AddTestarrayofbools(builder, testarrayofbools): return MonsterAddTestarrayofbools(builder, testarrayofbools) -def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartTestarrayofboolsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartTestarrayofboolsVector(builder, numElems): return MonsterStartTestarrayofboolsVector(builder, numElems) -def MonsterAddTestf(builder, testf): builder.PrependFloat32Slot(25, testf, 3.14159) + +def MonsterAddTestf(builder, testf): + return builder.PrependFloat32Slot(25, testf, 3.14159) + def AddTestf(builder, testf): return MonsterAddTestf(builder, testf) -def MonsterAddTestf2(builder, testf2): builder.PrependFloat32Slot(26, testf2, 3.0) + +def MonsterAddTestf2(builder, testf2): + return builder.PrependFloat32Slot(26, testf2, 3.0) + def AddTestf2(builder, testf2): return MonsterAddTestf2(builder, testf2) -def MonsterAddTestf3(builder, testf3): builder.PrependFloat32Slot(27, testf3, 0.0) + +def MonsterAddTestf3(builder, testf3): + return builder.PrependFloat32Slot(27, testf3, 0.0) + def AddTestf3(builder, testf3): return MonsterAddTestf3(builder, testf3) -def MonsterAddTestarrayofstring2(builder, testarrayofstring2): builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) + +def MonsterAddTestarrayofstring2(builder, testarrayofstring2): + return builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) + def AddTestarrayofstring2(builder, testarrayofstring2): return MonsterAddTestarrayofstring2(builder, testarrayofstring2) -def MonsterStartTestarrayofstring2Vector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartTestarrayofstring2Vector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartTestarrayofstring2Vector(builder, numElems): return MonsterStartTestarrayofstring2Vector(builder, numElems) -def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) + +def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): + return builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) + def AddTestarrayofsortedstruct(builder, testarrayofsortedstruct): return MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct) -def MonsterStartTestarrayofsortedstructVector(builder, numElems): return builder.StartVector(8, numElems, 4) + +def MonsterStartTestarrayofsortedstructVector(builder, numElems): + return builder.StartVector(8, numElems, 4) + def StartTestarrayofsortedstructVector(builder, numElems): return MonsterStartTestarrayofsortedstructVector(builder, numElems) -def MonsterAddFlex(builder, flex): builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) + +def MonsterAddFlex(builder, flex): + return builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) + def AddFlex(builder, flex): return MonsterAddFlex(builder, flex) -def MonsterStartFlexVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartFlexVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartFlexVector(builder, numElems): return MonsterStartFlexVector(builder, numElems) -def MonsterAddTest5(builder, test5): builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) + +def MonsterAddTest5(builder, test5): + return builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) + def AddTest5(builder, test5): return MonsterAddTest5(builder, test5) -def MonsterStartTest5Vector(builder, numElems): return builder.StartVector(4, numElems, 2) + +def MonsterStartTest5Vector(builder, numElems): + return builder.StartVector(4, numElems, 2) + def StartTest5Vector(builder, numElems): return MonsterStartTest5Vector(builder, numElems) -def MonsterAddVectorOfLongs(builder, vectorOfLongs): builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) + +def MonsterAddVectorOfLongs(builder, vectorOfLongs): + return builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) + def AddVectorOfLongs(builder, vectorOfLongs): return MonsterAddVectorOfLongs(builder, vectorOfLongs) -def MonsterStartVectorOfLongsVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterStartVectorOfLongsVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVectorOfLongsVector(builder, numElems): return MonsterStartVectorOfLongsVector(builder, numElems) -def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) + +def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): + return builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) + def AddVectorOfDoubles(builder, vectorOfDoubles): return MonsterAddVectorOfDoubles(builder, vectorOfDoubles) -def MonsterStartVectorOfDoublesVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterStartVectorOfDoublesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVectorOfDoublesVector(builder, numElems): return MonsterStartVectorOfDoublesVector(builder, numElems) -def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) + +def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): + return builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) + def AddParentNamespaceTest(builder, parentNamespaceTest): return MonsterAddParentNamespaceTest(builder, parentNamespaceTest) -def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) + +def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): + return builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) + def AddVectorOfReferrables(builder, vectorOfReferrables): return MonsterAddVectorOfReferrables(builder, vectorOfReferrables) -def MonsterStartVectorOfReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartVectorOfReferrablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartVectorOfReferrablesVector(builder, numElems): return MonsterStartVectorOfReferrablesVector(builder, numElems) -def MonsterAddSingleWeakReference(builder, singleWeakReference): builder.PrependUint64Slot(36, singleWeakReference, 0) + +def MonsterAddSingleWeakReference(builder, singleWeakReference): + return builder.PrependUint64Slot(36, singleWeakReference, 0) + def AddSingleWeakReference(builder, singleWeakReference): return MonsterAddSingleWeakReference(builder, singleWeakReference) -def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) + +def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): + return builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) + def AddVectorOfWeakReferences(builder, vectorOfWeakReferences): return MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences) -def MonsterStartVectorOfWeakReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterStartVectorOfWeakReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVectorOfWeakReferencesVector(builder, numElems): return MonsterStartVectorOfWeakReferencesVector(builder, numElems) -def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) + +def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): + return builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) + def AddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): return MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables) -def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartVectorOfStrongReferrablesVector(builder, numElems): return MonsterStartVectorOfStrongReferrablesVector(builder, numElems) -def MonsterAddCoOwningReference(builder, coOwningReference): builder.PrependUint64Slot(39, coOwningReference, 0) + +def MonsterAddCoOwningReference(builder, coOwningReference): + return builder.PrependUint64Slot(39, coOwningReference, 0) + def AddCoOwningReference(builder, coOwningReference): return MonsterAddCoOwningReference(builder, coOwningReference) -def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) + +def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): + return builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) + def AddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): return MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences) -def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVectorOfCoOwningReferencesVector(builder, numElems): return MonsterStartVectorOfCoOwningReferencesVector(builder, numElems) -def MonsterAddNonOwningReference(builder, nonOwningReference): builder.PrependUint64Slot(41, nonOwningReference, 0) + +def MonsterAddNonOwningReference(builder, nonOwningReference): + return builder.PrependUint64Slot(41, nonOwningReference, 0) + def AddNonOwningReference(builder, nonOwningReference): return MonsterAddNonOwningReference(builder, nonOwningReference) -def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) + +def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): + return builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) + def AddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): return MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences) -def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVectorOfNonOwningReferencesVector(builder, numElems): return MonsterStartVectorOfNonOwningReferencesVector(builder, numElems) -def MonsterAddAnyUniqueType(builder, anyUniqueType): builder.PrependUint8Slot(43, anyUniqueType, 0) + +def MonsterAddAnyUniqueType(builder, anyUniqueType): + return builder.PrependUint8Slot(43, anyUniqueType, 0) + def AddAnyUniqueType(builder, anyUniqueType): return MonsterAddAnyUniqueType(builder, anyUniqueType) -def MonsterAddAnyUnique(builder, anyUnique): builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) + +def MonsterAddAnyUnique(builder, anyUnique): + return builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) + def AddAnyUnique(builder, anyUnique): return MonsterAddAnyUnique(builder, anyUnique) -def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): builder.PrependUint8Slot(45, anyAmbiguousType, 0) + +def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): + return builder.PrependUint8Slot(45, anyAmbiguousType, 0) + def AddAnyAmbiguousType(builder, anyAmbiguousType): return MonsterAddAnyAmbiguousType(builder, anyAmbiguousType) -def MonsterAddAnyAmbiguous(builder, anyAmbiguous): builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) + +def MonsterAddAnyAmbiguous(builder, anyAmbiguous): + return builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) + def AddAnyAmbiguous(builder, anyAmbiguous): return MonsterAddAnyAmbiguous(builder, anyAmbiguous) -def MonsterAddVectorOfEnums(builder, vectorOfEnums): builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) + +def MonsterAddVectorOfEnums(builder, vectorOfEnums): + return builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) + def AddVectorOfEnums(builder, vectorOfEnums): return MonsterAddVectorOfEnums(builder, vectorOfEnums) -def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartVectorOfEnumsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartVectorOfEnumsVector(builder, numElems): return MonsterStartVectorOfEnumsVector(builder, numElems) -def MonsterAddSignedEnum(builder, signedEnum): builder.PrependInt8Slot(48, signedEnum, -1) + +def MonsterAddSignedEnum(builder, signedEnum): + return builder.PrependInt8Slot(48, signedEnum, -1) + def AddSignedEnum(builder, signedEnum): return MonsterAddSignedEnum(builder, signedEnum) -def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) + +def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): + return builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) + def AddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): return MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer) -def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartTestrequirednestedflatbufferVector(builder, numElems): return MonsterStartTestrequirednestedflatbufferVector(builder, numElems) + def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): builder.StartVector(1, len(bytes), 1) builder.head = builder.head - len(bytes) @@ -1093,48 +1300,90 @@ def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): return builder.EndVector() def MakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): return MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes) -def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) +def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): + return builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) + def AddScalarKeySortedTables(builder, scalarKeySortedTables): return MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables) -def MonsterStartScalarKeySortedTablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterStartScalarKeySortedTablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartScalarKeySortedTablesVector(builder, numElems): return MonsterStartScalarKeySortedTablesVector(builder, numElems) -def MonsterAddNativeInline(builder, nativeInline): builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) + +def MonsterAddNativeInline(builder, nativeInline): + return builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) + def AddNativeInline(builder, nativeInline): return MonsterAddNativeInline(builder, nativeInline) -def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) + +def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): + return builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) + def AddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): return MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault) -def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): builder.PrependUint64Slot(53, longEnumNormalDefault, 2) + +def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): + return builder.PrependUint64Slot(53, longEnumNormalDefault, 2) + def AddLongEnumNormalDefault(builder, longEnumNormalDefault): return MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault) -def MonsterAddNanDefault(builder, nanDefault): builder.PrependFloat32Slot(54, nanDefault, float('nan')) + +def MonsterAddNanDefault(builder, nanDefault): + return builder.PrependFloat32Slot(54, nanDefault, float('nan')) + def AddNanDefault(builder, nanDefault): return MonsterAddNanDefault(builder, nanDefault) -def MonsterAddInfDefault(builder, infDefault): builder.PrependFloat32Slot(55, infDefault, float('inf')) + +def MonsterAddInfDefault(builder, infDefault): + return builder.PrependFloat32Slot(55, infDefault, float('inf')) + def AddInfDefault(builder, infDefault): return MonsterAddInfDefault(builder, infDefault) -def MonsterAddPositiveInfDefault(builder, positiveInfDefault): builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) + +def MonsterAddPositiveInfDefault(builder, positiveInfDefault): + return builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) + def AddPositiveInfDefault(builder, positiveInfDefault): return MonsterAddPositiveInfDefault(builder, positiveInfDefault) -def MonsterAddInfinityDefault(builder, infinityDefault): builder.PrependFloat32Slot(57, infinityDefault, float('inf')) + +def MonsterAddInfinityDefault(builder, infinityDefault): + return builder.PrependFloat32Slot(57, infinityDefault, float('inf')) + def AddInfinityDefault(builder, infinityDefault): return MonsterAddInfinityDefault(builder, infinityDefault) -def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) + +def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): + return builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) + def AddPositiveInfinityDefault(builder, positiveInfinityDefault): return MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault) -def MonsterAddNegativeInfDefault(builder, negativeInfDefault): builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) + +def MonsterAddNegativeInfDefault(builder, negativeInfDefault): + return builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) + def AddNegativeInfDefault(builder, negativeInfDefault): return MonsterAddNegativeInfDefault(builder, negativeInfDefault) -def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) + +def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): + return builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) + def AddNegativeInfinityDefault(builder, negativeInfinityDefault): return MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault) -def MonsterAddDoubleInfDefault(builder, doubleInfDefault): builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) + +def MonsterAddDoubleInfDefault(builder, doubleInfDefault): + return builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) + def AddDoubleInfDefault(builder, doubleInfDefault): return MonsterAddDoubleInfDefault(builder, doubleInfDefault) -def MonsterEnd(builder): return builder.EndObject() + +def MonsterEnd(builder): + return builder.EndObject() + def End(builder): return MonsterEnd(builder) + import MyGame.Example.Ability import MyGame.Example.Any import MyGame.Example.AnyAmbiguousAliases diff --git a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py index 9a3cbee22500..33c2a441564e 100644 --- a/tests/MyGame/Example/NestedUnion/NestedUnionTest.py +++ b/tests/MyGame/Example/NestedUnion/NestedUnionTest.py @@ -55,24 +55,42 @@ def Id(self): return self._tab.Get(flatbuffers.number_types.Int16Flags, o + self._tab.Pos) return 0 -def NestedUnionTestStart(builder): builder.StartObject(4) +def NestedUnionTestStart(builder): + return builder.StartObject(4) + def Start(builder): return NestedUnionTestStart(builder) -def NestedUnionTestAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def NestedUnionTestAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + def AddName(builder, name): return NestedUnionTestAddName(builder, name) -def NestedUnionTestAddDataType(builder, dataType): builder.PrependUint8Slot(1, dataType, 0) + +def NestedUnionTestAddDataType(builder, dataType): + return builder.PrependUint8Slot(1, dataType, 0) + def AddDataType(builder, dataType): return NestedUnionTestAddDataType(builder, dataType) -def NestedUnionTestAddData(builder, data): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) + +def NestedUnionTestAddData(builder, data): + return builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) + def AddData(builder, data): return NestedUnionTestAddData(builder, data) -def NestedUnionTestAddId(builder, id): builder.PrependInt16Slot(3, id, 0) + +def NestedUnionTestAddId(builder, id): + return builder.PrependInt16Slot(3, id, 0) + def AddId(builder, id): return NestedUnionTestAddId(builder, id) -def NestedUnionTestEnd(builder): return builder.EndObject() + +def NestedUnionTestEnd(builder): + return builder.EndObject() + def End(builder): return NestedUnionTestEnd(builder) + import MyGame.Example.NestedUnion.Any import MyGame.Example.NestedUnion.TestSimpleTableWithEnum import MyGame.Example.NestedUnion.Vec3 diff --git a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py index 46ebc263c925..b3ad74f76abb 100644 --- a/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/NestedUnion/TestSimpleTableWithEnum.py @@ -31,16 +31,25 @@ def Color(self): return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 2 -def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) +def TestSimpleTableWithEnumStart(builder): + return builder.StartObject(1) + def Start(builder): return TestSimpleTableWithEnumStart(builder) -def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2) + +def TestSimpleTableWithEnumAddColor(builder, color): + return builder.PrependUint8Slot(0, color, 2) + def AddColor(builder, color): return TestSimpleTableWithEnumAddColor(builder, color) -def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() + +def TestSimpleTableWithEnumEnd(builder): + return builder.EndObject() + def End(builder): return TestSimpleTableWithEnumEnd(builder) + class TestSimpleTableWithEnumT(object): # TestSimpleTableWithEnumT diff --git a/tests/MyGame/Example/NestedUnion/Vec3.py b/tests/MyGame/Example/NestedUnion/Vec3.py index f3bb75f26ca0..915f580146c8 100644 --- a/tests/MyGame/Example/NestedUnion/Vec3.py +++ b/tests/MyGame/Example/NestedUnion/Vec3.py @@ -70,30 +70,54 @@ def Test3(self): return obj return None -def Vec3Start(builder): builder.StartObject(6) +def Vec3Start(builder): + return builder.StartObject(6) + def Start(builder): return Vec3Start(builder) -def Vec3AddX(builder, x): builder.PrependFloat64Slot(0, x, 0.0) + +def Vec3AddX(builder, x): + return builder.PrependFloat64Slot(0, x, 0.0) + def AddX(builder, x): return Vec3AddX(builder, x) -def Vec3AddY(builder, y): builder.PrependFloat64Slot(1, y, 0.0) + +def Vec3AddY(builder, y): + return builder.PrependFloat64Slot(1, y, 0.0) + def AddY(builder, y): return Vec3AddY(builder, y) -def Vec3AddZ(builder, z): builder.PrependFloat64Slot(2, z, 0.0) + +def Vec3AddZ(builder, z): + return builder.PrependFloat64Slot(2, z, 0.0) + def AddZ(builder, z): return Vec3AddZ(builder, z) -def Vec3AddTest1(builder, test1): builder.PrependFloat64Slot(3, test1, 0.0) + +def Vec3AddTest1(builder, test1): + return builder.PrependFloat64Slot(3, test1, 0.0) + def AddTest1(builder, test1): return Vec3AddTest1(builder, test1) -def Vec3AddTest2(builder, test2): builder.PrependUint8Slot(4, test2, 0) + +def Vec3AddTest2(builder, test2): + return builder.PrependUint8Slot(4, test2, 0) + def AddTest2(builder, test2): return Vec3AddTest2(builder, test2) -def Vec3AddTest3(builder, test3): builder.PrependStructSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(test3), 0) + +def Vec3AddTest3(builder, test3): + return builder.PrependStructSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(test3), 0) + def AddTest3(builder, test3): return Vec3AddTest3(builder, test3) -def Vec3End(builder): return builder.EndObject() + +def Vec3End(builder): + return builder.EndObject() + def End(builder): return Vec3End(builder) + import MyGame.Example.NestedUnion.Test try: from typing import Optional diff --git a/tests/MyGame/Example/Referrable.py b/tests/MyGame/Example/Referrable.py index 5fd1e24a27f7..e5081e1ae2ee 100644 --- a/tests/MyGame/Example/Referrable.py +++ b/tests/MyGame/Example/Referrable.py @@ -35,16 +35,25 @@ def Id(self): return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos) return 0 -def ReferrableStart(builder): builder.StartObject(1) +def ReferrableStart(builder): + return builder.StartObject(1) + def Start(builder): return ReferrableStart(builder) -def ReferrableAddId(builder, id): builder.PrependUint64Slot(0, id, 0) + +def ReferrableAddId(builder, id): + return builder.PrependUint64Slot(0, id, 0) + def AddId(builder, id): return ReferrableAddId(builder, id) -def ReferrableEnd(builder): return builder.EndObject() + +def ReferrableEnd(builder): + return builder.EndObject() + def End(builder): return ReferrableEnd(builder) + class ReferrableT(object): # ReferrableT diff --git a/tests/MyGame/Example/Stat.py b/tests/MyGame/Example/Stat.py index 471bc36ff068..00ca1a468aae 100644 --- a/tests/MyGame/Example/Stat.py +++ b/tests/MyGame/Example/Stat.py @@ -49,22 +49,37 @@ def Count(self): return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) return 0 -def StatStart(builder): builder.StartObject(3) +def StatStart(builder): + return builder.StartObject(3) + def Start(builder): return StatStart(builder) -def StatAddId(builder, id): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) + +def StatAddId(builder, id): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) + def AddId(builder, id): return StatAddId(builder, id) -def StatAddVal(builder, val): builder.PrependInt64Slot(1, val, 0) + +def StatAddVal(builder, val): + return builder.PrependInt64Slot(1, val, 0) + def AddVal(builder, val): return StatAddVal(builder, val) -def StatAddCount(builder, count): builder.PrependUint16Slot(2, count, 0) + +def StatAddCount(builder, count): + return builder.PrependUint16Slot(2, count, 0) + def AddCount(builder, count): return StatAddCount(builder, count) -def StatEnd(builder): return builder.EndObject() + +def StatEnd(builder): + return builder.EndObject() + def End(builder): return StatEnd(builder) + class StatT(object): # StatT diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.py b/tests/MyGame/Example/TestSimpleTableWithEnum.py index 9e58cc4b5510..99e5c41bcddb 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.py @@ -35,16 +35,25 @@ def Color(self): return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 2 -def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) +def TestSimpleTableWithEnumStart(builder): + return builder.StartObject(1) + def Start(builder): return TestSimpleTableWithEnumStart(builder) -def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2) + +def TestSimpleTableWithEnumAddColor(builder, color): + return builder.PrependUint8Slot(0, color, 2) + def AddColor(builder, color): return TestSimpleTableWithEnumAddColor(builder, color) -def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() + +def TestSimpleTableWithEnumEnd(builder): + return builder.EndObject() + def End(builder): return TestSimpleTableWithEnumEnd(builder) + class TestSimpleTableWithEnumT(object): # TestSimpleTableWithEnumT diff --git a/tests/MyGame/Example/TypeAliases.py b/tests/MyGame/Example/TypeAliases.py index b3020490a0b6..8fb33b9d3178 100644 --- a/tests/MyGame/Example/TypeAliases.py +++ b/tests/MyGame/Example/TypeAliases.py @@ -152,54 +152,102 @@ def Vf64IsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26)) return o == 0 -def TypeAliasesStart(builder): builder.StartObject(12) +def TypeAliasesStart(builder): + return builder.StartObject(12) + def Start(builder): return TypeAliasesStart(builder) -def TypeAliasesAddI8(builder, i8): builder.PrependInt8Slot(0, i8, 0) + +def TypeAliasesAddI8(builder, i8): + return builder.PrependInt8Slot(0, i8, 0) + def AddI8(builder, i8): return TypeAliasesAddI8(builder, i8) -def TypeAliasesAddU8(builder, u8): builder.PrependUint8Slot(1, u8, 0) + +def TypeAliasesAddU8(builder, u8): + return builder.PrependUint8Slot(1, u8, 0) + def AddU8(builder, u8): return TypeAliasesAddU8(builder, u8) -def TypeAliasesAddI16(builder, i16): builder.PrependInt16Slot(2, i16, 0) + +def TypeAliasesAddI16(builder, i16): + return builder.PrependInt16Slot(2, i16, 0) + def AddI16(builder, i16): return TypeAliasesAddI16(builder, i16) -def TypeAliasesAddU16(builder, u16): builder.PrependUint16Slot(3, u16, 0) + +def TypeAliasesAddU16(builder, u16): + return builder.PrependUint16Slot(3, u16, 0) + def AddU16(builder, u16): return TypeAliasesAddU16(builder, u16) -def TypeAliasesAddI32(builder, i32): builder.PrependInt32Slot(4, i32, 0) + +def TypeAliasesAddI32(builder, i32): + return builder.PrependInt32Slot(4, i32, 0) + def AddI32(builder, i32): return TypeAliasesAddI32(builder, i32) -def TypeAliasesAddU32(builder, u32): builder.PrependUint32Slot(5, u32, 0) + +def TypeAliasesAddU32(builder, u32): + return builder.PrependUint32Slot(5, u32, 0) + def AddU32(builder, u32): return TypeAliasesAddU32(builder, u32) -def TypeAliasesAddI64(builder, i64): builder.PrependInt64Slot(6, i64, 0) + +def TypeAliasesAddI64(builder, i64): + return builder.PrependInt64Slot(6, i64, 0) + def AddI64(builder, i64): return TypeAliasesAddI64(builder, i64) -def TypeAliasesAddU64(builder, u64): builder.PrependUint64Slot(7, u64, 0) + +def TypeAliasesAddU64(builder, u64): + return builder.PrependUint64Slot(7, u64, 0) + def AddU64(builder, u64): return TypeAliasesAddU64(builder, u64) -def TypeAliasesAddF32(builder, f32): builder.PrependFloat32Slot(8, f32, 0.0) + +def TypeAliasesAddF32(builder, f32): + return builder.PrependFloat32Slot(8, f32, 0.0) + def AddF32(builder, f32): return TypeAliasesAddF32(builder, f32) -def TypeAliasesAddF64(builder, f64): builder.PrependFloat64Slot(9, f64, 0.0) + +def TypeAliasesAddF64(builder, f64): + return builder.PrependFloat64Slot(9, f64, 0.0) + def AddF64(builder, f64): return TypeAliasesAddF64(builder, f64) -def TypeAliasesAddV8(builder, v8): builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) + +def TypeAliasesAddV8(builder, v8): + return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) + def AddV8(builder, v8): return TypeAliasesAddV8(builder, v8) -def TypeAliasesStartV8Vector(builder, numElems): return builder.StartVector(1, numElems, 1) + +def TypeAliasesStartV8Vector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def StartV8Vector(builder, numElems): return TypeAliasesStartV8Vector(builder, numElems) -def TypeAliasesAddVf64(builder, vf64): builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) + +def TypeAliasesAddVf64(builder, vf64): + return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) + def AddVf64(builder, vf64): return TypeAliasesAddVf64(builder, vf64) -def TypeAliasesStartVf64Vector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def TypeAliasesStartVf64Vector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartVf64Vector(builder, numElems): return TypeAliasesStartVf64Vector(builder, numElems) -def TypeAliasesEnd(builder): return builder.EndObject() + +def TypeAliasesEnd(builder): + return builder.EndObject() + def End(builder): return TypeAliasesEnd(builder) + try: from typing import List except: diff --git a/tests/MyGame/Example2/Monster.py b/tests/MyGame/Example2/Monster.py index 020efef731ce..965c4ffdc27e 100644 --- a/tests/MyGame/Example2/Monster.py +++ b/tests/MyGame/Example2/Monster.py @@ -28,13 +28,19 @@ def MonsterBufferHasIdentifier(cls, buf, offset, size_prefixed=False): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def MonsterStart(builder): builder.StartObject(0) +def MonsterStart(builder): + return builder.StartObject(0) + def Start(builder): return MonsterStart(builder) -def MonsterEnd(builder): return builder.EndObject() + +def MonsterEnd(builder): + return builder.EndObject() + def End(builder): return MonsterEnd(builder) + class MonsterT(object): # MonsterT diff --git a/tests/MyGame/InParentNamespace.py b/tests/MyGame/InParentNamespace.py index 0914aa462482..bd10e6955edb 100644 --- a/tests/MyGame/InParentNamespace.py +++ b/tests/MyGame/InParentNamespace.py @@ -28,13 +28,19 @@ def InParentNamespaceBufferHasIdentifier(cls, buf, offset, size_prefixed=False): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def InParentNamespaceStart(builder): builder.StartObject(0) +def InParentNamespaceStart(builder): + return builder.StartObject(0) + def Start(builder): return InParentNamespaceStart(builder) -def InParentNamespaceEnd(builder): return builder.EndObject() + +def InParentNamespaceEnd(builder): + return builder.EndObject() + def End(builder): return InParentNamespaceEnd(builder) + class InParentNamespaceT(object): # InParentNamespaceT diff --git a/tests/MyGame/MonsterExtra.py b/tests/MyGame/MonsterExtra.py index 90916523c96b..10e380b79d99 100644 --- a/tests/MyGame/MonsterExtra.py +++ b/tests/MyGame/MonsterExtra.py @@ -138,48 +138,90 @@ def FvecIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) return o == 0 -def MonsterExtraStart(builder): builder.StartObject(11) +def MonsterExtraStart(builder): + return builder.StartObject(11) + def Start(builder): return MonsterExtraStart(builder) -def MonsterExtraAddD0(builder, d0): builder.PrependFloat64Slot(0, d0, float('nan')) + +def MonsterExtraAddD0(builder, d0): + return builder.PrependFloat64Slot(0, d0, float('nan')) + def AddD0(builder, d0): return MonsterExtraAddD0(builder, d0) -def MonsterExtraAddD1(builder, d1): builder.PrependFloat64Slot(1, d1, float('nan')) + +def MonsterExtraAddD1(builder, d1): + return builder.PrependFloat64Slot(1, d1, float('nan')) + def AddD1(builder, d1): return MonsterExtraAddD1(builder, d1) -def MonsterExtraAddD2(builder, d2): builder.PrependFloat64Slot(2, d2, float('inf')) + +def MonsterExtraAddD2(builder, d2): + return builder.PrependFloat64Slot(2, d2, float('inf')) + def AddD2(builder, d2): return MonsterExtraAddD2(builder, d2) -def MonsterExtraAddD3(builder, d3): builder.PrependFloat64Slot(3, d3, float('-inf')) + +def MonsterExtraAddD3(builder, d3): + return builder.PrependFloat64Slot(3, d3, float('-inf')) + def AddD3(builder, d3): return MonsterExtraAddD3(builder, d3) -def MonsterExtraAddF0(builder, f0): builder.PrependFloat32Slot(4, f0, float('nan')) + +def MonsterExtraAddF0(builder, f0): + return builder.PrependFloat32Slot(4, f0, float('nan')) + def AddF0(builder, f0): return MonsterExtraAddF0(builder, f0) -def MonsterExtraAddF1(builder, f1): builder.PrependFloat32Slot(5, f1, float('nan')) + +def MonsterExtraAddF1(builder, f1): + return builder.PrependFloat32Slot(5, f1, float('nan')) + def AddF1(builder, f1): return MonsterExtraAddF1(builder, f1) -def MonsterExtraAddF2(builder, f2): builder.PrependFloat32Slot(6, f2, float('inf')) + +def MonsterExtraAddF2(builder, f2): + return builder.PrependFloat32Slot(6, f2, float('inf')) + def AddF2(builder, f2): return MonsterExtraAddF2(builder, f2) -def MonsterExtraAddF3(builder, f3): builder.PrependFloat32Slot(7, f3, float('-inf')) + +def MonsterExtraAddF3(builder, f3): + return builder.PrependFloat32Slot(7, f3, float('-inf')) + def AddF3(builder, f3): return MonsterExtraAddF3(builder, f3) -def MonsterExtraAddDvec(builder, dvec): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(dvec), 0) + +def MonsterExtraAddDvec(builder, dvec): + return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(dvec), 0) + def AddDvec(builder, dvec): return MonsterExtraAddDvec(builder, dvec) -def MonsterExtraStartDvecVector(builder, numElems): return builder.StartVector(8, numElems, 8) + +def MonsterExtraStartDvecVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + def StartDvecVector(builder, numElems): return MonsterExtraStartDvecVector(builder, numElems) -def MonsterExtraAddFvec(builder, fvec): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(fvec), 0) + +def MonsterExtraAddFvec(builder, fvec): + return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(fvec), 0) + def AddFvec(builder, fvec): return MonsterExtraAddFvec(builder, fvec) -def MonsterExtraStartFvecVector(builder, numElems): return builder.StartVector(4, numElems, 4) + +def MonsterExtraStartFvecVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + def StartFvecVector(builder, numElems): return MonsterExtraStartFvecVector(builder, numElems) -def MonsterExtraEnd(builder): return builder.EndObject() + +def MonsterExtraEnd(builder): + return builder.EndObject() + def End(builder): return MonsterExtraEnd(builder) + try: from typing import List except: diff --git a/tests/monster_test_generated.py b/tests/monster_test_generated.py index b70c31a2fb79..36bbb6021ae4 100644 --- a/tests/monster_test_generated.py +++ b/tests/monster_test_generated.py @@ -108,8 +108,12 @@ def InParentNamespaceBufferHasIdentifier(cls, buf, offset, size_prefixed=False): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def InParentNamespaceStart(builder): builder.StartObject(0) -def InParentNamespaceEnd(builder): return builder.EndObject() +def InParentNamespaceStart(builder): + return builder.StartObject(0) + +def InParentNamespaceEnd(builder): + return builder.EndObject() + class InParentNamespaceT(object): @@ -169,8 +173,12 @@ def MonsterBufferHasIdentifier(cls, buf, offset, size_prefixed=False): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def MonsterStart(builder): builder.StartObject(0) -def MonsterEnd(builder): return builder.EndObject() +def MonsterStart(builder): + return builder.StartObject(0) + +def MonsterEnd(builder): + return builder.EndObject() + class MonsterT(object): @@ -297,9 +305,15 @@ def Color(self): return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 2 -def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) -def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2) -def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() +def TestSimpleTableWithEnumStart(builder): + return builder.StartObject(1) + +def TestSimpleTableWithEnumAddColor(builder, color): + return builder.PrependUint8Slot(0, color, 2) + +def TestSimpleTableWithEnumEnd(builder): + return builder.EndObject() + class TestSimpleTableWithEnumT(object): @@ -693,11 +707,21 @@ def Count(self): return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) return 0 -def StatStart(builder): builder.StartObject(3) -def StatAddId(builder, id): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) -def StatAddVal(builder, val): builder.PrependInt64Slot(1, val, 0) -def StatAddCount(builder, count): builder.PrependUint16Slot(2, count, 0) -def StatEnd(builder): return builder.EndObject() +def StatStart(builder): + return builder.StartObject(3) + +def StatAddId(builder, id): + return builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(id), 0) + +def StatAddVal(builder, val): + return builder.PrependInt64Slot(1, val, 0) + +def StatAddCount(builder, count): + return builder.PrependUint16Slot(2, count, 0) + +def StatEnd(builder): + return builder.EndObject() + class StatT(object): @@ -775,9 +799,15 @@ def Id(self): return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos) return 0 -def ReferrableStart(builder): builder.StartObject(1) -def ReferrableAddId(builder, id): builder.PrependUint64Slot(0, id, 0) -def ReferrableEnd(builder): return builder.EndObject() +def ReferrableStart(builder): + return builder.StartObject(1) + +def ReferrableAddId(builder, id): + return builder.PrependUint64Slot(0, id, 0) + +def ReferrableEnd(builder): + return builder.EndObject() + class ReferrableT(object): @@ -1021,7 +1051,7 @@ def TestnestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(30)) if o != 0: from MyGame.Example.Monster import Monster - return Monster.GetRootAsMonster(self._tab.Bytes, self._tab.Vector(o)) + return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 # Monster @@ -1552,7 +1582,7 @@ def TestrequirednestedflatbufferNestedRoot(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(102)) if o != 0: from MyGame.Example.Monster import Monster - return Monster.GetRootAsMonster(self._tab.Bytes, self._tab.Vector(o)) + return Monster.GetRootAs(self._tab.Bytes, self._tab.Vector(o)) return 0 # Monster @@ -1671,99 +1701,265 @@ def DoubleInfDefault(self): return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos) return float('inf') -def MonsterStart(builder): builder.StartObject(62) -def MonsterAddPos(builder, pos): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) -def MonsterAddMana(builder, mana): builder.PrependInt16Slot(1, mana, 150) -def MonsterAddHp(builder, hp): builder.PrependInt16Slot(2, hp, 100) -def MonsterAddName(builder, name): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def MonsterAddInventory(builder, inventory): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) -def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def MonsterAddColor(builder, color): builder.PrependUint8Slot(6, color, 8) -def MonsterAddTestType(builder, testType): builder.PrependUint8Slot(7, testType, 0) -def MonsterAddTest(builder, test): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) -def MonsterAddTest4(builder, test4): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) -def MonsterStartTest4Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def MonsterAddTestarrayofstring(builder, testarrayofstring): builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) -def MonsterStartTestarrayofstringVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddTestarrayoftables(builder, testarrayoftables): builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) -def MonsterStartTestarrayoftablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddEnemy(builder, enemy): builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) -def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) -def MonsterStartTestnestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) +def MonsterStart(builder): + return builder.StartObject(62) + +def MonsterAddPos(builder, pos): + return builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0) + +def MonsterAddMana(builder, mana): + return builder.PrependInt16Slot(1, mana, 150) + +def MonsterAddHp(builder, hp): + return builder.PrependInt16Slot(2, hp, 100) + +def MonsterAddName(builder, name): + return builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + +def MonsterAddInventory(builder, inventory): + return builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) + +def MonsterStartInventoryVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + +def MonsterAddColor(builder, color): + return builder.PrependUint8Slot(6, color, 8) + +def MonsterAddTestType(builder, testType): + return builder.PrependUint8Slot(7, testType, 0) + +def MonsterAddTest(builder, test): + return builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) + +def MonsterAddTest4(builder, test4): + return builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) + +def MonsterStartTest4Vector(builder, numElems): + return builder.StartVector(4, numElems, 2) + +def MonsterAddTestarrayofstring(builder, testarrayofstring): + return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring), 0) + +def MonsterStartTestarrayofstringVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddTestarrayoftables(builder, testarrayoftables): + return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayoftables), 0) + +def MonsterStartTestarrayoftablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddEnemy(builder, enemy): + return builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(enemy), 0) + +def MonsterAddTestnestedflatbuffer(builder, testnestedflatbuffer): + return builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(testnestedflatbuffer), 0) + +def MonsterStartTestnestedflatbufferVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def MonsterMakeTestnestedflatbufferVectorFromBytes(builder, bytes): builder.StartVector(1, len(bytes), 1) builder.head = builder.head - len(bytes) builder.Bytes[builder.head : builder.head + len(bytes)] = bytes return builder.EndVector() -def MonsterAddTestempty(builder, testempty): builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) -def MonsterAddTestbool(builder, testbool): builder.PrependBoolSlot(15, testbool, 0) -def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): builder.PrependInt32Slot(16, testhashs32Fnv1, 0) -def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): builder.PrependUint32Slot(17, testhashu32Fnv1, 0) -def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): builder.PrependInt64Slot(18, testhashs64Fnv1, 0) -def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): builder.PrependUint64Slot(19, testhashu64Fnv1, 0) -def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) -def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) -def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) -def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) -def MonsterAddTestarrayofbools(builder, testarrayofbools): builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) -def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def MonsterAddTestf(builder, testf): builder.PrependFloat32Slot(25, testf, 3.14159) -def MonsterAddTestf2(builder, testf2): builder.PrependFloat32Slot(26, testf2, 3.0) -def MonsterAddTestf3(builder, testf3): builder.PrependFloat32Slot(27, testf3, 0.0) -def MonsterAddTestarrayofstring2(builder, testarrayofstring2): builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) -def MonsterStartTestarrayofstring2Vector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) -def MonsterStartTestarrayofsortedstructVector(builder, numElems): return builder.StartVector(8, numElems, 4) -def MonsterAddFlex(builder, flex): builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) -def MonsterStartFlexVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def MonsterAddTest5(builder, test5): builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) -def MonsterStartTest5Vector(builder, numElems): return builder.StartVector(4, numElems, 2) -def MonsterAddVectorOfLongs(builder, vectorOfLongs): builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) -def MonsterStartVectorOfLongsVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) -def MonsterStartVectorOfDoublesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) -def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) -def MonsterStartVectorOfReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddSingleWeakReference(builder, singleWeakReference): builder.PrependUint64Slot(36, singleWeakReference, 0) -def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) -def MonsterStartVectorOfWeakReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) -def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddCoOwningReference(builder, coOwningReference): builder.PrependUint64Slot(39, coOwningReference, 0) -def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) -def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def MonsterAddNonOwningReference(builder, nonOwningReference): builder.PrependUint64Slot(41, nonOwningReference, 0) -def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) -def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def MonsterAddAnyUniqueType(builder, anyUniqueType): builder.PrependUint8Slot(43, anyUniqueType, 0) -def MonsterAddAnyUnique(builder, anyUnique): builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) -def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): builder.PrependUint8Slot(45, anyAmbiguousType, 0) -def MonsterAddAnyAmbiguous(builder, anyAmbiguous): builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) -def MonsterAddVectorOfEnums(builder, vectorOfEnums): builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) -def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def MonsterAddSignedEnum(builder, signedEnum): builder.PrependInt8Slot(48, signedEnum, -1) -def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) -def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): return builder.StartVector(1, numElems, 1) +def MonsterAddTestempty(builder, testempty): + return builder.PrependUOffsetTRelativeSlot(14, flatbuffers.number_types.UOffsetTFlags.py_type(testempty), 0) + +def MonsterAddTestbool(builder, testbool): + return builder.PrependBoolSlot(15, testbool, 0) + +def MonsterAddTesthashs32Fnv1(builder, testhashs32Fnv1): + return builder.PrependInt32Slot(16, testhashs32Fnv1, 0) + +def MonsterAddTesthashu32Fnv1(builder, testhashu32Fnv1): + return builder.PrependUint32Slot(17, testhashu32Fnv1, 0) + +def MonsterAddTesthashs64Fnv1(builder, testhashs64Fnv1): + return builder.PrependInt64Slot(18, testhashs64Fnv1, 0) + +def MonsterAddTesthashu64Fnv1(builder, testhashu64Fnv1): + return builder.PrependUint64Slot(19, testhashu64Fnv1, 0) + +def MonsterAddTesthashs32Fnv1a(builder, testhashs32Fnv1a): + return builder.PrependInt32Slot(20, testhashs32Fnv1a, 0) + +def MonsterAddTesthashu32Fnv1a(builder, testhashu32Fnv1a): + return builder.PrependUint32Slot(21, testhashu32Fnv1a, 0) + +def MonsterAddTesthashs64Fnv1a(builder, testhashs64Fnv1a): + return builder.PrependInt64Slot(22, testhashs64Fnv1a, 0) + +def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): + return builder.PrependUint64Slot(23, testhashu64Fnv1a, 0) + +def MonsterAddTestarrayofbools(builder, testarrayofbools): + return builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0) + +def MonsterStartTestarrayofboolsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + +def MonsterAddTestf(builder, testf): + return builder.PrependFloat32Slot(25, testf, 3.14159) + +def MonsterAddTestf2(builder, testf2): + return builder.PrependFloat32Slot(26, testf2, 3.0) + +def MonsterAddTestf3(builder, testf3): + return builder.PrependFloat32Slot(27, testf3, 0.0) + +def MonsterAddTestarrayofstring2(builder, testarrayofstring2): + return builder.PrependUOffsetTRelativeSlot(28, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofstring2), 0) + +def MonsterStartTestarrayofstring2Vector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddTestarrayofsortedstruct(builder, testarrayofsortedstruct): + return builder.PrependUOffsetTRelativeSlot(29, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofsortedstruct), 0) + +def MonsterStartTestarrayofsortedstructVector(builder, numElems): + return builder.StartVector(8, numElems, 4) + +def MonsterAddFlex(builder, flex): + return builder.PrependUOffsetTRelativeSlot(30, flatbuffers.number_types.UOffsetTFlags.py_type(flex), 0) + +def MonsterStartFlexVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + +def MonsterAddTest5(builder, test5): + return builder.PrependUOffsetTRelativeSlot(31, flatbuffers.number_types.UOffsetTFlags.py_type(test5), 0) + +def MonsterStartTest5Vector(builder, numElems): + return builder.StartVector(4, numElems, 2) + +def MonsterAddVectorOfLongs(builder, vectorOfLongs): + return builder.PrependUOffsetTRelativeSlot(32, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfLongs), 0) + +def MonsterStartVectorOfLongsVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def MonsterAddVectorOfDoubles(builder, vectorOfDoubles): + return builder.PrependUOffsetTRelativeSlot(33, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfDoubles), 0) + +def MonsterStartVectorOfDoublesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def MonsterAddParentNamespaceTest(builder, parentNamespaceTest): + return builder.PrependUOffsetTRelativeSlot(34, flatbuffers.number_types.UOffsetTFlags.py_type(parentNamespaceTest), 0) + +def MonsterAddVectorOfReferrables(builder, vectorOfReferrables): + return builder.PrependUOffsetTRelativeSlot(35, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfReferrables), 0) + +def MonsterStartVectorOfReferrablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddSingleWeakReference(builder, singleWeakReference): + return builder.PrependUint64Slot(36, singleWeakReference, 0) + +def MonsterAddVectorOfWeakReferences(builder, vectorOfWeakReferences): + return builder.PrependUOffsetTRelativeSlot(37, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfWeakReferences), 0) + +def MonsterStartVectorOfWeakReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def MonsterAddVectorOfStrongReferrables(builder, vectorOfStrongReferrables): + return builder.PrependUOffsetTRelativeSlot(38, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfStrongReferrables), 0) + +def MonsterStartVectorOfStrongReferrablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddCoOwningReference(builder, coOwningReference): + return builder.PrependUint64Slot(39, coOwningReference, 0) + +def MonsterAddVectorOfCoOwningReferences(builder, vectorOfCoOwningReferences): + return builder.PrependUOffsetTRelativeSlot(40, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfCoOwningReferences), 0) + +def MonsterStartVectorOfCoOwningReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def MonsterAddNonOwningReference(builder, nonOwningReference): + return builder.PrependUint64Slot(41, nonOwningReference, 0) + +def MonsterAddVectorOfNonOwningReferences(builder, vectorOfNonOwningReferences): + return builder.PrependUOffsetTRelativeSlot(42, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfNonOwningReferences), 0) + +def MonsterStartVectorOfNonOwningReferencesVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def MonsterAddAnyUniqueType(builder, anyUniqueType): + return builder.PrependUint8Slot(43, anyUniqueType, 0) + +def MonsterAddAnyUnique(builder, anyUnique): + return builder.PrependUOffsetTRelativeSlot(44, flatbuffers.number_types.UOffsetTFlags.py_type(anyUnique), 0) + +def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): + return builder.PrependUint8Slot(45, anyAmbiguousType, 0) + +def MonsterAddAnyAmbiguous(builder, anyAmbiguous): + return builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0) + +def MonsterAddVectorOfEnums(builder, vectorOfEnums): + return builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0) + +def MonsterStartVectorOfEnumsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + +def MonsterAddSignedEnum(builder, signedEnum): + return builder.PrependInt8Slot(48, signedEnum, -1) + +def MonsterAddTestrequirednestedflatbuffer(builder, testrequirednestedflatbuffer): + return builder.PrependUOffsetTRelativeSlot(49, flatbuffers.number_types.UOffsetTFlags.py_type(testrequirednestedflatbuffer), 0) + +def MonsterStartTestrequirednestedflatbufferVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + def MonsterMakeTestrequirednestedflatbufferVectorFromBytes(builder, bytes): builder.StartVector(1, len(bytes), 1) builder.head = builder.head - len(bytes) builder.Bytes[builder.head : builder.head + len(bytes)] = bytes return builder.EndVector() -def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) -def MonsterStartScalarKeySortedTablesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def MonsterAddNativeInline(builder, nativeInline): builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) -def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) -def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): builder.PrependUint64Slot(53, longEnumNormalDefault, 2) -def MonsterAddNanDefault(builder, nanDefault): builder.PrependFloat32Slot(54, nanDefault, float('nan')) -def MonsterAddInfDefault(builder, infDefault): builder.PrependFloat32Slot(55, infDefault, float('inf')) -def MonsterAddPositiveInfDefault(builder, positiveInfDefault): builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) -def MonsterAddInfinityDefault(builder, infinityDefault): builder.PrependFloat32Slot(57, infinityDefault, float('inf')) -def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) -def MonsterAddNegativeInfDefault(builder, negativeInfDefault): builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) -def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) -def MonsterAddDoubleInfDefault(builder, doubleInfDefault): builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) -def MonsterEnd(builder): return builder.EndObject() +def MonsterAddScalarKeySortedTables(builder, scalarKeySortedTables): + return builder.PrependUOffsetTRelativeSlot(50, flatbuffers.number_types.UOffsetTFlags.py_type(scalarKeySortedTables), 0) + +def MonsterStartScalarKeySortedTablesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + +def MonsterAddNativeInline(builder, nativeInline): + return builder.PrependStructSlot(51, flatbuffers.number_types.UOffsetTFlags.py_type(nativeInline), 0) + +def MonsterAddLongEnumNonEnumDefault(builder, longEnumNonEnumDefault): + return builder.PrependUint64Slot(52, longEnumNonEnumDefault, 0) + +def MonsterAddLongEnumNormalDefault(builder, longEnumNormalDefault): + return builder.PrependUint64Slot(53, longEnumNormalDefault, 2) + +def MonsterAddNanDefault(builder, nanDefault): + return builder.PrependFloat32Slot(54, nanDefault, float('nan')) + +def MonsterAddInfDefault(builder, infDefault): + return builder.PrependFloat32Slot(55, infDefault, float('inf')) + +def MonsterAddPositiveInfDefault(builder, positiveInfDefault): + return builder.PrependFloat32Slot(56, positiveInfDefault, float('inf')) + +def MonsterAddInfinityDefault(builder, infinityDefault): + return builder.PrependFloat32Slot(57, infinityDefault, float('inf')) + +def MonsterAddPositiveInfinityDefault(builder, positiveInfinityDefault): + return builder.PrependFloat32Slot(58, positiveInfinityDefault, float('inf')) + +def MonsterAddNegativeInfDefault(builder, negativeInfDefault): + return builder.PrependFloat32Slot(59, negativeInfDefault, float('-inf')) + +def MonsterAddNegativeInfinityDefault(builder, negativeInfinityDefault): + return builder.PrependFloat32Slot(60, negativeInfinityDefault, float('-inf')) + +def MonsterAddDoubleInfDefault(builder, doubleInfDefault): + return builder.PrependFloat64Slot(61, doubleInfDefault, float('inf')) + +def MonsterEnd(builder): + return builder.EndObject() + try: from typing import List, Optional, Union @@ -2455,22 +2651,54 @@ def Vf64IsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26)) return o == 0 -def TypeAliasesStart(builder): builder.StartObject(12) -def TypeAliasesAddI8(builder, i8): builder.PrependInt8Slot(0, i8, 0) -def TypeAliasesAddU8(builder, u8): builder.PrependUint8Slot(1, u8, 0) -def TypeAliasesAddI16(builder, i16): builder.PrependInt16Slot(2, i16, 0) -def TypeAliasesAddU16(builder, u16): builder.PrependUint16Slot(3, u16, 0) -def TypeAliasesAddI32(builder, i32): builder.PrependInt32Slot(4, i32, 0) -def TypeAliasesAddU32(builder, u32): builder.PrependUint32Slot(5, u32, 0) -def TypeAliasesAddI64(builder, i64): builder.PrependInt64Slot(6, i64, 0) -def TypeAliasesAddU64(builder, u64): builder.PrependUint64Slot(7, u64, 0) -def TypeAliasesAddF32(builder, f32): builder.PrependFloat32Slot(8, f32, 0.0) -def TypeAliasesAddF64(builder, f64): builder.PrependFloat64Slot(9, f64, 0.0) -def TypeAliasesAddV8(builder, v8): builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) -def TypeAliasesStartV8Vector(builder, numElems): return builder.StartVector(1, numElems, 1) -def TypeAliasesAddVf64(builder, vf64): builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) -def TypeAliasesStartVf64Vector(builder, numElems): return builder.StartVector(8, numElems, 8) -def TypeAliasesEnd(builder): return builder.EndObject() +def TypeAliasesStart(builder): + return builder.StartObject(12) + +def TypeAliasesAddI8(builder, i8): + return builder.PrependInt8Slot(0, i8, 0) + +def TypeAliasesAddU8(builder, u8): + return builder.PrependUint8Slot(1, u8, 0) + +def TypeAliasesAddI16(builder, i16): + return builder.PrependInt16Slot(2, i16, 0) + +def TypeAliasesAddU16(builder, u16): + return builder.PrependUint16Slot(3, u16, 0) + +def TypeAliasesAddI32(builder, i32): + return builder.PrependInt32Slot(4, i32, 0) + +def TypeAliasesAddU32(builder, u32): + return builder.PrependUint32Slot(5, u32, 0) + +def TypeAliasesAddI64(builder, i64): + return builder.PrependInt64Slot(6, i64, 0) + +def TypeAliasesAddU64(builder, u64): + return builder.PrependUint64Slot(7, u64, 0) + +def TypeAliasesAddF32(builder, f32): + return builder.PrependFloat32Slot(8, f32, 0.0) + +def TypeAliasesAddF64(builder, f64): + return builder.PrependFloat64Slot(9, f64, 0.0) + +def TypeAliasesAddV8(builder, v8): + return builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(v8), 0) + +def TypeAliasesStartV8Vector(builder, numElems): + return builder.StartVector(1, numElems, 1) + +def TypeAliasesAddVf64(builder, vf64): + return builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(vf64), 0) + +def TypeAliasesStartVf64Vector(builder, numElems): + return builder.StartVector(8, numElems, 8) + +def TypeAliasesEnd(builder): + return builder.EndObject() + try: from typing import List diff --git a/tests/optional_scalars/ScalarStuff.py b/tests/optional_scalars/ScalarStuff.py index ca7c253a6470..b75ba22df355 100644 --- a/tests/optional_scalars/ScalarStuff.py +++ b/tests/optional_scalars/ScalarStuff.py @@ -280,121 +280,235 @@ def DefaultEnum(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 1 -def ScalarStuffStart(builder): builder.StartObject(36) +def ScalarStuffStart(builder): + return builder.StartObject(36) + def Start(builder): return ScalarStuffStart(builder) -def ScalarStuffAddJustI8(builder, justI8): builder.PrependInt8Slot(0, justI8, 0) + +def ScalarStuffAddJustI8(builder, justI8): + return builder.PrependInt8Slot(0, justI8, 0) + def AddJustI8(builder, justI8): return ScalarStuffAddJustI8(builder, justI8) -def ScalarStuffAddMaybeI8(builder, maybeI8): builder.PrependInt8Slot(1, maybeI8, None) + +def ScalarStuffAddMaybeI8(builder, maybeI8): + return builder.PrependInt8Slot(1, maybeI8, None) + def AddMaybeI8(builder, maybeI8): return ScalarStuffAddMaybeI8(builder, maybeI8) -def ScalarStuffAddDefaultI8(builder, defaultI8): builder.PrependInt8Slot(2, defaultI8, 42) + +def ScalarStuffAddDefaultI8(builder, defaultI8): + return builder.PrependInt8Slot(2, defaultI8, 42) + def AddDefaultI8(builder, defaultI8): return ScalarStuffAddDefaultI8(builder, defaultI8) -def ScalarStuffAddJustU8(builder, justU8): builder.PrependUint8Slot(3, justU8, 0) + +def ScalarStuffAddJustU8(builder, justU8): + return builder.PrependUint8Slot(3, justU8, 0) + def AddJustU8(builder, justU8): return ScalarStuffAddJustU8(builder, justU8) -def ScalarStuffAddMaybeU8(builder, maybeU8): builder.PrependUint8Slot(4, maybeU8, None) + +def ScalarStuffAddMaybeU8(builder, maybeU8): + return builder.PrependUint8Slot(4, maybeU8, None) + def AddMaybeU8(builder, maybeU8): return ScalarStuffAddMaybeU8(builder, maybeU8) -def ScalarStuffAddDefaultU8(builder, defaultU8): builder.PrependUint8Slot(5, defaultU8, 42) + +def ScalarStuffAddDefaultU8(builder, defaultU8): + return builder.PrependUint8Slot(5, defaultU8, 42) + def AddDefaultU8(builder, defaultU8): return ScalarStuffAddDefaultU8(builder, defaultU8) -def ScalarStuffAddJustI16(builder, justI16): builder.PrependInt16Slot(6, justI16, 0) + +def ScalarStuffAddJustI16(builder, justI16): + return builder.PrependInt16Slot(6, justI16, 0) + def AddJustI16(builder, justI16): return ScalarStuffAddJustI16(builder, justI16) -def ScalarStuffAddMaybeI16(builder, maybeI16): builder.PrependInt16Slot(7, maybeI16, None) + +def ScalarStuffAddMaybeI16(builder, maybeI16): + return builder.PrependInt16Slot(7, maybeI16, None) + def AddMaybeI16(builder, maybeI16): return ScalarStuffAddMaybeI16(builder, maybeI16) -def ScalarStuffAddDefaultI16(builder, defaultI16): builder.PrependInt16Slot(8, defaultI16, 42) + +def ScalarStuffAddDefaultI16(builder, defaultI16): + return builder.PrependInt16Slot(8, defaultI16, 42) + def AddDefaultI16(builder, defaultI16): return ScalarStuffAddDefaultI16(builder, defaultI16) -def ScalarStuffAddJustU16(builder, justU16): builder.PrependUint16Slot(9, justU16, 0) + +def ScalarStuffAddJustU16(builder, justU16): + return builder.PrependUint16Slot(9, justU16, 0) + def AddJustU16(builder, justU16): return ScalarStuffAddJustU16(builder, justU16) -def ScalarStuffAddMaybeU16(builder, maybeU16): builder.PrependUint16Slot(10, maybeU16, None) + +def ScalarStuffAddMaybeU16(builder, maybeU16): + return builder.PrependUint16Slot(10, maybeU16, None) + def AddMaybeU16(builder, maybeU16): return ScalarStuffAddMaybeU16(builder, maybeU16) -def ScalarStuffAddDefaultU16(builder, defaultU16): builder.PrependUint16Slot(11, defaultU16, 42) + +def ScalarStuffAddDefaultU16(builder, defaultU16): + return builder.PrependUint16Slot(11, defaultU16, 42) + def AddDefaultU16(builder, defaultU16): return ScalarStuffAddDefaultU16(builder, defaultU16) -def ScalarStuffAddJustI32(builder, justI32): builder.PrependInt32Slot(12, justI32, 0) + +def ScalarStuffAddJustI32(builder, justI32): + return builder.PrependInt32Slot(12, justI32, 0) + def AddJustI32(builder, justI32): return ScalarStuffAddJustI32(builder, justI32) -def ScalarStuffAddMaybeI32(builder, maybeI32): builder.PrependInt32Slot(13, maybeI32, None) + +def ScalarStuffAddMaybeI32(builder, maybeI32): + return builder.PrependInt32Slot(13, maybeI32, None) + def AddMaybeI32(builder, maybeI32): return ScalarStuffAddMaybeI32(builder, maybeI32) -def ScalarStuffAddDefaultI32(builder, defaultI32): builder.PrependInt32Slot(14, defaultI32, 42) + +def ScalarStuffAddDefaultI32(builder, defaultI32): + return builder.PrependInt32Slot(14, defaultI32, 42) + def AddDefaultI32(builder, defaultI32): return ScalarStuffAddDefaultI32(builder, defaultI32) -def ScalarStuffAddJustU32(builder, justU32): builder.PrependUint32Slot(15, justU32, 0) + +def ScalarStuffAddJustU32(builder, justU32): + return builder.PrependUint32Slot(15, justU32, 0) + def AddJustU32(builder, justU32): return ScalarStuffAddJustU32(builder, justU32) -def ScalarStuffAddMaybeU32(builder, maybeU32): builder.PrependUint32Slot(16, maybeU32, None) + +def ScalarStuffAddMaybeU32(builder, maybeU32): + return builder.PrependUint32Slot(16, maybeU32, None) + def AddMaybeU32(builder, maybeU32): return ScalarStuffAddMaybeU32(builder, maybeU32) -def ScalarStuffAddDefaultU32(builder, defaultU32): builder.PrependUint32Slot(17, defaultU32, 42) + +def ScalarStuffAddDefaultU32(builder, defaultU32): + return builder.PrependUint32Slot(17, defaultU32, 42) + def AddDefaultU32(builder, defaultU32): return ScalarStuffAddDefaultU32(builder, defaultU32) -def ScalarStuffAddJustI64(builder, justI64): builder.PrependInt64Slot(18, justI64, 0) + +def ScalarStuffAddJustI64(builder, justI64): + return builder.PrependInt64Slot(18, justI64, 0) + def AddJustI64(builder, justI64): return ScalarStuffAddJustI64(builder, justI64) -def ScalarStuffAddMaybeI64(builder, maybeI64): builder.PrependInt64Slot(19, maybeI64, None) + +def ScalarStuffAddMaybeI64(builder, maybeI64): + return builder.PrependInt64Slot(19, maybeI64, None) + def AddMaybeI64(builder, maybeI64): return ScalarStuffAddMaybeI64(builder, maybeI64) -def ScalarStuffAddDefaultI64(builder, defaultI64): builder.PrependInt64Slot(20, defaultI64, 42) + +def ScalarStuffAddDefaultI64(builder, defaultI64): + return builder.PrependInt64Slot(20, defaultI64, 42) + def AddDefaultI64(builder, defaultI64): return ScalarStuffAddDefaultI64(builder, defaultI64) -def ScalarStuffAddJustU64(builder, justU64): builder.PrependUint64Slot(21, justU64, 0) + +def ScalarStuffAddJustU64(builder, justU64): + return builder.PrependUint64Slot(21, justU64, 0) + def AddJustU64(builder, justU64): return ScalarStuffAddJustU64(builder, justU64) -def ScalarStuffAddMaybeU64(builder, maybeU64): builder.PrependUint64Slot(22, maybeU64, None) + +def ScalarStuffAddMaybeU64(builder, maybeU64): + return builder.PrependUint64Slot(22, maybeU64, None) + def AddMaybeU64(builder, maybeU64): return ScalarStuffAddMaybeU64(builder, maybeU64) -def ScalarStuffAddDefaultU64(builder, defaultU64): builder.PrependUint64Slot(23, defaultU64, 42) + +def ScalarStuffAddDefaultU64(builder, defaultU64): + return builder.PrependUint64Slot(23, defaultU64, 42) + def AddDefaultU64(builder, defaultU64): return ScalarStuffAddDefaultU64(builder, defaultU64) -def ScalarStuffAddJustF32(builder, justF32): builder.PrependFloat32Slot(24, justF32, 0.0) + +def ScalarStuffAddJustF32(builder, justF32): + return builder.PrependFloat32Slot(24, justF32, 0.0) + def AddJustF32(builder, justF32): return ScalarStuffAddJustF32(builder, justF32) -def ScalarStuffAddMaybeF32(builder, maybeF32): builder.PrependFloat32Slot(25, maybeF32, None) + +def ScalarStuffAddMaybeF32(builder, maybeF32): + return builder.PrependFloat32Slot(25, maybeF32, None) + def AddMaybeF32(builder, maybeF32): return ScalarStuffAddMaybeF32(builder, maybeF32) -def ScalarStuffAddDefaultF32(builder, defaultF32): builder.PrependFloat32Slot(26, defaultF32, 42.0) + +def ScalarStuffAddDefaultF32(builder, defaultF32): + return builder.PrependFloat32Slot(26, defaultF32, 42.0) + def AddDefaultF32(builder, defaultF32): return ScalarStuffAddDefaultF32(builder, defaultF32) -def ScalarStuffAddJustF64(builder, justF64): builder.PrependFloat64Slot(27, justF64, 0.0) + +def ScalarStuffAddJustF64(builder, justF64): + return builder.PrependFloat64Slot(27, justF64, 0.0) + def AddJustF64(builder, justF64): return ScalarStuffAddJustF64(builder, justF64) -def ScalarStuffAddMaybeF64(builder, maybeF64): builder.PrependFloat64Slot(28, maybeF64, None) + +def ScalarStuffAddMaybeF64(builder, maybeF64): + return builder.PrependFloat64Slot(28, maybeF64, None) + def AddMaybeF64(builder, maybeF64): return ScalarStuffAddMaybeF64(builder, maybeF64) -def ScalarStuffAddDefaultF64(builder, defaultF64): builder.PrependFloat64Slot(29, defaultF64, 42.0) + +def ScalarStuffAddDefaultF64(builder, defaultF64): + return builder.PrependFloat64Slot(29, defaultF64, 42.0) + def AddDefaultF64(builder, defaultF64): return ScalarStuffAddDefaultF64(builder, defaultF64) -def ScalarStuffAddJustBool(builder, justBool): builder.PrependBoolSlot(30, justBool, 0) + +def ScalarStuffAddJustBool(builder, justBool): + return builder.PrependBoolSlot(30, justBool, 0) + def AddJustBool(builder, justBool): return ScalarStuffAddJustBool(builder, justBool) -def ScalarStuffAddMaybeBool(builder, maybeBool): builder.PrependBoolSlot(31, maybeBool, None) + +def ScalarStuffAddMaybeBool(builder, maybeBool): + return builder.PrependBoolSlot(31, maybeBool, None) + def AddMaybeBool(builder, maybeBool): return ScalarStuffAddMaybeBool(builder, maybeBool) -def ScalarStuffAddDefaultBool(builder, defaultBool): builder.PrependBoolSlot(32, defaultBool, 1) + +def ScalarStuffAddDefaultBool(builder, defaultBool): + return builder.PrependBoolSlot(32, defaultBool, 1) + def AddDefaultBool(builder, defaultBool): return ScalarStuffAddDefaultBool(builder, defaultBool) -def ScalarStuffAddJustEnum(builder, justEnum): builder.PrependInt8Slot(33, justEnum, 0) + +def ScalarStuffAddJustEnum(builder, justEnum): + return builder.PrependInt8Slot(33, justEnum, 0) + def AddJustEnum(builder, justEnum): return ScalarStuffAddJustEnum(builder, justEnum) -def ScalarStuffAddMaybeEnum(builder, maybeEnum): builder.PrependInt8Slot(34, maybeEnum, None) + +def ScalarStuffAddMaybeEnum(builder, maybeEnum): + return builder.PrependInt8Slot(34, maybeEnum, None) + def AddMaybeEnum(builder, maybeEnum): return ScalarStuffAddMaybeEnum(builder, maybeEnum) -def ScalarStuffAddDefaultEnum(builder, defaultEnum): builder.PrependInt8Slot(35, defaultEnum, 1) + +def ScalarStuffAddDefaultEnum(builder, defaultEnum): + return builder.PrependInt8Slot(35, defaultEnum, 1) + def AddDefaultEnum(builder, defaultEnum): return ScalarStuffAddDefaultEnum(builder, defaultEnum) -def ScalarStuffEnd(builder): return builder.EndObject() + +def ScalarStuffEnd(builder): + return builder.EndObject() + def End(builder): return ScalarStuffEnd(builder) + class ScalarStuffT(object): # ScalarStuffT