FlatbuffersVerifierTests

/*
final class FlatbuffersVerifierTests: XCTestCase {
  lazy var validStorage: ByteBuffer.Storage = ByteBuffer.Storage(
    count: Int(FlatBufferMaxSize) - 1,
    alignment: 1)
  lazy var errorStorage: ByteBuffer.Storage = ByteBuffer.Storage(
    count: Int(FlatBufferMaxSize) + 1,
    alignment: 1)
  var buffer: ByteBuffer!
  var validFlatbuffersObject: ByteBuffer!
  var invalidFlatbuffersObject: ByteBuffer!
  override func setUp() {
    // swiftformat:disable all
    buffer = ByteBuffer(initialSize: 32)
    add(buffer: &buffer, v: 4, p: 16)
    add(buffer: &buffer, v: 4, p: 20)
    validFlatbuffersObject = ByteBuffer(bytes: [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    invalidFlatbuffersObject = ByteBuffer(bytes: [0, 48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    // swiftformat:enable all
  }
  func testVeriferInitPassing() {
    var buffer = ByteBuffer(initialSize: 0)
    buffer._storage = validStorage
    XCTAssertNoThrow(try Verifier(buffer: &buffer))
  }
  func testVeriferInitFailing() {
    var buffer = ByteBuffer(initialSize: 0)
    buffer._storage = errorStorage
    XCTAssertThrowsError(try Verifier(buffer: &buffer))
  }
  func testVerifierCheckAlignment() {
    var verifier = try! Verifier(buffer: &buffer)
    do {
      try verifier.isAligned(position: 20, type: Int.self)
    } catch {
      XCTAssertEqual(
        error as? FlatbuffersErrors,
        .missAlignedPointer(position: 20, type: "Int"))
    }
    XCTAssertNoThrow(try verifier.isAligned(position: 16, type: Int.self))
    var newVerifer = try! Verifier(buffer: &buffer, checkAlignment: false)
    XCTAssertNoThrow(try newVerifer.isAligned(position: 16, type: Int.self))
  }
  func testRangeInBuffer() {
    var verifier = try! Verifier(buffer: &buffer)
    let size = MemoryLayout<Int64>.size
    XCTAssertNoThrow(try verifier.rangeInBuffer(position: 24, size: size))
    XCTAssertThrowsError(try verifier.rangeInBuffer(position: 26, size: size))
    XCTAssertThrowsError(try verifier.rangeInBuffer(position: 26, size: size))
    XCTAssertThrowsError(try verifier.rangeInBuffer(position: 30, size: size))
    XCTAssertThrowsError(try verifier.rangeInBuffer(position: 32, size: size))
    XCTAssertThrowsError(try verifier.rangeInBuffer(position: 34, size: size))
    verifier = try! Verifier(
      buffer: &buffer,
      options: .init(maxDepth: 0, maxTableCount: 0, maxApparentSize: 4))
    do {
      try verifier.rangeInBuffer(position: 24, size: size)
    } catch {
      XCTAssertEqual(
        error as! FlatbuffersErrors,
        .apparentSizeTooLarge)
    }
  }
  func testPositionInBuffer() {
    var verifier = try! Verifier(buffer: &buffer)
    XCTAssertNoThrow(try verifier.inBuffer(position: 0, of: Int64.self))
    XCTAssertNoThrow(try verifier.inBuffer(position: 24, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: -9, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 25, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 26, of: Int32.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 26, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 30, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 32, of: Int64.self))
    XCTAssertThrowsError(try verifier.inBuffer(position: 34, of: Int64.self))
  }
  func testVisitTable() {
    var verifier = try! Verifier(buffer: &validFlatbuffersObject)
    XCTAssertNoThrow(try verifier.visitTable(at: 48))
    verifier.reset()
  }
  func testTableVerifier() {
    var verifier = try! Verifier(buffer: &validFlatbuffersObject)
    var tableVerifer = try! verifier.visitTable(at: 48)
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 4,
      fieldName: "Vec",
      required: false,
      type: Vec3.self))
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 8,
      fieldName: "hp",
      required: false,
      type: Int16.self))
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 10,
      fieldName: "name",
      required: true,
      type: ForwardOffset<String>.self))
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 14,
      fieldName: "inventory",
      required: false,
      type: ForwardOffset<Vector<UInt8, UInt8>>.self))
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 22,
      fieldName: "test4",
      required: false,
      type: ForwardOffset<Vector<MyGame_Example_Test, MyGame_Example_Test>>
        .self))
    XCTAssertNoThrow(try tableVerifer.visit(
      field: 24,
      fieldName: "Vector of strings",
      required: false,
      type: ForwardOffset<Vector<ForwardOffset<String>, String>>.self))
    do {
      try tableVerifer.visit(
        field: 13,
        fieldName: "notvalid",
        required: false,
        type: Int16.self)
    } catch {
      XCTAssertEqual(
        error as! FlatbuffersErrors,
        .missAlignedPointer(position: 25, type: "UInt16"))
    }
    do {
      try tableVerifer.visit(
        unionKey: 18,
        unionField: 20,
        unionKeyName: "testType",
        fieldName: "test",
        required: false,
        completion: { (verifier, key: MyGame_Example_Any_, pos) in
          switch key {
          case .none_:
            break
          case .monster:
            try ForwardOffset<MyGame_Example_Monster>.verify(
              &verifier,
              at: pos,
              of: MyGame_Example_Monster.self)
          case .testsimpletablewithenum:
            break
          case .mygameExample2Monster:
            break
          }
        })
    } catch {
      XCTAssertEqual(
        error as! FlatbuffersErrors,
        .missAlignedPointer(position: 25, type: "UInt16"))
    }
  }
  func testVerifyUnionVectors() {
    // swiftformat:disable all
    var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
    // swiftformat:enable all
    XCTAssertNoThrow(try getCheckedRoot(byteBuffer: &byteBuffer) as Movie)
  }
  func testErrorWrongFileId() {
    // swiftformat:disable all
    var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
    // swiftformat:enable all
    XCTAssertThrowsError(try getCheckedRoot(byteBuffer: &byteBuffer, fileId: "FLEX") as Movie)
  }
  func testVerifyPrefixedBuffer() {
    // swiftformat:disable all
    var byteBuffer = ByteBuffer(bytes: [0, 0, 0, 1, 20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
    // swiftformat:enable all
    XCTAssertThrowsError(
      try getCheckedPrefixedSizeRoot(byteBuffer: &byteBuffer) as Movie)
  }
  func testFullVerifier() {
    XCTAssertNoThrow(
      try getCheckedRoot(
        byteBuffer: &validFlatbuffersObject) as MyGame_Example_Monster)
  }
  func testFullVerifierWithFileId() {
    XCTAssertNoThrow(
      try getCheckedRoot(
        byteBuffer: &validFlatbuffersObject,
        fileId: MyGame_Example_Monster.id) as MyGame_Example_Monster)
  }
  func testInvalidBuffer() {
    XCTAssertThrowsError(
      try getCheckedRoot(
        byteBuffer: &invalidFlatbuffersObject) as MyGame_Example_Monster)
  }
  func testValidUnionBuffer() {
    let string = "Awesome \\\\t\t\nstring!"
    var fb = FlatBufferBuilder()
    let stringOffset = fb.create(string: string)
    let characterType: [Character] = [.bookfan, .other]
    let characters = [
      fb.create(struct: BookReader(booksRead: 7)),
      stringOffset,
    ]
    let types = fb.createVector(characterType)
    let characterVector = fb.createVector(ofOffsets: characters)
    let end = Movie.createMovie(
      &fb,
      mainCharacterType: .other,
      mainCharacterOffset: Offset(offset: stringOffset.o),
      charactersTypeVectorOffset: types,
      charactersVectorOffset: characterVector)
    Movie.finish(&fb, end: end)
    var buf = fb.sizedBuffer
    XCTAssertNoThrow(try getCheckedRoot(byteBuffer: &buf) as Movie)
  }
  func add(buffer: inout ByteBuffer, v: Int32, p: Int) {
    buffer.write(value: v, index: p)
  }
}


FlatBuffersUnionTests

/*
final class FlatBuffersUnionTests: XCTestCase {
  func testCreateMonstor() {
    var b = FlatBufferBuilder(initialSize: 20)
    let dmg: Int16 = 5
    let str = "Axe"
    let axe = b.create(string: str)
    let weapon = Weapon.createWeapon(builder: &b, offset: axe, dmg: dmg)
    let weapons = b.createVector(ofOffsets: [weapon])
    let root = LocalMonster.createMonster(
      builder: &b,
      offset: weapons,
      equipment: .Weapon,
      equippedOffset: weapon.o)
    b.finish(offset: root)
    let buffer = b.sizedByteArray
    // swiftformat:disable all
    XCTAssertEqual(buffer, [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 8, 0, 7, 0, 12, 0, 10, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 20, 0, 0, 0, 1, 0, 0, 0, 12, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 5, 0, 4, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0])
    // swiftformat:enable all
    let monster = LocalMonster.getRootAsMonster(bb: ByteBuffer(bytes: buffer))
    XCTAssertEqual(monster.weapon(at: 0)?.dmg, dmg)
    XCTAssertEqual(monster.weapon(at: 0)?.name, str)
    XCTAssertEqual(monster.weapon(at: 0)?.nameVector, [65, 120, 101])
    let p: Weapon? = monster.equiped()
    XCTAssertEqual(p?.dmg, dmg)
    XCTAssertEqual(p?.name, str)
    XCTAssertEqual(p?.nameVector, [65, 120, 101])
  }
  func testEndTableFinish() {
    var builder = FlatBufferBuilder(initialSize: 20)
    let sword = builder.create(string: "Sword")
    let axe = builder.create(string: "Axe")
    let weaponOne = Weapon.createWeapon(
      builder: &builder,
      offset: sword,
      dmg: 3)
    let weaponTwo = Weapon.createWeapon(builder: &builder, offset: axe, dmg: 5)
    let name = builder.create(string: "Orc")
    let inventory: [UInt8] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    let inv = builder.createVector(inventory, size: 10)
    let weapons = builder.createVector(ofOffsets: [weaponOne, weaponTwo])
    let path = builder.createVector(ofStructs: [
      Vec(x: 4.0, y: 5.0, z: 6.0),
      Vec(x: 1.0, y: 2.0, z: 3.0),
    ])
    let orc = FinalMonster.createMonster(
      builder: &builder,
      position: Vec(x: 1, y: 2, z: 3),
      hp: 300,
      name: name,
      inventory: inv,
      color: .red,
      weapons: weapons,
      equipment: .Weapon,
      equippedOffset: weaponTwo,
      path: path)
    builder.finish(offset: orc)
    // swiftformat:disable all
    XCTAssertEqual(builder.sizedByteArray, [32, 0, 0, 0, 0, 0, 26, 0, 48, 0, 36, 0, 0, 0, 34, 0, 28, 0, 0, 0, 24, 0, 23, 0, 16, 0, 15, 0, 8, 0, 4, 0, 26, 0, 0, 0, 44, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 76, 0, 0, 0, 0, 0, 44, 1, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 52, 0, 0, 0, 28, 0, 0, 0, 10, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 3, 0, 0, 0, 79, 114, 99, 0, 244, 255, 255, 255, 0, 0, 5, 0, 24, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 3, 0, 12, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0, 5, 0, 0, 0, 83, 119, 111, 114, 100, 0, 0, 0])
    // swiftformat:enable all
  }
  func testEnumVector() {
    let vectorOfEnums: [ColorsNameSpace.RGB] = [.blue, .green]
    var builder = FlatBufferBuilder(initialSize: 1)
    let off = builder.createVector(vectorOfEnums)
    let start = ColorsNameSpace.Monster.startMonster(&builder)
    ColorsNameSpace.Monster.add(colors: off, &builder)
    let end = ColorsNameSpace.Monster.endMonster(&builder, start: start)
    builder.finish(offset: end)
    // swiftformat:disable all
    XCTAssertEqual(builder.sizedByteArray, [12, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])
    // swiftformat:enable all
    let monster = ColorsNameSpace.Monster.getRootAsMonster(bb: builder.buffer)
    XCTAssertEqual(monster.colorsCount, 2)
    XCTAssertEqual(monster.colors(at: 0), .blue)
    XCTAssertEqual(monster.colors(at: 1), .green)
  }
  func testUnionVector() {
    var fb = FlatBufferBuilder()
    let swordDmg: Int32 = 8
    let attackStart = Attacker.startAttacker(&fb)
    Attacker.add(swordAttackDamage: swordDmg, &fb)
    let attack = Attacker.endAttacker(&fb, start: attackStart)
    let characterType: [Character] = [.belle, .mulan, .bookfan]
    let characters = [
      fb.create(struct: BookReader(booksRead: 7)),
      attack,
      fb.create(struct: BookReader(booksRead: 2)),
    ]
    let types = fb.createVector(characterType)
    let characterVector = fb.createVector(ofOffsets: characters)
    let end = Movie.createMovie(
      &fb,
      charactersTypeVectorOffset: types,
      charactersVectorOffset: characterVector)
    Movie.finish(&fb, end: end)
    var movie = Movie.getRootAsMovie(bb: fb.buffer)
    XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count))
    XCTAssertEqual(movie.charactersCount, Int32(characters.count))
    for i in 0..<movie.charactersTypeCount {
      XCTAssertEqual(movie.charactersType(at: i), characterType[Int(i)])
    }
    XCTAssertEqual(
      movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
      7)
    XCTAssertEqual(
      movie.characters(at: 1, type: Attacker.self)?.swordAttackDamage,
      swordDmg)
    XCTAssertEqual(
      movie.characters(at: 2, type: BookReader_Mutable.self)?.booksRead,
      2)
    var objc: MovieT? = movie.unpack()
    XCTAssertEqual(
      movie.charactersTypeCount,
      Int32(objc?.characters.count ?? 0))
    XCTAssertEqual(
      movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
      (objc?.characters[0]?.value as? BookReader)?.booksRead)
    fb.clear()
    let newMovie = Movie.pack(&fb, obj: &objc)
    fb.finish(offset: newMovie)
    let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
    XCTAssertEqual(
      packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
      movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead)
    XCTAssertEqual(
      packedMovie.characters(at: 1, type: Attacker.self)?.swordAttackDamage,
      movie.characters(at: 1, type: Attacker.self)?.swordAttackDamage)
    XCTAssertEqual(
      packedMovie.characters(at: 2, type: BookReader_Mutable.self)?.booksRead,
      movie.characters(at: 2, type: BookReader_Mutable.self)?.booksRead)
  }
  func testStringUnion() {
    let string = "Awesome \\\\t\t\nstring!"
    var fb = FlatBufferBuilder()
    let stringOffset = fb.create(string: string)
    let characterType: [Character] = [.bookfan, .other]
    let characters = [
      fb.create(struct: BookReader(booksRead: 7)),
      stringOffset,
    ]
    let types = fb.createVector(characterType)
    let characterVector = fb.createVector(ofOffsets: characters)
    let end = Movie.createMovie(
      &fb,
      mainCharacterType: .other,
      mainCharacterOffset: Offset(offset: stringOffset.o),
      charactersTypeVectorOffset: types,
      charactersVectorOffset: characterVector)
    Movie.finish(&fb, end: end)
    var movie = Movie.getRootAsMovie(bb: fb.sizedBuffer)
    XCTAssertEqual(movie.mainCharacter(type: String.self), string)
    XCTAssertEqual(
      movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
      7)
    XCTAssertEqual(movie.characters(at: 1, type: String.self), string)
    var objc: MovieT? = movie.unpack()
    XCTAssertEqual(objc?.mainCharacter?.value as? String, string)
    XCTAssertEqual((objc?.characters[0]?.value as? BookReader)?.booksRead, 7)
    XCTAssertEqual(objc?.characters[1]?.value as? String, string)
    fb.clear()
    let newMovie = Movie.pack(&fb, obj: &objc)
    fb.finish(offset: newMovie)
    let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
    XCTAssertEqual(packedMovie.mainCharacter(type: String.self), string)
    XCTAssertEqual(
      packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
      7)
    XCTAssertEqual(packedMovie.characters(at: 1, type: String.self), string)
  }
  func testEncoding() {
    let string = "Awesome \\\\t\t\nstring!"
    var fb = FlatBufferBuilder()
    let stringOffset = fb.create(string: string)
    let swordDmg: Int32 = 8
    let attackStart = Attacker.startAttacker(&fb)
    Attacker.add(swordAttackDamage: swordDmg, &fb)
    let attack = Attacker.endAttacker(&fb, start: attackStart)
    let characterType: [Character] = [.belle, .mulan, .bookfan, .other]
    let characters = [
      fb.create(struct: BookReader(booksRead: 7)),
      attack,
      fb.create(struct: BookReader(booksRead: 2)),
      stringOffset,
    ]
    let types = fb.createVector(characterType)
    let characterVector = fb.createVector(ofOffsets: characters)
    let end = Movie.createMovie(
      &fb,
      charactersTypeVectorOffset: types,
      charactersVectorOffset: characterVector)
    Movie.finish(&fb, end: end)
    var sizedBuffer = fb.sizedBuffer
    do {
      let reader: Movie = try getCheckedRoot(byteBuffer: &sizedBuffer)
      let encoder = JSONEncoder()
      encoder.keyEncodingStrategy = .convertToSnakeCase
      let data = try encoder.encode(reader)
      XCTAssertEqual(data, jsonData.data(using: .utf8))
    } catch {
      XCTFail(error.localizedDescription)
    }
  }
  var jsonData: String {
    "{\"characters_type\":[\"Belle\",\"MuLan\",\"BookFan\",\"Other\"],\"characters\":[{\"books_read\":7},{\"sword_attack_damage\":8},{\"books_read\":2},\"Awesome \\\\\\\\t\\t\\nstring!\"]}"
  }
}
public enum ColorsNameSpace {
  enum RGB: Int32, Enum {
    typealias T = Int32
    static var byteSize: Int { MemoryLayout<Int32>.size }
    var value: Int32 { rawValue }
    case red = 0, green = 1, blue = 2
  }
  struct Monster: FlatBufferObject {
    var __buffer: ByteBuffer! { _accessor.bb }
    private var _accessor: Table
    static func getRootAsMonster(bb: ByteBuffer) -> Monster { Monster(Table(
      bb: bb,
      position: Int32(bb.read(def: UOffset.self, position: bb.reader)) +
        Int32(bb.reader))) }
    init(_ t: Table) { _accessor = t }
    init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
    public var colorsCount: Int32 {
      let o = _accessor.offset(4); return o == 0 ? 0 : _accessor
        .vector(count: o) }
    public func colors(at index: Int32) -> ColorsNameSpace
      .RGB?
    { let o = _accessor.offset(4); return o == 0 ? ColorsNameSpace
      .RGB(rawValue: 0)! : ColorsNameSpace.RGB(rawValue: _accessor.directRead(
        of: Int32.self,
        offset: _accessor.vector(at: o) + index * 4)) }
    static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb
      .startTable(with: 1) }
    static func add(colors: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(
      offset: colors,
      at: 4)  }
    static func endMonster(
      _ fbb: inout FlatBufferBuilder,
      start: UOffset)
      -> Offset
    { let end = Offset(offset: fbb.endTable(at: start)); return end
    }
  }
}
enum Equipment: Byte { case none, Weapon }
enum Color3: Int8 { case red = 0, green, blue }
struct FinalMonster {
  static func createMonster(
    builder: inout FlatBufferBuilder,
    position: Vec,
    hp: Int16,
    name: Offset,
    inventory: Offset,
    color: Color3,
    weapons: Offset,
    equipment: Equipment = .none,
    equippedOffset: Offset,
    path: Offset) -> Offset
  {
    let start = builder.startTable(with: 11)
    builder.create(struct: position, position: 4)
    builder.add(element: hp, def: 100, at: 8)
    builder.add(offset: name, at: 10)
    builder.add(offset: inventory, at: 14)
    builder.add(element: color.rawValue, def: Color3.green.rawValue, at: 16)
    builder.add(offset: weapons, at: 18)
    builder.add(
      element: equipment.rawValue,
      def: Equipment.none.rawValue,
      at: 20)
    builder.add(offset: equippedOffset, at: 22)
    builder.add(offset: path, at: 24)
    return Offset(offset: builder.endTable(at: start))
  }
}
struct LocalMonster {
  private var __t: Table
  init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o) }
  init(_ t: Table) { __t = t }
  func weapon(at index: Int32) -> Weapon? { let o = __t
    .offset(4); return o == 0 ? nil : Weapon.assign(
      __t.indirect(__t.vector(at: o) + (index * 4)),
      __t.bb) }
  func equiped<T: FlatBufferObject>() -> T? {
    let o = __t.offset(8); return o == 0 ? nil : __t.union(o)
  }
  static func getRootAsMonster(bb: ByteBuffer) -> LocalMonster {
    LocalMonster(Table(
      bb: bb,
      position: Int32(bb.read(def: UOffset.self, position: 0))))
  }
  static func createMonster(
    builder: inout FlatBufferBuilder,
    offset: Offset,
    equipment: Equipment = .none,
    equippedOffset: UOffset) -> Offset
  {
    let start = builder.startTable(with: 3)
    builder.add(element: equippedOffset, def: 0, at: 8)
    builder.add(offset: offset, at: 4)
    builder.add(
      element: equipment.rawValue,
      def: Equipment.none.rawValue,
      at: 6)
    return Offset(offset: builder.endTable(at: start))
  }
}
struct Weapon: FlatBufferObject {
  var __buffer: ByteBuffer! { __t.bb }
  static let offsets: (name: VOffset, dmg: VOffset) = (4, 6)
  private var __t: Table
  init(_ t: Table) { __t = t }
  init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o)}
  var dmg: Int16 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(
    of: Int16.self,
    at: o) }
  var nameVector: [UInt8]? { __t.getVector(at: 4) }
  var name: String? {
    let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) }
  static func assign(_ i: Int32, _ bb: ByteBuffer) -> Weapon { Weapon(Table(
    bb: bb,
    position: i)) }
  static func end(
    builder: inout FlatBufferBuilder,
    startOffset: UOffset) -> Offset
  {
    Offset(offset: builder.endTable(at: startOffset))
  }
  static func add(builder: inout FlatBufferBuilder, dmg: Int16) {
    builder.add(element: dmg, def: 0, at: Weapon.offsets.dmg)
  }
}


// automatically generated by the FlatBuffers compiler, do not modify
// swiftlint:disable all
// swiftformat:disable all
import FlatBuffers
public struct Property: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  private var _property: Bool
  public init(_ bb: ByteBuffer, o: Int32) {
    let _accessor = Struct(bb: bb, position: o)
    _property = _accessor.readBuffer(of: Bool.self, at: 0)
  }
  public init(property: Bool) {
    _property = property
  }
  public init() {
    _property = false
  }
  public init(_ _t: inout Property_Mutable) {
    _property = _t.property
  }
  public var property: Bool { _property }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    try verifier.inBuffer(position: position, of: Property.self)
  }
}
extension Property: Encodable {
  enum CodingKeys: String, CodingKey {
    case property = "property"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if property != false {
      try container.encodeIfPresent(property, forKey: .property)
    }
  }
}
public struct Property_Mutable: FlatBufferObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Struct
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
  public var property: Bool { return _accessor.readBuffer(of: Bool.self, at: 0) }

  public mutating func unpack() -> Property {
    return Property(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout Property?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout Property) -> Offset {
    return builder.create(struct: obj)
  }
}
public struct TestMutatingBool: FlatBufferObject, Verifiable, ObjectAPIPacker {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Table
  public static func getRootAsTestMutatingBool(bb: ByteBuffer) -> TestMutatingBool { return TestMutatingBool(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
  private init(_ t: Table) { _accessor = t }
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
  private enum VTOFFSET: VOffset {
    case b = 4
    var v: Int32 { Int32(self.rawValue) }
    var p: VOffset { self.rawValue }
  }
  public var b: Property? { let o = _accessor.offset(VTOFFSET.b.v); return o == 0 ? nil : _accessor.readBuffer(of: Property.self, at: o) }
  public var mutableB: Property_Mutable? { let o = _accessor.offset(VTOFFSET.b.v); return o == 0 ? nil : Property_Mutable(_accessor.bb, o: o + _accessor.postion) }
  public static func startTestMutatingBool(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
  public static func add(b: Property?, _ fbb: inout FlatBufferBuilder) { guard let b = b else { return }; fbb.create(struct: b, position: VTOFFSET.b.p) }
  public static func endTestMutatingBool(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
  public static func createTestMutatingBool(
    _ fbb: inout FlatBufferBuilder,
    b: Property? = nil
  ) -> Offset {
    let __start = TestMutatingBool.startTestMutatingBool(&fbb)
    TestMutatingBool.add(b: b, &fbb)
    return TestMutatingBool.endTestMutatingBool(&fbb, start: __start)
  }

  public mutating func unpack() -> TestMutatingBoolT {
    return TestMutatingBoolT(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout TestMutatingBoolT?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout TestMutatingBoolT) -> Offset {
    let __root = TestMutatingBool.startTestMutatingBool(&builder)
    TestMutatingBool.add(b: obj.b, &builder)
    return TestMutatingBool.endTestMutatingBool(&builder, start: __root)
  }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    var _v = try verifier.visitTable(at: position)
    try _v.visit(field: VTOFFSET.b.p, fieldName: "b", required: false, type: Property.self)
    _v.finish()
  }
}
extension TestMutatingBool: Encodable {
  enum CodingKeys: String, CodingKey {
    case b = "b"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encodeIfPresent(b, forKey: .b)
  }
}
public class TestMutatingBoolT: NativeObject {
  public var b: Property?
  public init(_ _t: inout TestMutatingBool) {
    b = _t.b
  }
  public init() {
    b = Property()
  }
  public func serialize() -> ByteBuffer { return serialize(type: TestMutatingBool.self) }
}


FlatBuffersMonsterWriterTests

/*
typealias Test = MyGame_Example_Test
typealias Monster = MyGame_Example_Monster
typealias Vec3 = MyGame_Example_Vec3
typealias Stat = MyGame_Example_Stat
class FlatBuffersMonsterWriterTests: XCTestCase {
  func testData() {
    // swiftformat:disable all
    let data = Data([48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    // swiftformat:enable all
    let _data = ByteBuffer(data: data)
    readVerifiedMonster(fb: _data)
  }
  func testReadFromOtherLanguages() {
    let path = FileManager.default.currentDirectoryPath
    let url = URL(fileURLWithPath: path, isDirectory: true)
      .appendingPathComponent("monsterdata_test").appendingPathExtension("mon")
    guard let data = try? Data(contentsOf: url) else { return }
    let _data = ByteBuffer(data: data)
    readVerifiedMonster(fb: _data)
  }
  func testCreateMonster() {
    let bytes = createMonster(withPrefix: false)
    // swiftformat:disable all
    XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    // swiftformat:enable all
    let monster = MyGame_Example_Monster.getRootAsMonster(bb: bytes.buffer)
    readMonster(monster: monster)
    mutateMonster(fb: bytes.buffer)
    readMonster(monster: monster)
  }
  func testCreateMonsterResizedBuffer() {
    let bytes = createMonster(withPrefix: false)
    // swiftformat:disable all
    XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    // swiftformat:enable all
    readVerifiedMonster(fb: bytes.sizedBuffer)
  }
  func testCreateMonsterPrefixed() {
    let bytes = createMonster(withPrefix: true)
    // swiftformat:disable all
    XCTAssertEqual(bytes.sizedByteArray, [44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
    // swiftformat:enable all
    var buffer = bytes.buffer
    readMonster(monster: getPrefixedSizeRoot(byteBuffer: &buffer))
  }
  func testCreateMonsterUsingCreateMonsterMethodWithNilPos() {
    var fbb = FlatBufferBuilder(initialSize: 1)
    let name = fbb.create(string: "Frodo")
    let mStart = Monster.startMonster(&fbb)
    Monster.add(name: name, &fbb)
    let root = Monster.endMonster(&fbb, start: mStart)
    fbb.finish(offset: root)
    let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
    XCTAssertNil(newMonster.pos)
    XCTAssertEqual(newMonster.name, "Frodo")
  }
  func testCreateMonsterUsingCreateMonsterMethodWithPosX() {
    var fbb = FlatBufferBuilder(initialSize: 1)
    let name = fbb.create(string: "Barney")
    let mStart = Monster.startMonster(&fbb)
    Monster.add(
      pos: MyGame_Example_Vec3(
        x: 10,
        y: 0,
        z: 0,
        test1: 0,
        test2: .blue,
        test3: .init()),
      &fbb)
    Monster.add(name: name, &fbb)
    let root = Monster.endMonster(&fbb, start: mStart)
    fbb.finish(offset: root)
    let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
    XCTAssertEqual(newMonster.pos!.x, 10)
    XCTAssertEqual(newMonster.name, "Barney")
  }
    // swiftformat:disable all
    var array: [UInt8] = [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]
    // swiftformat:enable all
    let unpacked = array
      .withUnsafeMutableBytes { (memory) -> MyGame_Example_MonsterT in
        let bytes = ByteBuffer(
          assumingMemoryBound: memory.baseAddress!,
          capacity: memory.count)
        var monster = Monster.getRootAsMonster(bb: bytes)
        readFlatbufferMonster(monster: &monster)
        let unpacked = monster.unpack()
        return unpacked
      }
    readObjectApi(monster: unpacked)
  }
  func testArrayOfBools() {
    let boolArray = [false, true, false, true, false, true, false]
    var fbb = FlatBufferBuilder(initialSize: 1)
    let name = fbb.create(string: "Frodo")
    let bools = fbb.createVector(boolArray)
    let root = Monster.createMonster(
      &fbb,
      nameOffset: name,
      testarrayofboolsVectorOffset: bools)
    fbb.finish(offset: root)
    let monster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
    let values = monster.testarrayofbools
    XCTAssertEqual(boolArray, values)
    for i in 0..<monster.testarrayofboolsCount {
      XCTAssertEqual(boolArray[Int(i)], monster.testarrayofbools(at: i))
    }
  }
  func readVerifiedMonster(fb: ByteBuffer) {
    var byteBuffer = fb
    XCTAssertNoThrow(
      try readMonster(
        monster: getCheckedRoot(
          byteBuffer: &byteBuffer) as MyGame_Example_Monster))
  }
  func readMonster(monster: Monster) {
    var monster = monster
    readFlatbufferMonster(monster: &monster)
    let unpacked: MyGame_Example_MonsterT? = monster.unpack()
    readObjectApi(monster: unpacked!)
    guard let buffer = unpacked?.serialize()
    else { fatalError("Couldnt generate bytebuffer") }
    var newMonster = Monster.getRootAsMonster(bb: buffer)
    readFlatbufferMonster(monster: &newMonster)
  }
  func createMonster(withPrefix prefix: Bool) -> FlatBufferBuilder {
    var fbb = FlatBufferBuilder(initialSize: 1)
    let names = [
      fbb.create(string: "Frodo"),
      fbb.create(string: "Barney"),
      fbb.create(string: "Wilma"),
    ]
    var offsets: [Offset] = []
    let start1 = Monster.startMonster(&fbb)
    Monster.add(name: names[0], &fbb)
    offsets.append(Monster.endMonster(&fbb, start: start1))
    let start2 = Monster.startMonster(&fbb)
    Monster.add(name: names[1], &fbb)
    offsets.append(Monster.endMonster(&fbb, start: start2))
    let start3 = Monster.startMonster(&fbb)
    Monster.add(name: names[2], &fbb)
    offsets.append(Monster.endMonster(&fbb, start: start3))
    let sortedArray = Monster.sortVectorOfMonster(offsets: offsets, &fbb)
    let str = fbb.create(string: "MyMonster")
    let test1 = fbb.create(string: "test1")
    let test2 = fbb.create(string: "test2")
    let _inv: [Byte] = [0, 1, 2, 3, 4]
    let inv = fbb.createVector(_inv)
    let fred = fbb.create(string: "Fred")
    let mon1Start = Monster.startMonster(&fbb)
    Monster.add(name: fred, &fbb)
    let mon2 = Monster.endMonster(&fbb, start: mon1Start)
    let test4 = fbb.createVector(ofStructs: [
      MyGame_Example_Test(a: 30, b: 40),
      MyGame_Example_Test(a: 10, b: 20),
    ])
    let stringTestVector = fbb.createVector(ofOffsets: [test1, test2])
    let mStart = Monster.startMonster(&fbb)
    Monster.add(
      pos: MyGame_Example_Vec3(
        x: 1,
        y: 2,
        z: 3,
        test1: 3,
        test2: .green,
        test3: .init(a: 5, b: 6)),
      &fbb)
    Monster.add(hp: 80, &fbb)
    Monster.add(name: str, &fbb)
    Monster.addVectorOf(inventory: inv, &fbb)
    Monster.add(testType: .monster, &fbb)
    Monster.add(test: mon2, &fbb)
    Monster.addVectorOf(test4: test4, &fbb)
    Monster.addVectorOf(testarrayofstring: stringTestVector, &fbb)
    Monster.add(testbool: true, &fbb)
    Monster.addVectorOf(testarrayoftables: sortedArray, &fbb)
    let end = Monster.endMonster(&fbb, start: mStart)
    Monster.finish(&fbb, end: end, prefix: prefix)
    return fbb
  }
  func mutateMonster(fb: ByteBuffer) {
    let monster = Monster.getRootAsMonster(bb: fb)
    XCTAssertFalse(monster.mutate(mana: 10))
    XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
    XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
    XCTAssertEqual(monster.testarrayoftables(at: 2)?.name, "Wilma")
    // Example of searching for a table by the key
    XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo"))
    XCTAssertNotNil(monster.testarrayoftablesBy(key: "Barney"))
    XCTAssertNotNil(monster.testarrayoftablesBy(key: "Wilma"))
    XCTAssertEqual(monster.testType, .monster)
    XCTAssertEqual(monster.mutate(inventory: 1, at: 0), true)
    XCTAssertEqual(monster.mutate(inventory: 2, at: 1), true)
    XCTAssertEqual(monster.mutate(inventory: 3, at: 2), true)
    XCTAssertEqual(monster.mutate(inventory: 4, at: 3), true)
    XCTAssertEqual(monster.mutate(inventory: 5, at: 4), true)
    for i in 0..<monster.inventoryCount {
      XCTAssertEqual(monster.inventory(at: i), Byte(i + 1))
    }
    XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true)
    XCTAssertEqual(monster.mutate(inventory: 1, at: 1), true)
    XCTAssertEqual(monster.mutate(inventory: 2, at: 2), true)
    XCTAssertEqual(monster.mutate(inventory: 3, at: 3), true)
    XCTAssertEqual(monster.mutate(inventory: 4, at: 4), true)
    let vec = monster.mutablePos
    XCTAssertEqual(vec?.x, 1)
    XCTAssertTrue(vec?.mutate(x: 55.0) ?? false)
    XCTAssertTrue(vec?.mutate(test1: 55) ?? false)
    XCTAssertEqual(vec?.x, 55.0)
    XCTAssertEqual(vec?.test1, 55.0)
    XCTAssertTrue(vec?.mutate(x: 1) ?? false)
    XCTAssertEqual(vec?.x, 1)
    XCTAssertTrue(vec?.mutate(test1: 3) ?? false)
  }
  func readFlatbufferMonster(monster: inout MyGame_Example_Monster) {
    XCTAssertEqual(monster.hp, 80)
    XCTAssertEqual(monster.mana, 150)
    XCTAssertEqual(monster.name, "MyMonster")
    let pos = monster.pos
    XCTAssertEqual(pos?.x, 1)
    XCTAssertEqual(pos?.y, 2)
    XCTAssertEqual(pos?.z, 3)
    XCTAssertEqual(pos?.test1, 3)
    XCTAssertEqual(pos?.test2, .green)
    let test = pos?.test3
    XCTAssertEqual(test?.a, 5)
    XCTAssertEqual(test?.b, 6)
    XCTAssertEqual(monster.testType, .monster)
    let monster2 = monster.test(type: Monster.self)
    XCTAssertEqual(monster2?.name, "Fred")
    XCTAssertEqual(monster.mutate(mana: 10), false)
    XCTAssertEqual(monster.mana, 150)
    XCTAssertEqual(monster.inventoryCount, 5)
    var sum: Byte = 0
    for i in 0...monster.inventoryCount {
      sum += monster.inventory(at: i)
    }
    XCTAssertEqual(sum, 10)
    XCTAssertEqual(monster.test4Count, 2)
    let test0 = monster.test4(at: 0)
    let test1 = monster.test4(at: 1)
    var sum0 = 0
    var sum1 = 0
    if let a = test0?.a, let b = test0?.b {
      sum0 = Int(a) + Int(b)
    }
    if let a = test1?.a, let b = test1?.b {
      sum1 = Int(a) + Int(b)
    }
    XCTAssertEqual(sum0 + sum1, 100)
    let mutableTest0 = monster.mutableTest4(at: 0)
    let mutableTest1 = monster.mutableTest4(at: 1)
    var sum2 = 0
    var sum3 = 0
    if let a = mutableTest0?.a, let b = mutableTest0?.b {
      sum2 = Int(a) + Int(b)
    }
    if let a = mutableTest1?.a, let b = mutableTest1?.b {
      sum3 = Int(a) + Int(b)
    }
    XCTAssertEqual(sum2 + sum3, 100)
    XCTAssertEqual(monster.testarrayofstringCount, 2)
    XCTAssertEqual(monster.testarrayofstring(at: 0), "test1")
    XCTAssertEqual(monster.testarrayofstring(at: 1), "test2")
    XCTAssertEqual(monster.testbool, true)
    let array = monster.nameSegmentArray
    XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
    if 0 == monster.testarrayofboolsCount  {
      XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
    } else {
      XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
    }
  }
  func readObjectApi(monster: MyGame_Example_MonsterT) {
    XCTAssertEqual(monster.hp, 80)
    XCTAssertEqual(monster.mana, 150)
    XCTAssertEqual(monster.name, "MyMonster")
    let pos = monster.pos
    XCTAssertEqual(pos?.x, 1)
    XCTAssertEqual(pos?.y, 2)
    XCTAssertEqual(pos?.z, 3)
    XCTAssertEqual(pos?.test1, 3)
    XCTAssertEqual(pos?.test2, .green)
    let test = pos?.test3
    XCTAssertEqual(test?.a, 5)
    XCTAssertEqual(test?.b, 6)
    let monster2 = monster.test?.value as? MyGame_Example_MonsterT
    XCTAssertEqual(monster2?.name, "Fred")
    XCTAssertEqual(monster.mana, 150)
    monster.mana = 10
    XCTAssertEqual(monster.mana, 10)
    monster.mana = 150
    XCTAssertEqual(monster.mana, 150)
    XCTAssertEqual(monster.inventory.count, 5)
    var sum: Byte = 0
    for i in monster.inventory {
      sum += i
    }
    XCTAssertEqual(sum, 10)
    XCTAssertEqual(monster.test4.count, 2)
    let test0 = monster.test4[0]
    let test1 = monster.test4[1]
    var sum0 = 0
    var sum1 = 0
    if let a = test0?.a, let b = test0?.b {
      sum0 = Int(a) + Int(b)
    }
    if let a = test1?.a, let b = test1?.b {
      sum1 = Int(a) + Int(b)
    }
    XCTAssertEqual(sum0 + sum1, 100)
    XCTAssertEqual(monster.testbool, true)
  }
  func testEncoding() {
    let fbb = createMonster(withPrefix: false)
    var sizedBuffer = fbb.sizedBuffer
    do {
      let reader: Monster = try getCheckedRoot(byteBuffer: &sizedBuffer)
      let encoder = JSONEncoder()
      encoder.keyEncodingStrategy = .convertToSnakeCase
      let data = try encoder.encode(reader)
      XCTAssertEqual(data, jsonData.data(using: .utf8))
    } catch {
      XCTFail(error.localizedDescription)
    }
  }
  var jsonData: String {
    """
    {\"hp\":80,\"inventory\":[0,1,2,3,4],\"test\":{\"name\":\"Fred\"},\"testarrayofstring\":[\"test1\",\"test2\"],\"testarrayoftables\":[{\"name\":\"Barney\"},{\"name\":\"Frodo\"},{\"name\":\"Wilma\"}],\"test4\":[{\"a\":30,\"b\":40},{\"a\":10,\"b\":20}],\"testbool\":true,\"test_type\":\"Monster\",\"pos\":{\"y\":2,\"test3\":{\"a\":5,\"b\":6},\"z\":3,\"x\":1,\"test1\":3,\"test2\":\"Green\"},\"name\":\"MyMonster\"}
    """
  }
}


FlatBuffersStructsTests

/*
final class FlatBuffersStructsTests: XCTestCase {
  func testWritingAndMutatingBools() {
    var fbb = FlatBufferBuilder()
    let start = TestMutatingBool.startTestMutatingBool(&fbb)
    TestMutatingBool.add(b: Property(property: false), &fbb)
    let root = TestMutatingBool.endTestMutatingBool(&fbb, start: start)
    fbb.finish(offset: root)
    let testMutatingBool = TestMutatingBool
      .getRootAsTestMutatingBool(bb: fbb.sizedBuffer)
    let property = testMutatingBool.mutableB
    XCTAssertEqual(property?.property, false)
    property?.mutate(property: false)
    XCTAssertEqual(property?.property, false)
    property?.mutate(property: true)
    XCTAssertEqual(property?.property, true)
  }
}
struct Vec: NativeStruct {
  var x: Float32
  var y: Float32
  var z: Float32
}


FlatbuffersMoreDefaults

/*
class FlatBuffersMoreDefaults: XCTestCase {
  func testFlatbuffersObject() {
    var fbb = FlatBufferBuilder()
    let root = MoreDefaults.createMoreDefaults(&fbb)
    fbb.finish(offset: root)
    let defaults = MoreDefaults.getRootAsMoreDefaults(bb: fbb.sizedBuffer)
    XCTAssertEqual(defaults.emptyString, "")
    XCTAssertEqual(defaults.someString, "some")
    XCTAssertEqual(defaults.ints, [])
    XCTAssertEqual(defaults.floats, [])
    XCTAssertEqual(defaults.bools, [])
    XCTAssertEqual(defaults.intsCount, 0)
    XCTAssertEqual(defaults.floatsCount, 0)
    XCTAssertEqual(defaults.abcsCount, 0)
    XCTAssertEqual(defaults.boolsCount, 0)
  }
  func testFlatbuffersObjectAPI() {
    var fbb = FlatBufferBuilder()
    let defaults = MoreDefaultsT()
    XCTAssertEqual(defaults.emptyString, "")
    XCTAssertEqual(defaults.someString, "some")
    XCTAssertEqual(defaults.ints, [])
    XCTAssertEqual(defaults.floats, [])
    XCTAssertEqual(defaults.abcs, [])
    XCTAssertEqual(defaults.bools, [])
    let buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
    let fDefaults = MoreDefaults.getRootAsMoreDefaults(bb: buffer)
    XCTAssertEqual(fDefaults.emptyString, "")
    XCTAssertEqual(fDefaults.someString, "some")
    XCTAssertEqual(fDefaults.ints, [])
    XCTAssertEqual(fDefaults.floats, [])
    XCTAssertEqual(fDefaults.intsCount, 0)
    XCTAssertEqual(fDefaults.floatsCount, 0)
    XCTAssertEqual(fDefaults.abcsCount, 0)
    XCTAssertEqual(fDefaults.boolsCount, 0)
  }
  func testEncoding() {
    var fbb = FlatBufferBuilder()
    let root = MoreDefaults.createMoreDefaults(&fbb)
    fbb.finish(offset: root)
    var sizedBuffer = fbb.sizedBuffer
    do {
      let reader: MoreDefaults = try getCheckedRoot(byteBuffer: &sizedBuffer)
      let encoder = JSONEncoder()
      encoder.keyEncodingStrategy = .convertToSnakeCase
      let data = try encoder.encode(reader)
      XCTAssertEqual(data, jsonData.data(using: .utf8))
    } catch {
      XCTFail(error.localizedDescription)
    }
  }
  var jsonData: String {
    "{\"empty_string\":\"\",\"some_string\":\"some\"}"
  }
}


XCTestManifests

/*
 */
#if !canImport(ObjectiveC)
import XCTest
extension FlatBuffersDoubleTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersDoubleTests = [
    ("testCreateFinish", testCreateFinish),
    ("testCreateFinishWithPrefix", testCreateFinishWithPrefix),
  ]
}
extension FlatBuffersMonsterWriterTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersMonsterWriterTests = [
    ("testArrayOfBools", testArrayOfBools),
    ("testCreateMonster", testCreateMonster),
    ("testCreateMonsterPrefixed", testCreateMonsterPrefixed),
    ("testCreateMonsterResizedBuffer", testCreateMonsterResizedBuffer),
    (
      "testCreateMonsterUsingCreateMonsterMethodWithNilPos",
      testCreateMonsterUsingCreateMonsterMethodWithNilPos),
    (
      "testCreateMonsterUsingCreateMonsterMethodWithPosX",
      testCreateMonsterUsingCreateMonsterMethodWithPosX),
    ("testData", testData),
    ("testReadFromOtherLanguages", testReadFromOtherLanguages),
    (
  ]
}
extension FlatBuffersMoreDefaults {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersMoreDefaults = [
    ("testFlatbuffersObject", testFlatbuffersObject),
    ("testFlatbuffersObjectAPI", testFlatbuffersObjectAPI),
  ]
}
extension FlatBuffersStructsTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersStructsTests = [
    ("testWritingAndMutatingBools", testWritingAndMutatingBools),
  ]
}
extension FlatBuffersTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersTests = [
    ("testCreateFinish", testCreateFinish),
    ("testCreateFinishWithPrefix", testCreateFinishWithPrefix),
    ("testCreateString", testCreateString),
    ("testEndian", testEndian),
    ("testOffset", testOffset),
    ("testReadCountry", testReadCountry),
    ("testStartTable", testStartTable),
    ("testWriteNullableStrings", testWriteNullableStrings),
    ("testWriteOptionalValues", testWriteOptionalValues),
  ]
}
extension FlatBuffersUnionTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersUnionTests = [
    ("testCreateMonstor", testCreateMonstor),
    ("testEndTableFinish", testEndTableFinish),
    ("testEnumVector", testEnumVector),
    ("testStringUnion", testStringUnion),
    ("testUnionVector", testUnionVector),
  ]
}
extension FlatBuffersVectors {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatBuffersVectors = [
    ("testCreateEmptyIntArray", testCreateEmptyIntArray),
    ("testCreateIntArray", testCreateIntArray),
    ("testCreateSharedStringVector", testCreateSharedStringVector),
    ("testCreateVectorOfStrings", testCreateVectorOfStrings),
    ("testCreatingTwoCountries", testCreatingTwoCountries),
    ("testHasForArray", testHasForArray),
    ("testReadDoubleArray", testReadDoubleArray),
    ("testReadInt32Array", testReadInt32Array),
  ]
}
extension FlatbuffersVerifierTests {
  // DO NOT MODIFY: This is autogenerated, use:
  //   `swift test --generate-linuxmain`
  // to regenerate.
  static let __allTests__FlatbuffersVerifierTests = [
    ("testFullVerifier", testFullVerifier),
    ("testInvalidBuffer", testInvalidBuffer),
    ("testPositionInBuffer", testPositionInBuffer),
    ("testRangeInBuffer", testRangeInBuffer),
    ("testTableVerifier", testTableVerifier),
    ("testValidUnionBuffer", testValidUnionBuffer),
    ("testVeriferInitFailing", testVeriferInitFailing),
    ("testVeriferInitPassing", testVeriferInitPassing),
    ("testVerifierCheckAlignment", testVerifierCheckAlignment),
    ("testVerifyUnionVectors", testVerifyUnionVectors),
    ("testVisitTable", testVisitTable),
  ]
}
public func __allTests() -> [XCTestCaseEntry] {
  [
    testCase(FlatBuffersDoubleTests.__allTests__FlatBuffersDoubleTests),
    testCase(
      FlatBuffersMonsterWriterTests
        .__allTests__FlatBuffersMonsterWriterTests),
    testCase(FlatBuffersMoreDefaults.__allTests__FlatBuffersMoreDefaults),
    testCase(FlatBuffersStructsTests.__allTests__FlatBuffersStructsTests),
    testCase(FlatBuffersTests.__allTests__FlatBuffersTests),
    testCase(FlatBuffersUnionTests.__allTests__FlatBuffersUnionTests),
    testCase(FlatBuffersVectors.__allTests__FlatBuffersVectors),
    testCase(FlatbuffersVerifierTests.__allTests__FlatbuffersVerifierTests),
  ]
}
#endif


// automatically generated by the FlatBuffers compiler, do not modify
// swiftlint:disable all
// swiftformat:disable all
import FlatBuffers
public enum Character: UInt8, UnionEnum {
  public typealias T = UInt8
  public init?(value: T) {
    self.init(rawValue: value)
  }
  public static var byteSize: Int { return MemoryLayout<UInt8>.size }
  public var value: UInt8 { return self.rawValue }
  case none_ = 0
  case mulan = 1
  case rapunzel = 2
  case belle = 3
  case bookfan = 4
  case other = 5
  case unused = 6
  public static var max: Character { return .unused }
  public static var min: Character { return .none_ }
}
extension Character: Encodable {
  public func encode(to encoder: Encoder) throws {
    var container = encoder.singleValueContainer()
    switch self {
    case .none_: try container.encode("NONE")
    case .mulan: try container.encode("MuLan")
    case .rapunzel: try container.encode("Rapunzel")
    case .belle: try container.encode("Belle")
    case .bookfan: try container.encode("BookFan")
    case .other: try container.encode("Other")
    case .unused: try container.encode("Unused")
    }
  }
}
public struct CharacterUnion {
  public var type: Character
  public var value: NativeObject?
  public init(_ v: NativeObject?, type: Character) {
    self.type = type
    self.value = v
  }
  public func pack(builder: inout FlatBufferBuilder) -> Offset {
    switch type {
    case .mulan:
      var __obj = value as? AttackerT
      return Attacker.pack(&builder, obj: &__obj)
    case .rapunzel:
      var __obj = value as? Rapunzel
      return Rapunzel_Mutable.pack(&builder, obj: &__obj)
    case .belle:
      var __obj = value as? BookReader
      return BookReader_Mutable.pack(&builder, obj: &__obj)
    case .bookfan:
      var __obj = value as? BookReader
      return BookReader_Mutable.pack(&builder, obj: &__obj)
    case .other:
      var __obj = value as? String
      return String.pack(&builder, obj: &__obj)
    case .unused:
      var __obj = value as? String
      return String.pack(&builder, obj: &__obj)
    default: return Offset()
    }
  }
}
public enum Gadget: UInt8, UnionEnum {
  public typealias T = UInt8
  public init?(value: T) {
    self.init(rawValue: value)
  }
  public static var byteSize: Int { return MemoryLayout<UInt8>.size }
  public var value: UInt8 { return self.rawValue }
  case none_ = 0
  case fallingtub = 1
  case handfan = 2
  public static var max: Gadget { return .handfan }
  public static var min: Gadget { return .none_ }
}
extension Gadget: Encodable {
  public func encode(to encoder: Encoder) throws {
    var container = encoder.singleValueContainer()
    switch self {
    case .none_: try container.encode("NONE")
    case .fallingtub: try container.encode("FallingTub")
    case .handfan: try container.encode("HandFan")
    }
  }
}
public struct GadgetUnion {
  public var type: Gadget
  public var value: NativeObject?
  public init(_ v: NativeObject?, type: Gadget) {
    self.type = type
    self.value = v
  }
  public func pack(builder: inout FlatBufferBuilder) -> Offset {
    switch type {
    case .fallingtub:
      var __obj = value as? FallingTub
      return FallingTub_Mutable.pack(&builder, obj: &__obj)
    case .handfan:
      var __obj = value as? HandFanT
      return HandFan.pack(&builder, obj: &__obj)
    default: return Offset()
    }
  }
}
public struct Rapunzel: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  private var _hairLength: Int32
  public init(_ bb: ByteBuffer, o: Int32) {
    let _accessor = Struct(bb: bb, position: o)
    _hairLength = _accessor.readBuffer(of: Int32.self, at: 0)
  }
  public init(hairLength: Int32) {
    _hairLength = hairLength
  }
  public init() {
    _hairLength = 0
  }
  public init(_ _t: inout Rapunzel_Mutable) {
    _hairLength = _t.hairLength
  }
  public var hairLength: Int32 { _hairLength }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    try verifier.inBuffer(position: position, of: Rapunzel.self)
  }
}
extension Rapunzel: Encodable {
  enum CodingKeys: String, CodingKey {
    case hairLength = "hair_length"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if hairLength != 0 {
      try container.encodeIfPresent(hairLength, forKey: .hairLength)
    }
  }
}
public struct Rapunzel_Mutable: FlatBufferObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Struct
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
  public var hairLength: Int32 { return _accessor.readBuffer(of: Int32.self, at: 0) }

  public mutating func unpack() -> Rapunzel {
    return Rapunzel(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout Rapunzel?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout Rapunzel) -> Offset {
    return builder.create(struct: obj)
  }
}
public struct BookReader: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  private var _booksRead: Int32
  public init(_ bb: ByteBuffer, o: Int32) {
    let _accessor = Struct(bb: bb, position: o)
    _booksRead = _accessor.readBuffer(of: Int32.self, at: 0)
  }
  public init(booksRead: Int32) {
    _booksRead = booksRead
  }
  public init() {
    _booksRead = 0
  }
  public init(_ _t: inout BookReader_Mutable) {
    _booksRead = _t.booksRead
  }
  public var booksRead: Int32 { _booksRead }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    try verifier.inBuffer(position: position, of: BookReader.self)
  }
}
extension BookReader: Encodable {
  enum CodingKeys: String, CodingKey {
    case booksRead = "books_read"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if booksRead != 0 {
      try container.encodeIfPresent(booksRead, forKey: .booksRead)
    }
  }
}
public struct BookReader_Mutable: FlatBufferObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Struct
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
  public var booksRead: Int32 { return _accessor.readBuffer(of: Int32.self, at: 0) }

  public mutating func unpack() -> BookReader {
    return BookReader(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout BookReader?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout BookReader) -> Offset {
    return builder.create(struct: obj)
  }
}
public struct FallingTub: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  private var _weight: Int32
  public init(_ bb: ByteBuffer, o: Int32) {
    let _accessor = Struct(bb: bb, position: o)
    _weight = _accessor.readBuffer(of: Int32.self, at: 0)
  }
  public init(weight: Int32) {
    _weight = weight
  }
  public init() {
    _weight = 0
  }
  public init(_ _t: inout FallingTub_Mutable) {
    _weight = _t.weight
  }
  public var weight: Int32 { _weight }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    try verifier.inBuffer(position: position, of: FallingTub.self)
  }
}
extension FallingTub: Encodable {
  enum CodingKeys: String, CodingKey {
    case weight = "weight"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if weight != 0 {
      try container.encodeIfPresent(weight, forKey: .weight)
    }
  }
}
public struct FallingTub_Mutable: FlatBufferObject {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Struct
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
  public var weight: Int32 { return _accessor.readBuffer(of: Int32.self, at: 0) }

  public mutating func unpack() -> FallingTub {
    return FallingTub(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout FallingTub?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout FallingTub) -> Offset {
    return builder.create(struct: obj)
  }
}
public struct Attacker: FlatBufferObject, Verifiable, ObjectAPIPacker {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Table
  public static var id: String { "MOVI" }
  public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Attacker.id, addPrefix: prefix) }
  public static func getRootAsAttacker(bb: ByteBuffer) -> Attacker { return Attacker(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
  private init(_ t: Table) { _accessor = t }
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
  private enum VTOFFSET: VOffset {
    case swordAttackDamage = 4
    var v: Int32 { Int32(self.rawValue) }
    var p: VOffset { self.rawValue }
  }
  public var swordAttackDamage: Int32 { let o = _accessor.offset(VTOFFSET.swordAttackDamage.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) }
  public static func startAttacker(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
  public static func add(swordAttackDamage: Int32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: swordAttackDamage, def: 0, at: VTOFFSET.swordAttackDamage.p) }
  public static func endAttacker(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
  public static func createAttacker(
    _ fbb: inout FlatBufferBuilder,
    swordAttackDamage: Int32 = 0
  ) -> Offset {
    let __start = Attacker.startAttacker(&fbb)
    Attacker.add(swordAttackDamage: swordAttackDamage, &fbb)
    return Attacker.endAttacker(&fbb, start: __start)
  }

  public mutating func unpack() -> AttackerT {
    return AttackerT(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout AttackerT?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout AttackerT) -> Offset {
    let __root = Attacker.startAttacker(&builder)
    Attacker.add(swordAttackDamage: obj.swordAttackDamage, &builder)
    return Attacker.endAttacker(&builder, start: __root)
  }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    var _v = try verifier.visitTable(at: position)
    try _v.visit(field: VTOFFSET.swordAttackDamage.p, fieldName: "swordAttackDamage", required: false, type: Int32.self)
    _v.finish()
  }
}
extension Attacker: Encodable {
  enum CodingKeys: String, CodingKey {
    case swordAttackDamage = "sword_attack_damage"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if swordAttackDamage != 0 {
      try container.encodeIfPresent(swordAttackDamage, forKey: .swordAttackDamage)
    }
  }
}
public class AttackerT: NativeObject {
  public var swordAttackDamage: Int32
  public init(_ _t: inout Attacker) {
    swordAttackDamage = _t.swordAttackDamage
  }
  public init() {
    swordAttackDamage = 0
  }
  public func serialize() -> ByteBuffer { return serialize(type: Attacker.self) }
}
public struct HandFan: FlatBufferObject, Verifiable, ObjectAPIPacker {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Table
  public static var id: String { "MOVI" }
  public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: HandFan.id, addPrefix: prefix) }
  public static func getRootAsHandFan(bb: ByteBuffer) -> HandFan { return HandFan(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
  private init(_ t: Table) { _accessor = t }
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
  private enum VTOFFSET: VOffset {
    case length = 4
    var v: Int32 { Int32(self.rawValue) }
    var p: VOffset { self.rawValue }
  }
  public var length: Int32 { let o = _accessor.offset(VTOFFSET.length.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) }
  public static func startHandFan(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
  public static func add(length: Int32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: length, def: 0, at: VTOFFSET.length.p) }
  public static func endHandFan(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
  public static func createHandFan(
    _ fbb: inout FlatBufferBuilder,
    length: Int32 = 0
  ) -> Offset {
    let __start = HandFan.startHandFan(&fbb)
    HandFan.add(length: length, &fbb)
    return HandFan.endHandFan(&fbb, start: __start)
  }

  public mutating func unpack() -> HandFanT {
    return HandFanT(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout HandFanT?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout HandFanT) -> Offset {
    let __root = HandFan.startHandFan(&builder)
    HandFan.add(length: obj.length, &builder)
    return HandFan.endHandFan(&builder, start: __root)
  }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    var _v = try verifier.visitTable(at: position)
    try _v.visit(field: VTOFFSET.length.p, fieldName: "length", required: false, type: Int32.self)
    _v.finish()
  }
}
extension HandFan: Encodable {
  enum CodingKeys: String, CodingKey {
    case length = "length"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if length != 0 {
      try container.encodeIfPresent(length, forKey: .length)
    }
  }
}
public class HandFanT: NativeObject {
  public var length: Int32
  public init(_ _t: inout HandFan) {
    length = _t.length
  }
  public init() {
    length = 0
  }
  public func serialize() -> ByteBuffer { return serialize(type: HandFan.self) }
}
public struct Movie: FlatBufferObject, Verifiable, ObjectAPIPacker {
  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Table
  public static var id: String { "MOVI" }
  public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Movie.id, addPrefix: prefix) }
  public static func getRootAsMovie(bb: ByteBuffer) -> Movie { return Movie(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
  private init(_ t: Table) { _accessor = t }
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
  private enum VTOFFSET: VOffset {
    case mainCharacterType = 4
    case mainCharacter = 6
    case charactersType = 8
    case characters = 10
    var v: Int32 { Int32(self.rawValue) }
    var p: VOffset { self.rawValue }
  }
  public var mainCharacterType: Character { let o = _accessor.offset(VTOFFSET.mainCharacterType.v); return o == 0 ? .none_ : Character(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
  public func mainCharacter<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.mainCharacter.v); return o == 0 ? nil : _accessor.union(o) }
  public var hasCharactersType: Bool { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? false : true }
  public var charactersTypeCount: Int32 { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? 0 : _accessor.vector(count: o) }
  public func charactersType(at index: Int32) -> Character? { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? Character.none_ : Character(rawValue: _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1)) }
  public var hasCharacters: Bool { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? false : true }
  public var charactersCount: Int32 { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? 0 : _accessor.vector(count: o) }
  public func characters<T: FlatbuffersInitializable>(at index: Int32, type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? nil : _accessor.directUnion(_accessor.vector(at: o) + index * 4) }
  public static func startMovie(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 4) }
  public static func add(mainCharacterType: Character, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mainCharacterType.rawValue, def: 0, at: VTOFFSET.mainCharacterType.p) }
  public static func add(mainCharacter: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: mainCharacter, at: VTOFFSET.mainCharacter.p) }
  public static func addVectorOf(charactersType: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: charactersType, at: VTOFFSET.charactersType.p) }
  public static func addVectorOf(characters: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: characters, at: VTOFFSET.characters.p) }
  public static func endMovie(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
  public static func createMovie(
    _ fbb: inout FlatBufferBuilder,
    mainCharacterType: Character = .none_,
    mainCharacterOffset mainCharacter: Offset = Offset(),
    charactersTypeVectorOffset charactersType: Offset = Offset(),
    charactersVectorOffset characters: Offset = Offset()
  ) -> Offset {
    let __start = Movie.startMovie(&fbb)
    Movie.add(mainCharacterType: mainCharacterType, &fbb)
    Movie.add(mainCharacter: mainCharacter, &fbb)
    Movie.addVectorOf(charactersType: charactersType, &fbb)
    Movie.addVectorOf(characters: characters, &fbb)
    return Movie.endMovie(&fbb, start: __start)
  }

  public mutating func unpack() -> MovieT {
    return MovieT(&self)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MovieT?) -> Offset {
    guard var obj = obj else { return Offset() }
    return pack(&builder, obj: &obj)
  }
  public static func pack(_ builder: inout FlatBufferBuilder, obj: inout MovieT) -> Offset {
    let __mainCharacter = obj.mainCharacter?.pack(builder: &builder) ?? Offset()
    var __characters__: [Offset] = []
    for i in obj.characters {
      guard let off = i?.pack(builder: &builder) else { continue }
      __characters__.append(off)
    }
    let __characters = builder.createVector(ofOffsets: __characters__)
    let __charactersType = builder.createVector(obj.characters.compactMap { $0?.type })
    let __root = Movie.startMovie(&builder)
    if let o = obj.mainCharacter?.type {
      Movie.add(mainCharacterType: o, &builder)
      Movie.add(mainCharacter: __mainCharacter, &builder)
    }
    Movie.addVectorOf(charactersType: __charactersType, &builder)
    Movie.addVectorOf(characters: __characters, &builder)
    return Movie.endMovie(&builder, start: __root)
  }
  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    var _v = try verifier.visitTable(at: position)
    try _v.visit(unionKey: VTOFFSET.mainCharacterType.p, unionField: VTOFFSET.mainCharacter.p, unionKeyName: "mainCharacterType", fieldName: "mainCharacter", required: false, completion: { (verifier, key: Character, pos) in
      switch key {
      case .none_:
        break // NOTE - SWIFT doesnt support none
      case .mulan:
        try ForwardOffset<Attacker>.verify(&verifier, at: pos, of: Attacker.self)
      case .rapunzel:
        try Rapunzel.verify(&verifier, at: pos, of: Rapunzel.self)
      case .belle:
        try BookReader.verify(&verifier, at: pos, of: BookReader.self)
      case .bookfan:
        try BookReader.verify(&verifier, at: pos, of: BookReader.self)
      case .other:
        try ForwardOffset<String>.verify(&verifier, at: pos, of: String.self)
      case .unused:
        try ForwardOffset<String>.verify(&verifier, at: pos, of: String.self)
      }
    })
    try _v.visitUnionVector(unionKey: VTOFFSET.charactersType.p, unionField: VTOFFSET.characters.p, unionKeyName: "charactersType", fieldName: "characters", required: false, completion: { (verifier, key: Character, pos) in
      switch key {
      case .none_:
        break // NOTE - SWIFT doesnt support none
      case .mulan:
        try ForwardOffset<Attacker>.verify(&verifier, at: pos, of: Attacker.self)
      case .rapunzel:
        try Rapunzel.verify(&verifier, at: pos, of: Rapunzel.self)
      case .belle:
        try BookReader.verify(&verifier, at: pos, of: BookReader.self)
      case .bookfan:
        try BookReader.verify(&verifier, at: pos, of: BookReader.self)
      case .other:
        try ForwardOffset<String>.verify(&verifier, at: pos, of: String.self)
      case .unused:
        try ForwardOffset<String>.verify(&verifier, at: pos, of: String.self)
      }
    })
    _v.finish()
  }
}
extension Movie: Encodable {
  enum CodingKeys: String, CodingKey {
    case mainCharacterType = "main_character_type"
    case mainCharacter = "main_character"
    case charactersType = "characters_type"
    case characters = "characters"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if mainCharacterType != .none_ {
      try container.encodeIfPresent(mainCharacterType, forKey: .mainCharacterType)
    }
    switch mainCharacterType {
    case .mulan:
      let _v = mainCharacter(type: Attacker.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    case .rapunzel:
      let _v = mainCharacter(type: Rapunzel.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    case .belle:
      let _v = mainCharacter(type: BookReader.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    case .bookfan:
      let _v = mainCharacter(type: BookReader.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    case .other:
      let _v = mainCharacter(type: String.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    case .unused:
      let _v = mainCharacter(type: String.self)
      try container.encodeIfPresent(_v, forKey: .mainCharacter)
    default: break;
    }
    if charactersCount > 0 {
      var enumsEncoder = container.nestedUnkeyedContainer(forKey: .charactersType)
      var contentEncoder = container.nestedUnkeyedContainer(forKey: .characters)
      for index in 0..<charactersCount {
        guard let type = charactersType(at: index) else { continue }
        try enumsEncoder.encode(type)
        switch type {
        case .mulan:
          let _v = characters(at: index, type: Attacker.self)
          try contentEncoder.encode(_v)
        case .rapunzel:
          let _v = characters(at: index, type: Rapunzel.self)
          try contentEncoder.encode(_v)
        case .belle:
          let _v = characters(at: index, type: BookReader.self)
          try contentEncoder.encode(_v)
        case .bookfan:
          let _v = characters(at: index, type: BookReader.self)
          try contentEncoder.encode(_v)
        case .other:
          let _v = characters(at: index, type: String.self)
          try contentEncoder.encode(_v)
        case .unused:
          let _v = characters(at: index, type: String.self)
          try contentEncoder.encode(_v)
        default: break;
        }
      }
    }
  }
}
public class MovieT: NativeObject {
  public var mainCharacter: CharacterUnion?
  public var characters: [CharacterUnion?]
  public init(_ _t: inout Movie) {
    switch _t.mainCharacterType {
    case .mulan:
      var _v = _t.mainCharacter(type: Attacker.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .mulan)
    case .rapunzel:
      var _v = _t.mainCharacter(type: Rapunzel_Mutable.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .rapunzel)
    case .belle:
      var _v = _t.mainCharacter(type: BookReader_Mutable.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .belle)
    case .bookfan:
      var _v = _t.mainCharacter(type: BookReader_Mutable.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .bookfan)
    case .other:
      var _v = _t.mainCharacter(type: String.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .other)
    case .unused:
      var _v = _t.mainCharacter(type: String.self)
      mainCharacter = CharacterUnion(_v?.unpack(), type: .unused)
    default: break
    }
    characters = []
    for index in 0..<_t.charactersCount {
        switch _t.charactersType(at: index) {
        case .mulan:
          var _v = _t.characters(at: index, type: Attacker.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .mulan))
        case .rapunzel:
          var _v = _t.characters(at: index, type: Rapunzel_Mutable.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .rapunzel))
        case .belle:
          var _v = _t.characters(at: index, type: BookReader_Mutable.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .belle))
        case .bookfan:
          var _v = _t.characters(at: index, type: BookReader_Mutable.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .bookfan))
        case .other:
          var _v = _t.characters(at: index, type: String.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .other))
        case .unused:
          var _v = _t.characters(at: index, type: String.self)
          characters.append(CharacterUnion(_v?.unpack(), type: .unused))
        default: break
        }
    }
  }
  public init() {
    characters = []
  }
  public func serialize() -> ByteBuffer { return serialize(type: Movie.self) }
}


FlatbuffersDoubleTests

/*
final class FlatBuffersDoubleTests: XCTestCase {
  let country = "Norway"
  func testCreateFinish() {
    var b = FlatBufferBuilder(initialSize: 16)
    let countryOff = CountryDouble.createCountry(
      builder: &b,
      name: country,
      log: 200,
      lan: 100)
    b.finish(offset: countryOff)
    // swiftformat:disable all
    let v: [UInt8] = [
      16, 0, 0, 0, 0, 0, 10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10,
      0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 64, 0, 0, 0,
      0, 0, 0, 105, 64, 0, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119,
      97, 121, 0, 0
    ]
    // swiftformat:enable all
    XCTAssertEqual(b.sizedByteArray, v)
  }
  func testCreateFinishWithPrefix() {
    var b = FlatBufferBuilder(initialSize: 16)
    let countryOff = CountryDouble.createCountry(
      builder: &b,
      name: country,
      log: 200,
      lan: 100)
    b.finish(offset: countryOff, addPrefix: true)
    // swiftformat:disable all
    let v: [UInt8] = [
      60, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 28
      , 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 89, 64, 0, 0, 0, 0, 0, 0, 105, 64, 0, 0, 0,
      0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0
    ]
    // swiftformat:enable all
    XCTAssertEqual(b.sizedByteArray, v)
  }
}
class CountryDouble {
  static let offsets: (name: VOffset, lan: VOffset, lng: VOffset) = (4, 6, 8)
  private var table: Table
  private init(table t: Table) { table = t }
  static func getRootAsCountry(_ bb: ByteBuffer) -> CountryDouble {
    let pos = bb.read(def: Int32.self, position: Int(bb.size))
    return CountryDouble(table: Table(bb: bb, position: Int32(pos)))
  }
  static func createCountry(
    builder: inout FlatBufferBuilder,
    name: String,
    log: Double,
    lan: Double) -> Offset
  {
    createCountry(
      builder: &builder,
      offset: builder.create(string: name),
      log: log,
      lan: lan)
  }
  static func createCountry(
    builder: inout FlatBufferBuilder,
    offset: Offset,
    log: Double,
    lan: Double) -> Offset
  {
    let _start = builder.startTable(with: 3)
    CountryDouble.add(builder: &builder, lng: log)
    CountryDouble.add(builder: &builder, lan: lan)
    CountryDouble.add(builder: &builder, name: offset)
    return CountryDouble.end(builder: &builder, startOffset: _start)
  }
  static func end(
    builder: inout FlatBufferBuilder,
    startOffset: UOffset) -> Offset
  {
    Offset(offset: builder.endTable(at: startOffset))
  }
  static func add(builder: inout FlatBufferBuilder, name: String) {
    add(builder: &builder, name: builder.create(string: name))
  }
  static func add(builder: inout FlatBufferBuilder, name: Offset) {
    builder.add(offset: name, at: Country.offsets.name)
  }
  static func add(builder: inout FlatBufferBuilder, lan: Double) {
    builder.add(element: lan, def: 0, at: Country.offsets.lan)
  }
  static func add(builder: inout FlatBufferBuilder, lng: Double) {
    builder.add(element: lng, def: 0, at: Country.offsets.lng)
  }
}


FlatBuffersTests

/*
final class FlatBuffersTests: XCTestCase {
  let country = "Norway"
  func testEndian() { XCTAssertEqual(isLitteEndian, true) }
  func testOffset() {
    let o = Offset()
    let b = Offset(offset: 1)
    XCTAssertEqual(o.isEmpty, true)
    XCTAssertEqual(b.isEmpty, false)
  }
  func testCreateString() {
    let helloWorld = "Hello, world!"
    var b = FlatBufferBuilder(initialSize: 16)
    XCTAssertEqual(b.create(string: country).o, 12)
    XCTAssertEqual(b.create(string: helloWorld).o, 32)
    b.clear()
    XCTAssertEqual(b.create(string: helloWorld).o, 20)
    XCTAssertEqual(b.create(string: country).o, 32)
    b.clear()
    XCTAssertEqual(b.create(string: String(repeating: "a", count: 257)).o, 264)
  }
  func testStartTable() {
    var b = FlatBufferBuilder(initialSize: 16)
    XCTAssertNoThrow(b.startTable(with: 0))
    b.clear()
    XCTAssertEqual(b.create(string: country).o, 12)
    XCTAssertEqual(b.startTable(with: 0), 12)
  }
  func testCreateFinish() {
    var b = FlatBufferBuilder(initialSize: 16)
    let countryOff = Country.createCountry(
      builder: &b,
      name: country,
      log: 200,
      lan: 100)
    b.finish(offset: countryOff)
    // swiftformat:disable all
    let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
    // swiftformat:enable all
    XCTAssertEqual(b.sizedByteArray, v)
  }
  func testCreateFinishWithPrefix() {
    var b = FlatBufferBuilder(initialSize: 16)
    let countryOff = Country.createCountry(
      builder: &b,
      name: country,
      log: 200,
      lan: 100)
    b.finish(offset: countryOff, addPrefix: true)
    // swiftformat:disable all
    let v: [UInt8] = [44, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
    // swiftformat:enable all
    XCTAssertEqual(b.sizedByteArray, v)
  }
  func testReadCountry() {
    // swiftformat:disable all
    let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
    // swiftformat:enable all
    let buffer = ByteBuffer(bytes: v)
    let c = Country.getRootAsCountry(buffer)
    XCTAssertEqual(c.lan, 100)
    XCTAssertEqual(c.log, 200)
    XCTAssertEqual(c.nameVector, [78, 111, 114, 119, 97, 121])
    XCTAssertEqual(c.name, country)
  }
  func testWriteNullableStrings() {
    var b = FlatBufferBuilder()
    XCTAssertTrue(b.create(string: nil).isEmpty)
    XCTAssertTrue(b.createShared(string: nil).isEmpty)
  }
  func testWriteOptionalValues() {
    var b = FlatBufferBuilder()
    let root = optional_scalars_ScalarStuff.createScalarStuff(
      &b,
      justI8: 80,
      maybeI8: nil,
      justU8: 100,
      maybeU8: 10,
      maybeBool: true,
      justEnum: .one,
      maybeEnum: nil)
    b.finish(offset: root)
    let scalarTable = optional_scalars_ScalarStuff
      .getRootAsScalarStuff(bb: b.sizedBuffer)
    XCTAssertEqual(scalarTable.justI8, 80)
    XCTAssertNil(scalarTable.maybeI8)
    XCTAssertEqual(scalarTable.maybeBool, true)
    XCTAssertEqual(scalarTable.defaultI8, 42)
    XCTAssertEqual(scalarTable.justU8, 100)
    XCTAssertEqual(scalarTable.maybeU8, 10)
    XCTAssertEqual(scalarTable.justEnum, .one)
    XCTAssertNil(scalarTable.maybeEnum)
  }
}
class Country {
  static let offsets: (name: VOffset, lan: VOffset, lng: VOffset) = (4, 6, 8)
  private var __t: Table
  private init(_ t: Table) {
    __t = t
  }
  var lan: Int32 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(
    of: Int32.self,
    at: o) }
  var log: Int32 { let o = __t.offset(8); return o == 0 ? 0 : __t.readBuffer(
    of: Int32.self,
    at: o) }
  var nameVector: [UInt8]? { __t.getVector(at: 4) }
  var name: String? {
    let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) }
  static func createCountry(
    builder: inout FlatBufferBuilder,
    name: String,
    log: Int32,
    lan: Int32) -> Offset
  {
    createCountry(
      builder: &builder,
      offset: builder.create(string: name),
      log: log,
      lan: lan)
  }
  static func end(
    builder: inout FlatBufferBuilder,
    startOffset: UOffset) -> Offset
  {
    Offset(offset: builder.endTable(at: startOffset))
  }
  static func add(builder: inout FlatBufferBuilder, lng: Int32) {
    builder.add(element: lng, def: 0, at: Country.offsets.lng)
  }
}


// automatically generated by the FlatBuffers compiler, do not modify
// swiftlint:disable all
// swiftformat:disable all

import FlatBuffers

public struct Swift_Tests_Vectors: FlatBufferObject, Verifiable {

  static func validateVersion() { FlatBuffersVersion_2_0_0() }
  public var __buffer: ByteBuffer! { return _accessor.bb }
  private var _accessor: Table

  public static func getRootAsVectors(bb: ByteBuffer) -> Swift_Tests_Vectors { return Swift_Tests_Vectors(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }

  private init(_ t: Table) { _accessor = t }
  public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }

  private enum VTOFFSET: VOffset {
    case none_ = 4
    case empty = 6
    case array = 8
    var v: Int32 { Int32(self.rawValue) }
    var p: VOffset { self.rawValue }
  }

  public var hasNone: Bool { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? false : true }
  public var none_Count: Int32 { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? 0 : _accessor.vector(count: o) }
  public func none_(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
  public var none_: [UInt64] { return _accessor.getVector(at: VTOFFSET.none_.v) ?? [] }
  public var hasEmpty: Bool { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? false : true }
  public var emptyCount: Int32 { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? 0 : _accessor.vector(count: o) }
  public func empty(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
  public var empty: [UInt64] { return _accessor.getVector(at: VTOFFSET.empty.v) ?? [] }
  public var hasArray: Bool { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? false : true }
  public var arrayCount: Int32 { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? 0 : _accessor.vector(count: o) }
  public func array(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
  public var array: [UInt64] { return _accessor.getVector(at: VTOFFSET.array.v) ?? [] }
  public static func startVectors(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 3) }
  public static func addVectorOf(none_: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: none_, at: VTOFFSET.none_.p) }
  public static func addVectorOf(empty: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: empty, at: VTOFFSET.empty.p) }
  public static func addVectorOf(array: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: array, at: VTOFFSET.array.p) }
  public static func endVectors(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
  public static func createVectors(
    _ fbb: inout FlatBufferBuilder,
    none_VectorOffset none_: Offset = Offset(),
    emptyVectorOffset empty: Offset = Offset(),
    arrayVectorOffset array: Offset = Offset()
  ) -> Offset {
    let __start = Swift_Tests_Vectors.startVectors(&fbb)
    Swift_Tests_Vectors.addVectorOf(none_: none_, &fbb)
    Swift_Tests_Vectors.addVectorOf(empty: empty, &fbb)
    Swift_Tests_Vectors.addVectorOf(array: array, &fbb)
    return Swift_Tests_Vectors.endVectors(&fbb, start: __start)
  }

  public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
    var _v = try verifier.visitTable(at: position)
    try _v.visit(field: VTOFFSET.none_.p, fieldName: "none_", required: false, type: ForwardOffset<Vector<UInt64, UInt64>>.self)
    try _v.visit(field: VTOFFSET.empty.p, fieldName: "empty", required: false, type: ForwardOffset<Vector<UInt64, UInt64>>.self)
    try _v.visit(field: VTOFFSET.array.p, fieldName: "array", required: false, type: ForwardOffset<Vector<UInt64, UInt64>>.self)
    _v.finish()
  }
}

extension Swift_Tests_Vectors: Encodable {

  enum CodingKeys: String, CodingKey {
    case none_ = "none"
    case empty = "empty"
    case array = "array"
  }
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if none_Count > 0 {
      try container.encodeIfPresent(none_, forKey: .none_)
    }
    if emptyCount > 0 {
      try container.encodeIfPresent(empty, forKey: .empty)
    }
    if arrayCount > 0 {
      try container.encodeIfPresent(array, forKey: .array)
    }
  }
}