[Swift] RFC: Switch Swift namespace from public enum to ordinary concat with _ (#6045)

This PR attempts to switch namespace from public enum back to ordinary
concat with _ in Swift. This kept style similar with protobuf, but
different from other popular style guide in Swift.

This is needed because previously, when we do `public enum`, we don't
really know when to declare and when to extend (extension). With namespace
implementation in this PR, there is no such ambiguity.
This commit is contained in:
Liu Liu
2020-07-27 01:06:11 -07:00
committed by GitHub
parent 18b015d25a
commit 5d052f4e55
7 changed files with 524 additions and 587 deletions

View File

@@ -2,10 +2,10 @@ import XCTest
import Foundation
@testable import FlatBuffers
public typealias Test = MyGame.Example.Test
public typealias Monster = MyGame.Example.Monster
public typealias Vec3 = MyGame.Example.Vec3
public typealias Stat = MyGame.Example.Stat
public typealias Test = MyGame_Example_Test
public typealias Monster = MyGame_Example_Monster
public typealias Vec3 = MyGame_Example_Vec3
public typealias Stat = MyGame_Example_Stat
class FlatBuffersMonsterWriterTests: XCTestCase {
@@ -57,7 +57,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
func testCreateMonsterUsingCreateMonsterMethodWithPosX() {
var fbb = FlatBufferBuilder(initialSize: 1)
let pos = MyGame.Example.createVec3(x: 10, test2: .blue)
let pos = MyGame_Example_Vec3.createVec3(x: 10, test2: .blue)
let name = fbb.create(string: "Barney")
let monster = Monster.createMonster(&fbb, structOfPos: pos, offsetOfName: name)
fbb.finish(offset: monster)
@@ -68,7 +68,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
func testReadMonsterFromUnsafePointerWithoutCopying() {
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]
let unpacked = array.withUnsafeMutableBytes { (memory) -> MyGame.Example.MonsterT in
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)
@@ -81,7 +81,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
func readMonster(fb: ByteBuffer) {
var monster = Monster.getRootAsMonster(bb: fb)
readFlatbufferMonster(monster: &monster)
var unpacked: MyGame.Example.MonsterT? = monster.unpack()
var unpacked: MyGame_Example_MonsterT? = monster.unpack()
readObjectApi(monster: unpacked!)
var builder = FlatBufferBuilder()
let root = Monster.pack(&builder, obj: &unpacked)
@@ -116,13 +116,13 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let mon1Start = Monster.startMonster(&fbb)
Monster.add(name: fred, &fbb)
let mon2 = Monster.endMonster(&fbb, start: mon1Start)
let test4 = fbb.createVector(structs: [MyGame.Example.createTest(a: 30, b: 40),
MyGame.Example.createTest(a: 10, b: 20)],
let test4 = fbb.createVector(structs: [MyGame_Example_Test.createTest(a: 30, b: 40),
MyGame_Example_Test.createTest(a: 10, b: 20)],
type: Test.self)
let stringTestVector = fbb.createVector(ofOffsets: [test1, test2])
let posStruct = MyGame.Example.createVec3(x: 1, y: 2, z: 3, test1: 3, test2: .green, test3a: 5, test3b: 6)
let posStruct = MyGame_Example_Vec3.createVec3(x: 1, y: 2, z: 3, test1: 3, test2: .green, test3a: 5, test3b: 6)
let mStart = Monster.startMonster(&fbb)
Monster.add(pos: posStruct, &fbb)
Monster.add(hp: 80, &fbb)
@@ -180,7 +180,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertTrue(vec?.mutate(test1: 3) ?? false)
}
func readFlatbufferMonster(monster: inout MyGame.Example.Monster) {
func readFlatbufferMonster(monster: inout MyGame_Example_Monster) {
XCTAssertEqual(monster.hp, 80)
XCTAssertEqual(monster.mana, 150)
XCTAssertEqual(monster.name, "MyMonster")
@@ -233,7 +233,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
}
}
func readObjectApi(monster: MyGame.Example.MonsterT) {
func readObjectApi(monster: MyGame_Example_MonsterT) {
XCTAssertEqual(monster.hp, 80)
XCTAssertEqual(monster.mana, 150)
XCTAssertEqual(monster.name, "MyMonster")
@@ -246,7 +246,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let test = pos?.test3
XCTAssertEqual(test?.a, 5)
XCTAssertEqual(test?.b, 6)
let monster2 = monster.test?.value as? MyGame.Example.MonsterT
let monster2 = monster.test?.value as? MyGame_Example_MonsterT
XCTAssertEqual(monster2?.name, "Fred")
XCTAssertEqual(monster.mana, 150)
monster.mana = 10