diff options
author | qazwsxedcrfvtg14 <qazwsxedcrfvtg14@gmail.com> | 2022-02-11 03:10:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 11:10:47 -0800 |
commit | b3006913369e0a7550795e477011ac5bebb93497 (patch) | |
tree | 8521f25e005463483570d403e290f53b4c564d9a | |
parent | faadbc10ea4b77bc57960696ef0d1d053536c68a (diff) | |
download | flatbuffers-b3006913369e0a7550795e477011ac5bebb93497.tar.gz flatbuffers-b3006913369e0a7550795e477011ac5bebb93497.tar.bz2 flatbuffers-b3006913369e0a7550795e477011ac5bebb93497.zip |
Add reflection support for python (#7026)
We already have the reflection.fbs file and the flatbuffers
python language support.
Adding this feature would give the python developers the
ability to parse the flatbuffers schema and write some tools.
Co-authored-by: Derek Bailey <derekbailey@google.com>
-rw-r--r-- | python/flatbuffers/reflection/AdvancedFeatures.py | 10 | ||||
-rw-r--r-- | python/flatbuffers/reflection/BaseType.py | 24 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Enum.py | 169 | ||||
-rw-r--r-- | python/flatbuffers/reflection/EnumVal.py | 96 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Field.py | 208 | ||||
-rw-r--r-- | python/flatbuffers/reflection/KeyValue.py | 56 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Object.py | 175 | ||||
-rw-r--r-- | python/flatbuffers/reflection/RPCCall.py | 131 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Schema.py | 206 | ||||
-rw-r--r-- | python/flatbuffers/reflection/SchemaFile.py | 77 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Service.py | 145 | ||||
-rw-r--r-- | python/flatbuffers/reflection/Type.py | 98 | ||||
-rw-r--r-- | python/flatbuffers/reflection/__init__.py | 0 | ||||
-rwxr-xr-x | scripts/generate_code.py | 41 |
14 files changed, 1420 insertions, 16 deletions
diff --git a/python/flatbuffers/reflection/AdvancedFeatures.py b/python/flatbuffers/reflection/AdvancedFeatures.py new file mode 100644 index 00000000..1c552588 --- /dev/null +++ b/python/flatbuffers/reflection/AdvancedFeatures.py @@ -0,0 +1,10 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +# New schema language features that are not supported by old code generators. +class AdvancedFeatures(object): + AdvancedArrayFeatures = 1 + AdvancedUnionFeatures = 2 + OptionalScalars = 4 + DefaultVectorsAndStrings = 8 diff --git a/python/flatbuffers/reflection/BaseType.py b/python/flatbuffers/reflection/BaseType.py new file mode 100644 index 00000000..2665b4a9 --- /dev/null +++ b/python/flatbuffers/reflection/BaseType.py @@ -0,0 +1,24 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +class BaseType(object): + None_ = 0 + UType = 1 + Bool = 2 + Byte = 3 + UByte = 4 + Short = 5 + UShort = 6 + Int = 7 + UInt = 8 + Long = 9 + ULong = 10 + Float = 11 + Double = 12 + String = 13 + Vector = 14 + Obj = 15 + Union = 16 + Array = 17 + MaxBaseType = 18 diff --git a/python/flatbuffers/reflection/Enum.py b/python/flatbuffers/reflection/Enum.py new file mode 100644 index 00000000..b27e4102 --- /dev/null +++ b/python/flatbuffers/reflection/Enum.py @@ -0,0 +1,169 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Enum(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Enum() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsEnum(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def EnumBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Enum + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Enum + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Enum + def Values(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.EnumVal import EnumVal + obj = EnumVal() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Enum + def ValuesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Enum + def ValuesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + return o == 0 + + # Enum + def IsUnion(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Enum + def UnderlyingType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Type import Type + obj = Type() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Enum + def Attributes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.KeyValue import KeyValue + obj = KeyValue() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Enum + def AttributesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Enum + def AttributesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + return o == 0 + + # Enum + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Enum + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Enum + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + return o == 0 + + # File that this Enum is declared in. + # Enum + def DeclarationFile(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + +def EnumStart(builder): 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 AddName(builder, name): + return EnumAddName(builder, name) +def EnumAddValues(builder, values): 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 StartValuesVector(builder, numElems): + return EnumStartValuesVector(builder, numElems) +def EnumAddIsUnion(builder, isUnion): 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 AddUnderlyingType(builder, underlyingType): + return EnumAddUnderlyingType(builder, underlyingType) +def EnumAddAttributes(builder, attributes): 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 StartAttributesVector(builder, numElems): + return EnumStartAttributesVector(builder, numElems) +def EnumAddDocumentation(builder, documentation): 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 StartDocumentationVector(builder, numElems): + return EnumStartDocumentationVector(builder, numElems) +def EnumAddDeclarationFile(builder, declarationFile): 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 End(builder): + return EnumEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/EnumVal.py b/python/flatbuffers/reflection/EnumVal.py new file mode 100644 index 00000000..62a32dc7 --- /dev/null +++ b/python/flatbuffers/reflection/EnumVal.py @@ -0,0 +1,96 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class EnumVal(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = EnumVal() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsEnumVal(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def EnumValBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # EnumVal + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # EnumVal + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # EnumVal + def Value(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos) + return 0 + + # EnumVal + def UnionType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Type import Type + obj = Type() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # EnumVal + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # EnumVal + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # EnumVal + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + return o == 0 + +def EnumValStart(builder): builder.StartObject(5) +def Start(builder): + return EnumValStart(builder) +def EnumValAddName(builder, name): 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 AddValue(builder, value): + return EnumValAddValue(builder, value) +def EnumValAddUnionType(builder, unionType): 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 AddDocumentation(builder, documentation): + return EnumValAddDocumentation(builder, documentation) +def EnumValStartDocumentationVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def StartDocumentationVector(builder, numElems): + return EnumValStartDocumentationVector(builder, numElems) +def EnumValEnd(builder): return builder.EndObject() +def End(builder): + return EnumValEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/Field.py b/python/flatbuffers/reflection/Field.py new file mode 100644 index 00000000..01b52808 --- /dev/null +++ b/python/flatbuffers/reflection/Field.py @@ -0,0 +1,208 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Field(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Field() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsField(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def FieldBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Field + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Field + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Field + def Type(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Type import Type + obj = Type() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Field + def Id(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) + return 0 + + # Field + def Offset(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) + return 0 + + # Field + def DefaultInteger(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos) + return 0 + + # Field + def DefaultReal(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos) + return 0.0 + + # Field + def Deprecated(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Field + def Required(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Field + def Key(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Field + def Attributes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.KeyValue import KeyValue + obj = KeyValue() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Field + def AttributesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Field + def AttributesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22)) + return o == 0 + + # Field + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(24)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Field + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(24)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Field + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(24)) + return o == 0 + + # Field + def Optional(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Number of padding octets to always add after this field. Structs only. + # Field + def Padding(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(28)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) + return 0 + +def FieldStart(builder): 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 AddName(builder, name): + return FieldAddName(builder, name) +def FieldAddType(builder, type): 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 AddId(builder, id): + return FieldAddId(builder, id) +def FieldAddOffset(builder, offset): builder.PrependUint16Slot(3, offset, 0) +def AddOffset(builder, offset): + return FieldAddOffset(builder, offset) +def FieldAddDefaultInteger(builder, defaultInteger): builder.PrependInt64Slot(4, defaultInteger, 0) +def AddDefaultInteger(builder, defaultInteger): + return FieldAddDefaultInteger(builder, defaultInteger) +def FieldAddDefaultReal(builder, defaultReal): builder.PrependFloat64Slot(5, defaultReal, 0.0) +def AddDefaultReal(builder, defaultReal): + return FieldAddDefaultReal(builder, defaultReal) +def FieldAddDeprecated(builder, deprecated): builder.PrependBoolSlot(6, deprecated, 0) +def AddDeprecated(builder, deprecated): + return FieldAddDeprecated(builder, deprecated) +def FieldAddRequired(builder, required): builder.PrependBoolSlot(7, required, 0) +def AddRequired(builder, required): + return FieldAddRequired(builder, required) +def FieldAddKey(builder, key): 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 AddAttributes(builder, attributes): + return FieldAddAttributes(builder, attributes) +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 AddDocumentation(builder, documentation): + return FieldAddDocumentation(builder, documentation) +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 AddOptional(builder, optional): + return FieldAddOptional(builder, optional) +def FieldAddPadding(builder, padding): builder.PrependUint16Slot(12, padding, 0) +def AddPadding(builder, padding): + return FieldAddPadding(builder, padding) +def FieldEnd(builder): return builder.EndObject() +def End(builder): + return FieldEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/KeyValue.py b/python/flatbuffers/reflection/KeyValue.py new file mode 100644 index 00000000..dde37dff --- /dev/null +++ b/python/flatbuffers/reflection/KeyValue.py @@ -0,0 +1,56 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class KeyValue(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = KeyValue() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsKeyValue(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def KeyValueBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # KeyValue + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # KeyValue + def Key(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # KeyValue + def Value(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + +def KeyValueStart(builder): 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 AddKey(builder, key): + return KeyValueAddKey(builder, key) +def KeyValueAddValue(builder, value): 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 End(builder): + return KeyValueEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/Object.py b/python/flatbuffers/reflection/Object.py new file mode 100644 index 00000000..598927c8 --- /dev/null +++ b/python/flatbuffers/reflection/Object.py @@ -0,0 +1,175 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Object(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Object() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsObject(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def ObjectBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Object + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Object + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Object + def Fields(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.Field import Field + obj = Field() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Object + def FieldsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Object + def FieldsIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + return o == 0 + + # Object + def IsStruct(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + + # Object + def Minalign(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Object + def Bytesize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Object + def Attributes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.KeyValue import KeyValue + obj = KeyValue() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Object + def AttributesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Object + def AttributesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + return o == 0 + + # Object + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Object + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Object + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + return o == 0 + + # File that this Object is declared in. + # Object + def DeclarationFile(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + +def ObjectStart(builder): 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 AddName(builder, name): + return ObjectAddName(builder, name) +def ObjectAddFields(builder, fields): 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 StartFieldsVector(builder, numElems): + return ObjectStartFieldsVector(builder, numElems) +def ObjectAddIsStruct(builder, isStruct): builder.PrependBoolSlot(2, isStruct, 0) +def AddIsStruct(builder, isStruct): + return ObjectAddIsStruct(builder, isStruct) +def ObjectAddMinalign(builder, minalign): builder.PrependInt32Slot(3, minalign, 0) +def AddMinalign(builder, minalign): + return ObjectAddMinalign(builder, minalign) +def ObjectAddBytesize(builder, bytesize): 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 AddAttributes(builder, attributes): + return ObjectAddAttributes(builder, attributes) +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 AddDocumentation(builder, documentation): + return ObjectAddDocumentation(builder, documentation) +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 AddDeclarationFile(builder, declarationFile): + return ObjectAddDeclarationFile(builder, declarationFile) +def ObjectEnd(builder): return builder.EndObject() +def End(builder): + return ObjectEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/RPCCall.py b/python/flatbuffers/reflection/RPCCall.py new file mode 100644 index 00000000..9fdbf468 --- /dev/null +++ b/python/flatbuffers/reflection/RPCCall.py @@ -0,0 +1,131 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class RPCCall(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = RPCCall() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsRPCCall(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def RPCCallBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # RPCCall + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # RPCCall + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # RPCCall + def Request(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Object import Object + obj = Object() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # RPCCall + def Response(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Object import Object + obj = Object() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # RPCCall + def Attributes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.KeyValue import KeyValue + obj = KeyValue() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # RPCCall + def AttributesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # RPCCall + def AttributesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + return o == 0 + + # RPCCall + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # RPCCall + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # RPCCall + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + return o == 0 + +def RPCCallStart(builder): 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 AddName(builder, name): + return RPCCallAddName(builder, name) +def RPCCallAddRequest(builder, request): 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 AddResponse(builder, response): + return RPCCallAddResponse(builder, response) +def RPCCallAddAttributes(builder, attributes): 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 StartAttributesVector(builder, numElems): + return RPCCallStartAttributesVector(builder, numElems) +def RPCCallAddDocumentation(builder, documentation): 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 StartDocumentationVector(builder, numElems): + return RPCCallStartDocumentationVector(builder, numElems) +def RPCCallEnd(builder): return builder.EndObject() +def End(builder): + return RPCCallEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/Schema.py b/python/flatbuffers/reflection/Schema.py new file mode 100644 index 00000000..df2f072f --- /dev/null +++ b/python/flatbuffers/reflection/Schema.py @@ -0,0 +1,206 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Schema(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Schema() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsSchema(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def SchemaBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Schema + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Schema + def Objects(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.Object import Object + obj = Object() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Schema + def ObjectsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Schema + def ObjectsIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + return o == 0 + + # Schema + def Enums(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.Enum import Enum + obj = Enum() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Schema + def EnumsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Schema + def EnumsIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + return o == 0 + + # Schema + def FileIdent(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Schema + def FileExt(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Schema + def RootTable(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from reflection.Object import Object + obj = Object() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Schema + def Services(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.Service import Service + obj = Service() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Schema + def ServicesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Schema + def ServicesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + return o == 0 + + # Schema + def AdvancedFeatures(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos) + return 0 + + # All the files used in this compilation. Files are relative to where + # flatc was invoked. + # Schema + def FbsFiles(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.SchemaFile import SchemaFile + obj = SchemaFile() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Schema + def FbsFilesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Schema + def FbsFilesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + return o == 0 + +def SchemaStart(builder): 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 AddObjects(builder, objects): + return SchemaAddObjects(builder, objects) +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 AddEnums(builder, enums): + return SchemaAddEnums(builder, enums) +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 AddFileIdent(builder, fileIdent): + return SchemaAddFileIdent(builder, fileIdent) +def SchemaAddFileExt(builder, fileExt): 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 AddRootTable(builder, rootTable): + return SchemaAddRootTable(builder, rootTable) +def SchemaAddServices(builder, services): 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 StartServicesVector(builder, numElems): + return SchemaStartServicesVector(builder, numElems) +def SchemaAddAdvancedFeatures(builder, advancedFeatures): 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 AddFbsFiles(builder, fbsFiles): + return SchemaAddFbsFiles(builder, fbsFiles) +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 End(builder): + return SchemaEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/SchemaFile.py b/python/flatbuffers/reflection/SchemaFile.py new file mode 100644 index 00000000..890fd3b5 --- /dev/null +++ b/python/flatbuffers/reflection/SchemaFile.py @@ -0,0 +1,77 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +# File specific information. +# Symbols declared within a file may be recovered by iterating over all +# symbols and examining the `declaration_file` field. +class SchemaFile(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SchemaFile() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsSchemaFile(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def SchemaFileBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # SchemaFile + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Filename, relative to project root. + # SchemaFile + def Filename(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Names of included files, relative to project root. + # SchemaFile + def IncludedFilenames(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # SchemaFile + def IncludedFilenamesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # SchemaFile + def IncludedFilenamesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + return o == 0 + +def SchemaFileStart(builder): 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 AddFilename(builder, filename): + return SchemaFileAddFilename(builder, filename) +def SchemaFileAddIncludedFilenames(builder, includedFilenames): 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 StartIncludedFilenamesVector(builder, numElems): + return SchemaFileStartIncludedFilenamesVector(builder, numElems) +def SchemaFileEnd(builder): return builder.EndObject() +def End(builder): + return SchemaFileEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/Service.py b/python/flatbuffers/reflection/Service.py new file mode 100644 index 00000000..d4f1a6a8 --- /dev/null +++ b/python/flatbuffers/reflection/Service.py @@ -0,0 +1,145 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Service(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Service() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsService(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def ServiceBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Service + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Service + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + + # Service + def Calls(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.RPCCall import RPCCall + obj = RPCCall() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Service + def CallsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Service + def CallsIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + return o == 0 + + # Service + def Attributes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from reflection.KeyValue import KeyValue + obj = KeyValue() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Service + def AttributesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Service + def AttributesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + return o == 0 + + # Service + def Documentation(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Service + def DocumentationLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Service + def DocumentationIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + return o == 0 + + # File that this Service is declared in. + # Service + def DeclarationFile(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return None + +def ServiceStart(builder): 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 AddName(builder, name): + return ServiceAddName(builder, name) +def ServiceAddCalls(builder, calls): 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 StartCallsVector(builder, numElems): + return ServiceStartCallsVector(builder, numElems) +def ServiceAddAttributes(builder, attributes): 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 StartAttributesVector(builder, numElems): + return ServiceStartAttributesVector(builder, numElems) +def ServiceAddDocumentation(builder, documentation): 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 StartDocumentationVector(builder, numElems): + return ServiceStartDocumentationVector(builder, numElems) +def ServiceAddDeclarationFile(builder, declarationFile): 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 End(builder): + return ServiceEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/Type.py b/python/flatbuffers/reflection/Type.py new file mode 100644 index 00000000..d606ab9a --- /dev/null +++ b/python/flatbuffers/reflection/Type.py @@ -0,0 +1,98 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: reflection + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class Type(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Type() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsType(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def TypeBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed) + + # Type + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Type + def BaseType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Type + def Element(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Type + def Index(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return -1 + + # Type + def FixedLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos) + return 0 + + # The size (octets) of the `base_type` field. + # Type + def BaseSize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) + return 4 + + # The size (octets) of the `element` field, if present. + # Type + def ElementSize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) + return 0 + +def TypeStart(builder): builder.StartObject(6) +def Start(builder): + return TypeStart(builder) +def TypeAddBaseType(builder, baseType): builder.PrependInt8Slot(0, baseType, 0) +def AddBaseType(builder, baseType): + return TypeAddBaseType(builder, baseType) +def TypeAddElement(builder, element): builder.PrependInt8Slot(1, element, 0) +def AddElement(builder, element): + return TypeAddElement(builder, element) +def TypeAddIndex(builder, index): builder.PrependInt32Slot(2, index, -1) +def AddIndex(builder, index): + return TypeAddIndex(builder, index) +def TypeAddFixedLength(builder, fixedLength): builder.PrependUint16Slot(3, fixedLength, 0) +def AddFixedLength(builder, fixedLength): + return TypeAddFixedLength(builder, fixedLength) +def TypeAddBaseSize(builder, baseSize): builder.PrependUint32Slot(4, baseSize, 4) +def AddBaseSize(builder, baseSize): + return TypeAddBaseSize(builder, baseSize) +def TypeAddElementSize(builder, elementSize): builder.PrependUint32Slot(5, elementSize, 0) +def AddElementSize(builder, elementSize): + return TypeAddElementSize(builder, elementSize) +def TypeEnd(builder): return builder.EndObject() +def End(builder): + return TypeEnd(builder)
\ No newline at end of file diff --git a/python/flatbuffers/reflection/__init__.py b/python/flatbuffers/reflection/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/python/flatbuffers/reflection/__init__.py diff --git a/scripts/generate_code.py b/scripts/generate_code.py index 7a20eddd..48d317e6 100755 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -82,6 +82,24 @@ def flatc( result = subprocess.run(cmd, cwd=str(cwd), check=True) +# Generate the code for flatbuffers reflection schema +def flatc_reflection(options, location, target): + full_options = ["--no-prefix"] + options + temp_dir = ".tmp" + flatc( + full_options, + prefix=temp_dir, + schema="reflection.fbs", + cwd=reflection_path, + ) + new_reflection_path = Path(reflection_path, temp_dir, target) + original_reflection_path = Path(root_path, location, target) + if not filecmp.cmp(str(new_reflection_path), str(original_reflection_path)): + shutil.rmtree(str(original_reflection_path)) + shutil.move(str(new_reflection_path), str(original_reflection_path)) + shutil.rmtree(str(Path(reflection_path, temp_dir))) + + # Glob a pattern relative to file path def glob(path, pattern): return [str(p) for p in path.glob(pattern)] @@ -422,22 +440,13 @@ flatc( ) # Reflection + # Skip generating the reflection if told too, as we run this script after # building flatc which uses the reflection_generated.h itself. if not args.skip_gen_reflection: - temp_dir = ".tmp" - flatc( - ["-c", "--cpp-std", "c++0x", "--no-prefix"], - prefix=temp_dir, - schema="reflection.fbs", - cwd=reflection_path, - ) - new_reflection_file = Path( - reflection_path, temp_dir, "reflection_generated.h" - ) - original_reflection_file = Path( - root_path, "include/flatbuffers/reflection_generated.h" - ) - if not filecmp.cmp(str(new_reflection_file), str(original_reflection_file)): - shutil.move(str(new_reflection_file), str(original_reflection_file)) - shutil.rmtree(str(Path(reflection_path, temp_dir))) + # C++ Reflection + flatc_reflection(["-c", "--cpp-std", "c++0x"], "include/flatbuffers", + "reflection_generated.h") + +# Python Reflection +flatc_reflection(["-p"], "python/flatbuffers", "reflection")
\ No newline at end of file |