From 316d7c20898ce95eacbbca734448538b66d6785f Mon Sep 17 00:00:00 2001 From: mustiikhalil Date: Sat, 25 Jan 2020 01:55:57 +0300 Subject: Creates a flatbuffers validation function + small fix (#5725) --- src/idl_gen_swift.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/idl_gen_swift.cpp') 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 {"; - 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) -- cgit v1.2.3