diff options
author | mustiikhalil <mustii@mmk.one> | 2020-01-25 01:55:57 +0300 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-01-24 14:55:57 -0800 |
commit | 316d7c20898ce95eacbbca734448538b66d6785f (patch) | |
tree | ede18dc2e0faa25400ce08a3adbf248c56c6e590 /src/idl_gen_swift.cpp | |
parent | 47026ea6ba0e3ea8c4f4ab47de880cb5665ee1b6 (diff) | |
download | flatbuffers-316d7c20898ce95eacbbca734448538b66d6785f.tar.gz flatbuffers-316d7c20898ce95eacbbca734448538b66d6785f.tar.bz2 flatbuffers-316d7c20898ce95eacbbca734448538b66d6785f.zip |
Creates a flatbuffers validation function + small fix (#5725)
Diffstat (limited to 'src/idl_gen_swift.cpp')
-rw-r--r-- | src/idl_gen_swift.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/idl_gen_swift.cpp b/src/idl_gen_swift.cpp index 4f4dd5b6..03ac2f21 100644 --- a/src/idl_gen_swift.cpp +++ b/src/idl_gen_swift.cpp @@ -164,8 +164,9 @@ class SwiftGenerator : public BaseGenerator { code_.SetValue("PROTOCOL", struct_def.fixed ? "Readable" : "FlatBufferObject"); code_.SetValue("OBJECTTYPE", struct_def.fixed ? "Struct" : "Table"); - code_ += "public struct {{STRUCTNAME}}: {{PROTOCOL}} {"; - code_ += "\tprivate var {{ACCESS}}: {{OBJECTTYPE}}"; + code_ += "public struct {{STRUCTNAME}}: {{PROTOCOL}} {\n"; + code_ += ValidateFunc(); + code_ += "\n\tprivate var {{ACCESS}}: {{OBJECTTYPE}}"; if (struct_def.fixed) { code_.SetValue("BYTESIZE", NumToString(struct_def.bytesize)); code_.SetValue("MINALIGN", NumToString(struct_def.minalign)); @@ -256,10 +257,10 @@ class SwiftGenerator : public BaseGenerator { create_func_header.substr(0, create_func_header.size() - 2) + "\\"; code_ += ") -> Offset<UOffset> {"; - code_ += "\t\tlet start = {{STRUCTNAME}}.start{{STRUCTNAME}}(fbb)"; + code_ += "\t\tlet __start = {{STRUCTNAME}}.start{{STRUCTNAME}}(fbb)"; if (should_generate_create) code_ += create_func_body.substr(0, create_func_body.size() - 1); - code_ += "\t\treturn {{STRUCTNAME}}.end{{STRUCTNAME}}(fbb, start: start)"; + code_ += "\t\treturn {{STRUCTNAME}}.end{{STRUCTNAME}}(fbb, start: __start)"; code_ += "\t}"; std::string spacing = "\t\t"; @@ -678,6 +679,10 @@ class SwiftGenerator : public BaseGenerator { return "{{VALUETYPE}}(rawValue: " + GenReader("BASEVALUE", at) + ") "; } + std::string ValidateFunc() { + return "\tstatic func validateVersion() { FlatBuffersVersion_1_11_1() }"; + } + std::string GenType(const Type &type) const { return IsScalar(type.base_type) ? GenTypeBasic(type) |