From 164f555b86acf9a226e1abf7348a123109d26919 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sat, 31 Aug 2019 15:15:18 -0400 Subject: [PATCH 01/54] basic layout for CoreBluetooth transport --- .idea/.gitignore | 3 + .idea/.name | 1 + .idea/UB.swift.iml | 2 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/runConfigurations/Node.xml | 11 ++ .idea/runConfigurations/UB_Package.xml | 11 ++ .idea/vcs.xml | 6 + .idea/xcode.xml | 4 + Package.swift | 7 + Sources/Main/main.swift | 9 ++ .../Transports/CoreBluetoothTransport.swift | 147 ++++++++++++++++++ Sources/UB/{ => Transports}/Transport.swift | 0 13 files changed, 215 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/UB.swift.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations/Node.xml create mode 100644 .idea/runConfigurations/UB_Package.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/xcode.xml create mode 100644 Sources/Main/main.swift create mode 100644 Sources/UB/Transports/CoreBluetoothTransport.swift rename Sources/UB/{ => Transports}/Transport.swift (100%) diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..256f165 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +UB \ No newline at end of file diff --git a/.idea/UB.swift.iml b/.idea/UB.swift.iml new file mode 100644 index 0000000..74121dc --- /dev/null +++ b/.idea/UB.swift.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b41bfb0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Node.xml b/.idea/runConfigurations/Node.xml new file mode 100644 index 0000000..6bb0e3d --- /dev/null +++ b/.idea/runConfigurations/Node.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/UB_Package.xml b/.idea/runConfigurations/UB_Package.xml new file mode 100644 index 0000000..c9bcbe0 --- /dev/null +++ b/.idea/runConfigurations/UB_Package.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/xcode.xml b/.idea/xcode.xml new file mode 100644 index 0000000..8b9173a --- /dev/null +++ b/.idea/xcode.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Package.swift b/Package.swift index 365a3ef..84c3bf2 100644 --- a/Package.swift +++ b/Package.swift @@ -10,6 +10,10 @@ let package = Package( .library( name: "UB", targets: ["UB"]), + .executable( + name: "Main", + targets: ["Main"] + ) ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -21,6 +25,9 @@ let package = Package( .target( name: "UB", dependencies: []), + .target( + name: "Main", + dependencies: ["UB"]), .testTarget( name: "UBTests", dependencies: ["UB"]), diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift new file mode 100644 index 0000000..4e63bb8 --- /dev/null +++ b/Sources/Main/main.swift @@ -0,0 +1,9 @@ +import Foundation +import UB + + +let UBBT = CoreBluetoothTransport() + + + +RunLoop.current.run() diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift new file mode 100644 index 0000000..3122929 --- /dev/null +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -0,0 +1,147 @@ +import Foundation +import CoreBluetooth + + +/// CoreBluetoothTransport is used to send and receieve message over Bluetooth +public class CoreBluetoothTransport: NSObject, Transport { + + private var centralManager: CBCentralManager? + private var peripheralManager: CBPeripheralManager? + + private var testServiceID = CBUUID(string: "0xAAAA") + private var testServiceID2 = CBUUID(string: "0xBBBB") + + private var perp: CBPeripheral? // make this an array for multiple devices + + + public override convenience init(){ + self.init(cbManager: CBCentralManager(delegate: nil, queue: nil), + periphManager: CBPeripheralManager(delegate: nil, queue: nil)) + centralManager?.delegate = self + peripheralManager?.delegate = self + } + + public init(cbManager: CBCentralManager, periphManager: CBPeripheralManager) { + super.init() + centralManager = cbManager + peripheralManager = periphManager + + } + + + /// Send implements a function to send messages between nodes using Bluetooth + /// + /// - Parameters: + /// - message: The message to send. + public func send(message: Message) { + print("A") + } + + /// Listen implements a function to receive messages being sent to a node. + /// + /// - Parameters: + /// - handler: The message handler to handle received messages. + public func listen(_ handler: (Message) -> Void) { + print("B") + } + +} + +extension CoreBluetoothTransport: CBPeripheralManagerDelegate { + public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { + <#code#> + } +} + + +extension CoreBluetoothTransport: CBCentralManagerDelegate { + public func centralManagerDidUpdateState(_ central: CBCentralManager) { + switch central.state { + + case .unknown: + print("Bluetooth status is UNKNOWN") + case .resetting: + print("Bluetooth status is RESETTING") + case .unsupported: + print("Bluetooth status is UNSUPPORTED") + case .unauthorized: + print("Bluetooth status is UNAUTHORIZED") + case .poweredOff: + print("Bluetooth status is POWERED OFF") + case .poweredOn: + print("Bluetooth status is POWERED ON") + + centralManager?.scanForPeripherals(withServices: nil) + + } + } + + public func centralManager(_ central: CBCentralManager, + didDiscover peripheral: CBPeripheral, + advertisementData: [String : Any], + rssi RSSI: NSNumber) { + if let x = peripheral.name { + + //peripheral.discoverServices(nil) + // perp = peripheral; + if x == "Blank"{ + perp = peripheral + perp?.delegate = self + + print(x) + decodePeripheralState(peripheralState: peripheral.state) + centralManager?.connect(perp!) + } + } + } + + public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { + + // STEP 8: look for services of interest on peripheral + print("gunna start discoverSerivces") + perp?.discoverServices(nil) + + } + + public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { + print("servicessssss ") + for service in peripheral.services! { + + print("Service: \(service)") + + // STEP 9: look for characteristics of interest + // within services of interest + //peripheral.discoverCharacteristics(nil, for: service) + + } + } + + + + + func decodePeripheralState(peripheralState: CBPeripheralState) { + + switch peripheralState { + case .disconnected: + print("Peripheral state: disconnected") + case .connected: + print("Peripheral state: connected") + case .connecting: + print("Peripheral state: connecting") + case .disconnecting: + print("Peripheral state: disconnecting") + } + + } +} + +extension CoreBluetoothTransport: CBPeripheralDelegate{ + +} + + +extension CoreBluetoothTransport { + public func startScanning() { + + } +} diff --git a/Sources/UB/Transport.swift b/Sources/UB/Transports/Transport.swift similarity index 100% rename from Sources/UB/Transport.swift rename to Sources/UB/Transports/Transport.swift From 75b6157c92bc8ce5d30d69c08c6074eba5939e91 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sat, 31 Aug 2019 15:33:40 -0400 Subject: [PATCH 02/54] Can discover and connect to devices with service ID AAAA --- .../Transports/CoreBluetoothTransport.swift | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 3122929..a2ebaa9 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -12,19 +12,19 @@ public class CoreBluetoothTransport: NSObject, Transport { private var testServiceID2 = CBUUID(string: "0xBBBB") private var perp: CBPeripheral? // make this an array for multiple devices - + private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices public override convenience init(){ - self.init(cbManager: CBCentralManager(delegate: nil, queue: nil), - periphManager: CBPeripheralManager(delegate: nil, queue: nil)) + self.init(centralManager: CBCentralManager(delegate: nil, queue: nil), + peripheralManager: CBPeripheralManager(delegate: nil, queue: nil)) centralManager?.delegate = self peripheralManager?.delegate = self } - public init(cbManager: CBCentralManager, periphManager: CBPeripheralManager) { + public init(centralManager: CBCentralManager, peripheralManager: CBPeripheralManager) { super.init() - centralManager = cbManager - peripheralManager = periphManager + self.centralManager = centralManager + self.peripheralManager = peripheralManager } @@ -49,12 +49,19 @@ public class CoreBluetoothTransport: NSObject, Transport { extension CoreBluetoothTransport: CBPeripheralManagerDelegate { public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { - <#code#> +// if (peripheral.state == .poweredOn){ +// +// let advertisementData = String(format: "%@|%d|%d", userData.name, userData.avatarId, userData.colorId) +// peripheralManager.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[SERVICE_UUID], +// CBAdvertisementDataLocalNameKey: advertisementData]) +// } } } extension CoreBluetoothTransport: CBCentralManagerDelegate { + + /// Lets us know if Bluetooth is in correct state to start. public func centralManagerDidUpdateState(_ central: CBCentralManager) { switch central.state { @@ -70,8 +77,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { print("Bluetooth status is POWERED OFF") case .poweredOn: print("Bluetooth status is POWERED ON") - - centralManager?.scanForPeripherals(withServices: nil) + centralManager?.scanForPeripherals(withServices: [testServiceID]) } } @@ -81,24 +87,19 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { advertisementData: [String : Any], rssi RSSI: NSNumber) { if let x = peripheral.name { + perp = peripheral + perp?.delegate = self + peripherals.append(perp) - //peripheral.discoverServices(nil) - // perp = peripheral; - if x == "Blank"{ - perp = peripheral - perp?.delegate = self - - print(x) - decodePeripheralState(peripheralState: peripheral.state) - centralManager?.connect(perp!) - } + print("LOLZ ", x) + decodePeripheralState(peripheralState: peripheral.state) + centralManager?.connect(perp!) } } public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { - // STEP 8: look for services of interest on peripheral - print("gunna start discoverSerivces") + // look for services of interest on peripheral perp?.discoverServices(nil) } From f4d00154d13dc5a552ecc9b78c552b637f4968f1 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sat, 31 Aug 2019 15:55:41 -0400 Subject: [PATCH 03/54] add .idea to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2bf0d33..49c3d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ xcuserdata/ *.moved-aside *.xccheckout *.xcscmblueprint +.idea ## Obj-C/Swift specific *.hmap From 11f0cc3c809c885015a9d2312592b6db2b20de5d Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sat, 31 Aug 2019 15:59:44 -0400 Subject: [PATCH 04/54] Can see characteristics of devices --- .../Transports/CoreBluetoothTransport.swift | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index a2ebaa9..b1d27b4 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -77,48 +77,35 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { print("Bluetooth status is POWERED OFF") case .poweredOn: print("Bluetooth status is POWERED ON") - centralManager?.scanForPeripherals(withServices: [testServiceID]) + centralManager?.scanForPeripherals(withServices: [testServiceID, testServiceID2]) } } + // Try to connect to discovered devices public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { - if let x = peripheral.name { perp = peripheral perp?.delegate = self peripherals.append(perp) - - print("LOLZ ", x) + print(peripherals.count) decodePeripheralState(peripheralState: peripheral.state) centralManager?.connect(perp!) - } } + // When connected to a devices, ask for the Services public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { - // look for services of interest on peripheral - perp?.discoverServices(nil) - - } - - public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { - print("servicessssss ") - for service in peripheral.services! { - - print("Service: \(service)") - - // STEP 9: look for characteristics of interest - // within services of interest - //peripheral.discoverCharacteristics(nil, for: service) - - } + perp?.discoverServices([testServiceID, testServiceID2]) } + // Handle Disconnections + public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { + } func decodePeripheralState(peripheralState: CBPeripheralState) { @@ -137,6 +124,22 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { } extension CoreBluetoothTransport: CBPeripheralDelegate{ + // ask for Characteristics for each Service of interest + public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { + print("servicessssss ") + for service in peripheral.services! { + print("Service: \(service)") + peripheral.discoverCharacteristics(nil, for: service) + } + } + + // called with characteristics + public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { + for characteristic in service.characteristics! { + print("Characteristic: \(characteristic)") + } + } + } From 396a2379316bbb05ebda9181d9f20c06d0364573 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sat, 31 Aug 2019 16:12:25 -0400 Subject: [PATCH 05/54] Can read values of characteristics --- .../Transports/CoreBluetoothTransport.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index b1d27b4..85d4929 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -14,7 +14,7 @@ public class CoreBluetoothTransport: NSObject, Transport { private var perp: CBPeripheral? // make this an array for multiple devices private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices - public override convenience init(){ + public override convenience init() { self.init(centralManager: CBCentralManager(delegate: nil, queue: nil), peripheralManager: CBPeripheralManager(delegate: nil, queue: nil)) centralManager?.delegate = self @@ -137,9 +137,18 @@ extension CoreBluetoothTransport: CBPeripheralDelegate{ public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { for characteristic in service.characteristics! { print("Characteristic: \(characteristic)") + peripheral.readValue(for: characteristic) + } } + // called when reading a value from peripheral + public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { + let data = Data(bytes: characteristic.value!) + print("Characteristic Value: \(data.hexEncodedString())") + } + + } @@ -149,3 +158,16 @@ extension CoreBluetoothTransport { } } + + +extension Data { + struct HexEncodingOptions: OptionSet { + let rawValue: Int + static let upperCase = HexEncodingOptions(rawValue: 1 << 0) + } + + func hexEncodedString(options: HexEncodingOptions = []) -> String { + let format = options.contains(.upperCase) ? "%02hhX" : "%02hhx" + return map { String(format: format, $0) }.joined() + } +} From 1a39b5f80f4d57e200be1b623bf78496ca80ee7a Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sun, 1 Sep 2019 13:45:30 -0400 Subject: [PATCH 06/54] remove .idea --- .idea/.gitignore | 3 --- .idea/.name | 1 - .idea/UB.swift.iml | 2 -- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/runConfigurations/Node.xml | 11 ----------- .idea/runConfigurations/UB_Package.xml | 11 ----------- .idea/vcs.xml | 6 ------ .idea/xcode.xml | 4 ---- 9 files changed, 52 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/UB.swift.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations/Node.xml delete mode 100644 .idea/runConfigurations/UB_Package.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/xcode.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 0e40fe8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 256f165..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -UB \ No newline at end of file diff --git a/.idea/UB.swift.iml b/.idea/UB.swift.iml deleted file mode 100644 index 74121dc..0000000 --- a/.idea/UB.swift.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b41bfb0..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Node.xml b/.idea/runConfigurations/Node.xml deleted file mode 100644 index 6bb0e3d..0000000 --- a/.idea/runConfigurations/Node.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/UB_Package.xml b/.idea/runConfigurations/UB_Package.xml deleted file mode 100644 index c9bcbe0..0000000 --- a/.idea/runConfigurations/UB_Package.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/xcode.xml b/.idea/xcode.xml deleted file mode 100644 index 8b9173a..0000000 --- a/.idea/xcode.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 02a1edca4cb2e7e40b943edbc761ca3d558990ba Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sun, 1 Sep 2019 13:51:37 -0400 Subject: [PATCH 07/54] Move Transport to extension --- Sources/UB/Transports/CoreBluetoothTransport.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 85d4929..7abb614 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -3,7 +3,7 @@ import CoreBluetooth /// CoreBluetoothTransport is used to send and receieve message over Bluetooth -public class CoreBluetoothTransport: NSObject, Transport { +public class CoreBluetoothTransport: NSObject { private var centralManager: CBCentralManager? private var peripheralManager: CBPeripheralManager? @@ -28,6 +28,9 @@ public class CoreBluetoothTransport: NSObject, Transport { } +} + +extension CoreBluetoothTransport: Transport { /// Send implements a function to send messages between nodes using Bluetooth /// From 4d85b241e7d913b482a2d3661bad740ba9872a35 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sun, 1 Sep 2019 14:00:16 -0400 Subject: [PATCH 08/54] Create Extensions folder --- Sources/UB/Extensions/Data+HexEncoding.swift | 13 +++++++++++++ Sources/UB/Transports/CoreBluetoothTransport.swift | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 Sources/UB/Extensions/Data+HexEncoding.swift diff --git a/Sources/UB/Extensions/Data+HexEncoding.swift b/Sources/UB/Extensions/Data+HexEncoding.swift new file mode 100644 index 0000000..794f7e9 --- /dev/null +++ b/Sources/UB/Extensions/Data+HexEncoding.swift @@ -0,0 +1,13 @@ +import Foundation + +extension Data { + struct HexEncodingOptions: OptionSet { + let rawValue: Int + static let upperCase = HexEncodingOptions(rawValue: 1 << 0) + } + + func hexEncodedString(options: HexEncodingOptions = []) -> String { + let format = options.contains(.upperCase) ? "%02hhX" : "%02hhx" + return map { String(format: format, $0) }.joined() + } +} diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 7abb614..4ee8569 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -162,15 +162,3 @@ extension CoreBluetoothTransport { } } - -extension Data { - struct HexEncodingOptions: OptionSet { - let rawValue: Int - static let upperCase = HexEncodingOptions(rawValue: 1 << 0) - } - - func hexEncodedString(options: HexEncodingOptions = []) -> String { - let format = options.contains(.upperCase) ? "%02hhX" : "%02hhx" - return map { String(format: format, $0) }.joined() - } -} From cddafe4c143f09652166a2f3fa738743fb3b53d6 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Sun, 1 Sep 2019 14:33:50 -0400 Subject: [PATCH 09/54] UNTESTED: can probably send and receive abc --- .../Transports/CoreBluetoothTransport.swift | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 4ee8569..d90cd29 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -51,13 +51,27 @@ extension CoreBluetoothTransport: Transport { } extension CoreBluetoothTransport: CBPeripheralManagerDelegate { + + // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { -// if (peripheral.state == .poweredOn){ -// -// let advertisementData = String(format: "%@|%d|%d", userData.name, userData.avatarId, userData.colorId) -// peripheralManager.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[SERVICE_UUID], -// CBAdvertisementDataLocalNameKey: advertisementData]) -// } + if (peripheral.state == .poweredOn){ + + peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[testServiceID, testServiceID2], + CBAdvertisementDataLocalNameKey: nil]) + } + } + + public func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { + + for request in requests { + if let value = request.value { + + let messageText = String(data: value, encoding: String.Encoding.utf8) as String! + print(messageText!) + //appendMessageToChat(message: Message(text: messageText!, isSent: false)) + } + peripheral.respond(to: request, withResult: .success) + } } } @@ -140,19 +154,25 @@ extension CoreBluetoothTransport: CBPeripheralDelegate{ public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { for characteristic in service.characteristics! { print("Characteristic: \(characteristic)") - peripheral.readValue(for: characteristic) + //peripheral.readValue(for: characteristic) + if characteristic.uuid == testServiceID { + print("Sending some good shit") + let data = Data(bytes: [97,98,99]) + peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withResponse) + } } } - // called when reading a value from peripheral - public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { - let data = Data(bytes: characteristic.value!) - print("Characteristic Value: \(data.hexEncodedString())") - } +// // called when reading a value from peripheral characteristic data field. +// public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { +// let data = Data(bytes: characteristic.value!) +// print("Characteristic Value: \(data.hexEncodedString())") +// } + } From d9a6f0b452d73f5250d72f7bf23f253032267652 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 2 Sep 2019 15:06:12 -0400 Subject: [PATCH 10/54] got sending and recieving working --- .../Transports/CoreBluetoothTransport.swift | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index d90cd29..a81147f 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -55,19 +55,35 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { if (peripheral.state == .poweredOn){ + + let WR_UUID = CBUUID(string: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") + let WR_PROPERTIES: CBCharacteristicProperties = .write + let WR_PERMISSIONS: CBAttributePermissions = .writeable + + let serialService = CBMutableService(type: testServiceID, primary: true) + + let writeCharacteristics = CBMutableCharacteristic(type: WR_UUID, + properties: WR_PROPERTIES, value: nil, + permissions: WR_PERMISSIONS) + serialService.characteristics = [writeCharacteristics] + peripheral.add(serialService) - peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[testServiceID, testServiceID2], + peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [testServiceID, testServiceID2], CBAdvertisementDataLocalNameKey: nil]) } } public func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { - + print("Got a message! Ding!") for request in requests { if let value = request.value { - let messageText = String(data: value, encoding: String.Encoding.utf8) as String! - print(messageText!) + if let messageText = String(data: value, encoding: String.Encoding.utf8) as String!{ + print("GOOOOTEEMMM \(messageText)") + + } else { + print("failed to decode string of \(value.hexEncodedString())") + } //appendMessageToChat(message: Message(text: messageText!, isSent: false)) } peripheral.respond(to: request, withResult: .success) @@ -155,11 +171,11 @@ extension CoreBluetoothTransport: CBPeripheralDelegate{ for characteristic in service.characteristics! { print("Characteristic: \(characteristic)") //peripheral.readValue(for: characteristic) - if characteristic.uuid == testServiceID { +// if characteristic.uuid == testServiceID { print("Sending some good shit") - let data = Data(bytes: [97,98,99]) - peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withResponse) - } + let data = Data(bytes: [97,98,99,100]) + peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) +// } } } From c2af52b7dc71b19bb530384b5e0e330032c2c937 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 2 Sep 2019 15:16:10 -0400 Subject: [PATCH 11/54] asthetics --- Sources/UB/Transports/CoreBluetoothTransport.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index a81147f..1512b06 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -15,8 +15,10 @@ public class CoreBluetoothTransport: NSObject { private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices public override convenience init() { - self.init(centralManager: CBCentralManager(delegate: nil, queue: nil), - peripheralManager: CBPeripheralManager(delegate: nil, queue: nil)) + self.init( + centralManager: CBCentralManager(delegate: nil, queue: nil), + peripheralManager: CBPeripheralManager(delegate: nil, queue: nil) + ) centralManager?.delegate = self peripheralManager?.delegate = self } From 436054425e869a763141c9b31b7063660c4aeaf5 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Wed, 4 Sep 2019 23:46:39 -0400 Subject: [PATCH 12/54] autocorrect --- Sources/Main/main.swift | 3 - Sources/UB/Extensions/Data+HexEncoding.swift | 2 +- .../Transports/CoreBluetoothTransport.swift | 71 ++++++++----------- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index 4e63bb8..d30891b 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -1,9 +1,6 @@ import Foundation import UB - let UBBT = CoreBluetoothTransport() - - RunLoop.current.run() diff --git a/Sources/UB/Extensions/Data+HexEncoding.swift b/Sources/UB/Extensions/Data+HexEncoding.swift index 794f7e9..92157b2 100644 --- a/Sources/UB/Extensions/Data+HexEncoding.swift +++ b/Sources/UB/Extensions/Data+HexEncoding.swift @@ -5,7 +5,7 @@ extension Data { let rawValue: Int static let upperCase = HexEncodingOptions(rawValue: 1 << 0) } - + func hexEncodedString(options: HexEncodingOptions = []) -> String { let format = options.contains(.upperCase) ? "%02hhX" : "%02hhx" return map { String(format: format, $0) }.joined() diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 1512b06..195b28c 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -1,19 +1,18 @@ import Foundation import CoreBluetooth - /// CoreBluetoothTransport is used to send and receieve message over Bluetooth public class CoreBluetoothTransport: NSObject { - + private var centralManager: CBCentralManager? private var peripheralManager: CBPeripheralManager? private var testServiceID = CBUUID(string: "0xAAAA") private var testServiceID2 = CBUUID(string: "0xBBBB") - + private var perp: CBPeripheral? // make this an array for multiple devices private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices - + public override convenience init() { self.init( centralManager: CBCentralManager(delegate: nil, queue: nil), @@ -22,18 +21,18 @@ public class CoreBluetoothTransport: NSObject { centralManager?.delegate = self peripheralManager?.delegate = self } - + public init(centralManager: CBCentralManager, peripheralManager: CBPeripheralManager) { super.init() self.centralManager = centralManager self.peripheralManager = peripheralManager } - + } extension CoreBluetoothTransport: Transport { - + /// Send implements a function to send messages between nodes using Bluetooth /// /// - Parameters: @@ -41,7 +40,7 @@ extension CoreBluetoothTransport: Transport { public func send(message: Message) { print("A") } - + /// Listen implements a function to receive messages being sent to a node. /// /// - Parameters: @@ -49,21 +48,21 @@ extension CoreBluetoothTransport: Transport { public func listen(_ handler: (Message) -> Void) { print("B") } - + } extension CoreBluetoothTransport: CBPeripheralManagerDelegate { - + // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { - if (peripheral.state == .poweredOn){ - + if (peripheral.state == .poweredOn) { + let WR_UUID = CBUUID(string: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") let WR_PROPERTIES: CBCharacteristicProperties = .write let WR_PERMISSIONS: CBAttributePermissions = .writeable - + let serialService = CBMutableService(type: testServiceID, primary: true) - + let writeCharacteristics = CBMutableCharacteristic(type: WR_UUID, properties: WR_PROPERTIES, value: nil, permissions: WR_PERMISSIONS) @@ -74,13 +73,13 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { CBAdvertisementDataLocalNameKey: nil]) } } - + public func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { print("Got a message! Ding!") for request in requests { if let value = request.value { - - if let messageText = String(data: value, encoding: String.Encoding.utf8) as String!{ + + if let messageText = String(data: value, encoding: String.Encoding.utf8) as String! { print("GOOOOTEEMMM \(messageText)") } else { @@ -93,13 +92,12 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { } } - extension CoreBluetoothTransport: CBCentralManagerDelegate { - + /// Lets us know if Bluetooth is in correct state to start. public func centralManagerDidUpdateState(_ central: CBCentralManager) { switch central.state { - + case .unknown: print("Bluetooth status is UNKNOWN") case .resetting: @@ -113,14 +111,14 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { case .poweredOn: print("Bluetooth status is POWERED ON") centralManager?.scanForPeripherals(withServices: [testServiceID, testServiceID2]) - + } } - + // Try to connect to discovered devices public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, - advertisementData: [String : Any], + advertisementData: [String: Any], rssi RSSI: NSNumber) { perp = peripheral perp?.delegate = self @@ -129,21 +127,19 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { decodePeripheralState(peripheralState: peripheral.state) centralManager?.connect(perp!) } - + // When connected to a devices, ask for the Services public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { // look for services of interest on peripheral perp?.discoverServices([testServiceID, testServiceID2]) } - - - + // Handle Disconnections public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { } - + func decodePeripheralState(peripheralState: CBPeripheralState) { - + switch peripheralState { case .disconnected: print("Peripheral state: disconnected") @@ -154,11 +150,11 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { case .disconnecting: print("Peripheral state: disconnecting") } - + } } -extension CoreBluetoothTransport: CBPeripheralDelegate{ +extension CoreBluetoothTransport: CBPeripheralDelegate { // ask for Characteristics for each Service of interest public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { print("servicessssss ") @@ -167,7 +163,7 @@ extension CoreBluetoothTransport: CBPeripheralDelegate{ peripheral.discoverCharacteristics(nil, for: service) } } - + // called with characteristics public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { for characteristic in service.characteristics! { @@ -175,28 +171,23 @@ extension CoreBluetoothTransport: CBPeripheralDelegate{ //peripheral.readValue(for: characteristic) // if characteristic.uuid == testServiceID { print("Sending some good shit") - let data = Data(bytes: [97,98,99,100]) + let data = Data(bytes: [97, 98, 99, 100]) peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) // } } } - + // // called when reading a value from peripheral characteristic data field. // public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { // let data = Data(bytes: characteristic.value!) // print("Characteristic Value: \(data.hexEncodedString())") // } - - - } - extension CoreBluetoothTransport { public func startScanning() { - + } } - From 7877229c8eeec2f6d46240c9fa531409eb94c41d Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 5 Sep 2019 00:05:42 -0400 Subject: [PATCH 13/54] some linting --- Package.swift | 13 +-- .../Transports/CoreBluetoothTransport.swift | 88 ++++++++----------- 2 files changed, 45 insertions(+), 56 deletions(-) diff --git a/Package.swift b/Package.swift index 50bf5d4..8b1008c 100644 --- a/Package.swift +++ b/Package.swift @@ -8,11 +8,12 @@ let package = Package( // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "UB", - targets: ["UB"]), + targets: ["UB"] + ), .executable( name: "Main", targets: ["Main"] - ) + ), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -23,10 +24,12 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "UB", - dependencies: []), - .target( + dependencies: [] + ), + .target( name: "Main", - dependencies: ["UB"]), + dependencies: ["UB"] + ), .testTarget( name: "UBTests", dependencies: ["UB"] diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 195b28c..83b07a1 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -1,11 +1,10 @@ -import Foundation import CoreBluetooth +import Foundation /// CoreBluetoothTransport is used to send and receieve message over Bluetooth public class CoreBluetoothTransport: NSObject { - - private var centralManager: CBCentralManager? - private var peripheralManager: CBPeripheralManager? + private let centralManager: CBCentralManager + private let peripheralManager: CBPeripheralManager private var testServiceID = CBUUID(string: "0xAAAA") private var testServiceID2 = CBUUID(string: "0xBBBB") @@ -13,31 +12,28 @@ public class CoreBluetoothTransport: NSObject { private var perp: CBPeripheral? // make this an array for multiple devices private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices - public override convenience init() { + public convenience override init() { self.init( centralManager: CBCentralManager(delegate: nil, queue: nil), peripheralManager: CBPeripheralManager(delegate: nil, queue: nil) ) - centralManager?.delegate = self - peripheralManager?.delegate = self } public init(centralManager: CBCentralManager, peripheralManager: CBPeripheralManager) { - super.init() self.centralManager = centralManager self.peripheralManager = peripheralManager - + super.init() + self.centralManager.delegate = self + self.peripheralManager.delegate = self } - } extension CoreBluetoothTransport: Transport { - /// Send implements a function to send messages between nodes using Bluetooth /// /// - Parameters: /// - message: The message to send. - public func send(message: Message) { + public func send(message _: Message) { print("A") } @@ -45,18 +41,15 @@ extension CoreBluetoothTransport: Transport { /// /// - Parameters: /// - handler: The message handler to handle received messages. - public func listen(_ handler: (Message) -> Void) { + public func listen(_: (Message) -> Void) { print("B") } - } extension CoreBluetoothTransport: CBPeripheralManagerDelegate { - // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { - if (peripheral.state == .poweredOn) { - + if peripheral.state == .poweredOn { let WR_UUID = CBUUID(string: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") let WR_PROPERTIES: CBCharacteristicProperties = .write let WR_PERMISSIONS: CBAttributePermissions = .writeable @@ -70,7 +63,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { peripheral.add(serialService) peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [testServiceID, testServiceID2], - CBAdvertisementDataLocalNameKey: nil]) + CBAdvertisementDataLocalNameKey: nil]) } } @@ -78,14 +71,13 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { print("Got a message! Ding!") for request in requests { if let value = request.value { - - if let messageText = String(data: value, encoding: String.Encoding.utf8) as String! { + if let messageText = String(data: value, encoding: String.Encoding.utf8) as! String? { print("GOOOOTEEMMM \(messageText)") } else { print("failed to decode string of \(value.hexEncodedString())") } - //appendMessageToChat(message: Message(text: messageText!, isSent: false)) + // appendMessageToChat(message: Message(text: messageText!, isSent: false)) } peripheral.respond(to: request, withResult: .success) } @@ -93,11 +85,9 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { } extension CoreBluetoothTransport: CBCentralManagerDelegate { - /// Lets us know if Bluetooth is in correct state to start. public func centralManagerDidUpdateState(_ central: CBCentralManager) { switch central.state { - case .unknown: print("Bluetooth status is UNKNOWN") case .resetting: @@ -110,36 +100,33 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { print("Bluetooth status is POWERED OFF") case .poweredOn: print("Bluetooth status is POWERED ON") - centralManager?.scanForPeripherals(withServices: [testServiceID, testServiceID2]) - + centralManager.scanForPeripherals(withServices: [testServiceID, testServiceID2]) } } // Try to connect to discovered devices - public func centralManager(_ central: CBCentralManager, - didDiscover peripheral: CBPeripheral, - advertisementData: [String: Any], - rssi RSSI: NSNumber) { - perp = peripheral - perp?.delegate = self - peripherals.append(perp) - print(peripherals.count) - decodePeripheralState(peripheralState: peripheral.state) - centralManager?.connect(perp!) + public func centralManager(_: CBCentralManager, + didDiscover peripheral: CBPeripheral, + advertisementData _: [String: Any], + rssi _: NSNumber) { + perp = peripheral + perp?.delegate = self + peripherals.append(perp) + print(peripherals.count) + decodePeripheralState(peripheralState: peripheral.state) + centralManager.connect(perp!) } // When connected to a devices, ask for the Services - public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { + public func centralManager(_: CBCentralManager, didConnect _: CBPeripheral) { // look for services of interest on peripheral perp?.discoverServices([testServiceID, testServiceID2]) } // Handle Disconnections - public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { - } + public func centralManager(_: CBCentralManager, didDisconnectPeripheral _: CBPeripheral, error _: Error?) {} func decodePeripheralState(peripheralState: CBPeripheralState) { - switch peripheralState { case .disconnected: print("Peripheral state: disconnected") @@ -150,13 +137,12 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { case .disconnecting: print("Peripheral state: disconnecting") } - } } extension CoreBluetoothTransport: CBPeripheralDelegate { // ask for Characteristics for each Service of interest - public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { + public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices _: Error?) { print("servicessssss ") for service in peripheral.services! { print("Service: \(service)") @@ -165,16 +151,19 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { } // called with characteristics - public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { + public func peripheral( + _ peripheral: CBPeripheral, + didDiscoverCharacteristicsFor service: CBService, + error _: Error? + ) { for characteristic in service.characteristics! { print("Characteristic: \(characteristic)") - //peripheral.readValue(for: characteristic) + // peripheral.readValue(for: characteristic) // if characteristic.uuid == testServiceID { - print("Sending some good shit") - let data = Data(bytes: [97, 98, 99, 100]) - peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) + print("Sending some good shit") + let data = Data(bytes: [97, 98, 99, 100]) + peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) // } - } } @@ -183,11 +172,8 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { // let data = Data(bytes: characteristic.value!) // print("Characteristic Value: \(data.hexEncodedString())") // } - } extension CoreBluetoothTransport { - public func startScanning() { - - } + public func startScanning() {} } From 9f5851115f32019014b9a8e2fb5c4a7b2932306a Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 5 Sep 2019 18:28:24 -0400 Subject: [PATCH 14/54] kinda works --- Sources/Main/main.swift | 40 ++++++++++ Sources/UB/Message.swift | 8 ++ .../Transports/CoreBluetoothTransport.swift | 74 ++++++++++++++++--- 3 files changed, 110 insertions(+), 12 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index d30891b..91fd624 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -2,5 +2,45 @@ import Foundation import UB let UBBT = CoreBluetoothTransport() +//var msgs: [Message] = [] +// +//for i in UInt8(0)...6 { +// let message = Message( +// proto: UBID(repeating: 1, count: 1), +// recipient: Addr(repeating: 4, count: 4), +// from: Addr(repeating: 2, count: 3), +// origin: Addr(repeating: 2, count: 3), +// message: Data(repeating: i, count: 3) +// ) +// UBBT.send(message: message, to: message.recipient) +// sleep() +//} + +//let iphoneUUID = UUID(uuidString: "71150DB7-F394-44C6-B161-FD116855E05D") + + +let iphoneUUID = "0BCD7956-7E10-4562-B5AF-D25F5D8D86AF".utf8 + +let message = Message( + proto: UBID(repeating: 1, count: 1), + recipient: Addr(repeating: 4, count: 4), + from: Addr(repeating: 2, count: 3), + origin: Addr(repeating: 2, count: 3), + message: Data(repeating: 7, count: 3) +) +// +//let data = withUnsafePointer(to: iphoneUUID!.uuid) { +// Data(bytes: $0, count: MemoryLayout.size(ofValue: iphoneUUID!.uuid)) +//} + + +if #available(OSX 10.12, *) { + let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) {_ in + UBBT.send(message: message, to: Addr(iphoneUUID)) + } +} else { + // Fallback on earlier versions +} + RunLoop.current.run() diff --git a/Sources/UB/Message.swift b/Sources/UB/Message.swift index fce812e..3c85ea8 100644 --- a/Sources/UB/Message.swift +++ b/Sources/UB/Message.swift @@ -17,6 +17,14 @@ public struct Message: Equatable { /// The raw message data. public let message: Data + + public init (proto: UBID, recipient: Addr, from: Addr, origin: Addr, message: Data) { + self.proto = proto + self.recipient = recipient + self.from = from + self.origin = origin + self.message = message + } } // @todo encoding and decoding diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 83b07a1..d202f0b 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -8,9 +8,23 @@ public class CoreBluetoothTransport: NSObject { private var testServiceID = CBUUID(string: "0xAAAA") private var testServiceID2 = CBUUID(string: "0xBBBB") - + + let receiveCharacteristic = CBMutableCharacteristic( + type: CBUUID(string: "0002"), + properties: CBCharacteristicProperties.writeWithoutResponse, + value: nil, + permissions: CBAttributePermissions.writeable + ) + + var test: CBCharacteristic? + private var perp: CBPeripheral? // make this an array for multiple devices - private var peripherals: [CBPeripheral?] = [] // make this an array for multiple devices + // private var peripherals = [Addr:CBPeripheral?]() // make this an array for multiple devices + + + + private var outQueue = [(Message,Addr)]() + public convenience override init() { self.init( @@ -29,12 +43,35 @@ public class CoreBluetoothTransport: NSObject { } extension CoreBluetoothTransport: Transport { + public var peers: [Peer] { + return []//centralManager.retrieveConnectedPeripherals(withServices: [testServiceID, testServiceID2]) + } + /// Send implements a function to send messages between nodes using Bluetooth /// /// - Parameters: /// - message: The message to send. - public func send(message _: Message) { - print("A") + public func send(message: Message, to: Addr) { + // check bluetooth is running + + guard let uuid = String(bytes: to, encoding: .utf8) else { + print("Error: not a valid Byte sequence") + return + } + guard let toUUID = UUID(uuidString: uuid) else { + print("Error: not a valid UUID sequence") + return + } + let peripherals = centralManager.retrievePeripherals(withIdentifiers: [toUUID]) + if peripherals.count == 0 { + print("Error: peripheral with uuid \(to) not found") + return + } + + let peripheral = peripherals[0] + print("NAME : \(peripheral)") + + peripheral.writeValue(message.message, for: test!, type: CBCharacteristicWriteType.withoutResponse) } /// Listen implements a function to receive messages being sent to a node. @@ -111,9 +148,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { rssi _: NSNumber) { perp = peripheral perp?.delegate = self - peripherals.append(perp) - print(peripherals.count) - decodePeripheralState(peripheralState: peripheral.state) + decodePeripheralState(peripheralState: peripheral.state, peripheral: peripheral) centralManager.connect(perp!) } @@ -126,12 +161,17 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { // Handle Disconnections public func centralManager(_: CBCentralManager, didDisconnectPeripheral _: CBPeripheral, error _: Error?) {} - func decodePeripheralState(peripheralState: CBPeripheralState) { + func decodePeripheralState(peripheralState: CBPeripheralState, peripheral: CBPeripheral) { switch peripheralState { case .disconnected: print("Peripheral state: disconnected") case .connected: print("Peripheral state: connected") + if #available(OSX 10.13, *) { + print("UUID: \(peripheral.identifier)") + } else { + // Fallback on earlier versions + } case .connecting: print("Peripheral state: connecting") case .disconnecting: @@ -156,13 +196,23 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { didDiscoverCharacteristicsFor service: CBService, error _: Error? ) { + for characteristic in service.characteristics! { - print("Characteristic: \(characteristic)") + if characteristic.uuid == CBUUID(string: "0002"){ + print("WE GOT THE RIGHT CHARACTERISTIC") + test = characteristic + } + // peripheral.readValue(for: characteristic) // if characteristic.uuid == testServiceID { - print("Sending some good shit") - let data = Data(bytes: [97, 98, 99, 100]) - peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) + //let data = Data(bytes: [97, 98, 99, 100]) + print("Characteristic: \(characteristic)") + +// print("Sending some good shit") +// let data = outQueue[0].0.message; +// peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) +// outQueue.remove(at:0) + // } } } From 7aa2eab188b2f168fe8d29bdd60a73c9c2efb02a Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 21:53:51 -0400 Subject: [PATCH 15/54] started cleaning up --- Pods/Manifest.lock | 17 + Pods/SwiftProtobuf/LICENSE.txt | 211 +++ Pods/SwiftProtobuf/README.md | 300 ++++ .../SwiftProtobuf/AnyMessageStorage.swift | 467 +++++ .../SwiftProtobuf/AnyUnpackError.swift | 37 + .../Sources/SwiftProtobuf/BinaryDecoder.swift | 1503 ++++++++++++++++ .../SwiftProtobuf/BinaryDecodingError.swift | 44 + .../SwiftProtobuf/BinaryDecodingOptions.swift | 39 + .../SwiftProtobuf/BinaryDelimited.swift | 227 +++ .../Sources/SwiftProtobuf/BinaryEncoder.swift | 135 ++ .../SwiftProtobuf/BinaryEncodingError.swift | 27 + .../BinaryEncodingSizeVisitor.swift | 369 ++++ .../SwiftProtobuf/BinaryEncodingVisitor.swift | 360 ++++ .../SwiftProtobuf/CustomJSONCodable.swift | 36 + .../SwiftProtobuf/Data+Extensions.swift | 33 + .../Sources/SwiftProtobuf/Decoder.swift | 150 ++ .../Sources/SwiftProtobuf/DoubleParser.swift | 68 + .../Sources/SwiftProtobuf/Enum.swift | 93 + .../SwiftProtobuf/ExtensibleMessage.swift | 39 + .../ExtensionFieldValueSet.swift | 89 + .../SwiftProtobuf/ExtensionFields.swift | 708 ++++++++ .../Sources/SwiftProtobuf/ExtensionMap.swift | 38 + .../Sources/SwiftProtobuf/FieldTag.swift | 69 + .../Sources/SwiftProtobuf/FieldTypes.swift | 412 +++++ .../Google_Protobuf_Any+Extensions.swift | 145 ++ .../Google_Protobuf_Any+Registry.swift | 135 ++ .../Google_Protobuf_Duration+Extensions.swift | 234 +++ ...Google_Protobuf_FieldMask+Extensions.swift | 163 ++ ...Google_Protobuf_ListValue+Extensions.swift | 80 + .../Google_Protobuf_Struct+Extensions.swift | 85 + ...Google_Protobuf_Timestamp+Extensions.swift | 337 ++++ .../Google_Protobuf_Value+Extensions.swift | 163 ++ .../Google_Protobuf_Wrappers+Extensions.swift | 283 +++ .../Sources/SwiftProtobuf/HashVisitor.swift | 408 +++++ .../Sources/SwiftProtobuf/Internal.swift | 51 + .../Sources/SwiftProtobuf/JSONDecoder.swift | 702 ++++++++ .../SwiftProtobuf/JSONDecodingError.swift | 62 + .../SwiftProtobuf/JSONDecodingOptions.swift | 29 + .../Sources/SwiftProtobuf/JSONEncoder.swift | 370 ++++ .../SwiftProtobuf/JSONEncodingError.swift | 35 + .../SwiftProtobuf/JSONEncodingOptions.swift | 26 + .../SwiftProtobuf/JSONEncodingVisitor.swift | 352 ++++ .../JSONMapEncodingVisitor.swift | 174 ++ .../Sources/SwiftProtobuf/JSONScanner.swift | 1512 +++++++++++++++++ .../Sources/SwiftProtobuf/MathUtils.swift | 40 + .../SwiftProtobuf/Message+AnyAdditions.swift | 45 + .../Message+BinaryAdditions.swift | 126 ++ .../SwiftProtobuf/Message+JSONAdditions.swift | 117 ++ .../Message+JSONArrayAdditions.swift | 111 ++ .../Message+TextFormatAdditions.swift | 89 + .../Sources/SwiftProtobuf/Message.swift | 216 +++ .../SwiftProtobuf/MessageExtension.swift | 41 + .../Sources/SwiftProtobuf/NameMap.swift | 286 ++++ .../SwiftProtobuf/ProtoNameProviding.swift | 23 + .../ProtobufAPIVersionCheck.swift | 43 + .../Sources/SwiftProtobuf/ProtobufMap.swift | 39 + .../SwiftProtobuf/SelectiveVisitor.swift | 268 +++ .../SwiftProtobuf/SimpleExtensionMap.swift | 112 ++ .../Sources/SwiftProtobuf/StringUtils.swift | 73 + .../SwiftProtobuf/TextFormatDecoder.swift | 713 ++++++++ .../TextFormatDecodingError.swift | 40 + .../SwiftProtobuf/TextFormatEncoder.swift | 292 ++++ .../TextFormatEncodingOptions.swift | 22 + .../TextFormatEncodingVisitor.swift | 553 ++++++ .../SwiftProtobuf/TextFormatScanner.swift | 1078 ++++++++++++ .../Sources/SwiftProtobuf/TimeUtils.swift | 53 + .../SwiftProtobuf/UnknownStorage.swift | 46 + .../Sources/SwiftProtobuf/Varint.swift | 108 ++ .../Sources/SwiftProtobuf/Version.swift | 28 + .../Sources/SwiftProtobuf/Visitor.swift | 693 ++++++++ .../Sources/SwiftProtobuf/WireFormat.swift | 70 + .../Sources/SwiftProtobuf/ZigZag.swift | 66 + .../Sources/SwiftProtobuf/any.pb.swift | 234 +++ .../Sources/SwiftProtobuf/api.pb.swift | 476 ++++++ .../Sources/SwiftProtobuf/duration.pb.swift | 169 ++ .../Sources/SwiftProtobuf/empty.pb.swift | 91 + .../Sources/SwiftProtobuf/field_mask.pb.swift | 294 ++++ .../SwiftProtobuf/source_context.pb.swift | 98 ++ .../Sources/SwiftProtobuf/struct.pb.swift | 417 +++++ .../Sources/SwiftProtobuf/timestamp.pb.swift | 189 +++ .../Sources/SwiftProtobuf/type.pb.swift | 924 ++++++++++ .../Sources/SwiftProtobuf/wrappers.pb.swift | 468 +++++ .../Pods-UB/Pods-UB-Info.plist | 26 + .../Pods-UB/Pods-UB-acknowledgements.markdown | 218 +++ .../Pods-UB/Pods-UB-acknowledgements.plist | 250 +++ .../Pods-UB/Pods-UB-dummy.m | 5 + .../Pods-UB/Pods-UB-umbrella.h | 16 + .../Pods-UB/Pods-UB.debug.xcconfig | 10 + .../Pods-UB/Pods-UB.modulemap | 6 + .../Pods-UB/Pods-UB.release.xcconfig | 10 + .../Pods-UBTests/Pods-UBTests-Info.plist | 26 + .../Pods-UBTests-acknowledgements.markdown | 218 +++ .../Pods-UBTests-acknowledgements.plist | 250 +++ .../Pods-UBTests/Pods-UBTests-dummy.m | 5 + .../Pods-UBTests/Pods-UBTests-frameworks.sh | 171 ++ .../Pods-UBTests/Pods-UBTests-umbrella.h | 16 + .../Pods-UBTests/Pods-UBTests.debug.xcconfig | 11 + .../Pods-UBTests/Pods-UBTests.modulemap | 6 + .../Pods-UBTests.release.xcconfig | 11 + .../SwiftProtobuf/SwiftProtobuf-Info.plist | 26 + .../SwiftProtobuf/SwiftProtobuf-dummy.m | 5 + .../SwiftProtobuf/SwiftProtobuf-prefix.pch | 12 + .../SwiftProtobuf/SwiftProtobuf-umbrella.h | 16 + .../SwiftProtobuf/SwiftProtobuf.modulemap | 6 + .../SwiftProtobuf/SwiftProtobuf.xcconfig | 10 + Sources/UB/Extensions/UUID+Bytes.swift | 13 + .../Transports/CoreBluetoothTransport.swift | 128 +- UB.xcworkspace/contents.xcworkspacedata | 10 + 108 files changed, 20972 insertions(+), 77 deletions(-) create mode 100644 Pods/Manifest.lock create mode 100644 Pods/SwiftProtobuf/LICENSE.txt create mode 100644 Pods/SwiftProtobuf/README.md create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncodingOptions.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift create mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.modulemap create mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m create mode 100755 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap create mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap create mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig create mode 100644 Sources/UB/Extensions/UUID+Bytes.swift create mode 100644 UB.xcworkspace/contents.xcworkspacedata diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock new file mode 100644 index 0000000..b704343 --- /dev/null +++ b/Pods/Manifest.lock @@ -0,0 +1,17 @@ +PODS: + - SwiftProtobuf (1.6.0) + +DEPENDENCIES: + - SwiftProtobuf + - SwiftProtobuf (~> 1.0) + +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - SwiftProtobuf + +SPEC CHECKSUMS: + SwiftProtobuf: e905ca1366405696411aaf174411c4b19c0ef73d + +PODFILE CHECKSUM: 8bab0dca2a6adb9d64e1fee38b77e3add1ceea2d + +COCOAPODS: 1.7.5 diff --git a/Pods/SwiftProtobuf/LICENSE.txt b/Pods/SwiftProtobuf/LICENSE.txt new file mode 100644 index 0000000..4b3ed03 --- /dev/null +++ b/Pods/SwiftProtobuf/LICENSE.txt @@ -0,0 +1,211 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +## Runtime Library Exception to the Apache 2.0 License: ## + + + As an exception, if you use this Software to compile your source code and + portions of this Software are embedded into the binary product as a result, + you may redistribute such product without providing attribution as would + otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. diff --git a/Pods/SwiftProtobuf/README.md b/Pods/SwiftProtobuf/README.md new file mode 100644 index 0000000..6dc45b0 --- /dev/null +++ b/Pods/SwiftProtobuf/README.md @@ -0,0 +1,300 @@ +Swift logo + +# Swift Protobuf + +**Welcome to Swift Protobuf!** + +[Apple's Swift programming language](https://swift.org/) is a perfect +complement to [Google's Protocol +Buffer](https://developers.google.com/protocol-buffers/) ("protobuf") serialization +technology. +They both emphasize high performance and programmer safety. + +This project provides both the command-line program that adds Swift +code generation to Google's `protoc` and the runtime library that is +necessary for using the generated code. +After using the protoc plugin to generate Swift code from your .proto +files, you will need to add this library to your project. + + +# Features of SwiftProtobuf + +SwiftProtobuf offers many advantages over alternative serialization +systems: + +* Safety: The protobuf code-generation system avoids the + errors that are common with hand-built serialization code. +* Correctness: SwiftProtobuf passes both its own extensive + test suite and Google's full conformance test for protobuf + correctness. +* Schema-driven: Defining your data structures in a separate + `.proto` schema file clearly documents your communications + conventions. +* Idiomatic: SwiftProtobuf takes full advantage of the Swift language. + In particular, all generated types provide full Swift copy-on-write + value semantics. +* Efficient binary serialization: The `.serializedData()` + method returns a `Data` with a compact binary form of your data. + You can deserialize the data using the `init(serializedData:)` + initializer. +* Standard JSON serialization: The `.jsonUTF8Data()` method returns a JSON + form of your data that can be parsed with the `init(jsonUTF8Data:)` + initializer. +* Hashable, Equatable: The generated struct can be put into a + `Set<>` or `Dictionary<>`. +* Performant: The binary and JSON serializers have been + extensively optimized. +* Extensible: You can add your own Swift extensions to any + of the generated types. + +Best of all, you can take the same `.proto` file and generate +Java, C++, Python, or Objective-C for use on other platforms. The +generated code for those languages will use the exact same +serialization and deserialization conventions as SwiftProtobuf, making +it easy to exchange serialized data in binary or JSON forms, with no +additional effort on your part. + +# Documentation + +More information is available in the associated documentation: + + * [Google's protobuf documentation](https://developers.google.com/protocol-buffers/) + provides general information about protocol buffers, the protoc compiler, + and how to use protocol buffers with C++, Java, and other languages. + * [PLUGIN.md](Documentation/PLUGIN.md) documents the `protoc-gen-swift` + plugin that adds Swift support to the `protoc` program + * [API.md](Documentation/API.md) documents how to use the generated code. + This is recommended reading for anyone using SwiftProtobuf in their + project. + * [cocoadocs.org](http://cocoadocs.org/docsets/SwiftProtobuf/) has the generated + API documentation + * [INTERNALS.md](Documentation/INTERNALS.md) documents the internal structure + of the generated code and the library. This + should only be needed by folks interested in working on SwiftProtobuf + itself. + * [STYLE_GUIDELINES.md](Documentation/STYLE_GUIDELINES.md) documents the style + guidelines we have adopted in our codebase if you are interested in + contributing + +# Getting Started + +If you've worked with Protocol Buffers before, adding Swift support is very +simple: you just need to build the `protoc-gen-swift` program and copy it into +your PATH. +The `protoc` program will find and use it automatically, allowing you +to build Swift sources for your proto files. +You will also, of course, need to add the SwiftProtobuf runtime library to +your project as explained below. + +## System Requirements + +To use Swift with Protocol buffers, you'll need: + +* A Swift 4.0 or later compiler (Xcode 9.1 or later). Support is included +for the Swift Package Manager; or using the included Xcode project. The Swift +protobuf project is being developed and tested against the latest release +version of Swift available from [Swift.org](https://swift.org) + +* Google's protoc compiler. The Swift protoc plugin is being actively +developed and tested against the latest protobuf sources. +The SwiftProtobuf tests need a version of protoc which supports the +`swift_prefix` option (introduced in protoc 3.2.0). +It may work with earlier versions of protoc. +You can get recent versions from +[Google's github repository](https://github.com/protocolbuffers/protobuf). + +## Building and Installing the Code Generator Plugin + +To translate `.proto` files into Swift, you will need both Google's +protoc compiler and the SwiftProtobuf code generator plugin. + +Building the plugin should be simple on any supported Swift platform: + +``` +$ git clone https://github.com/apple/swift-protobuf.git +$ cd swift-protobuf +``` + +Pick what released version of SwiftProtobuf you are going to use. You can get +a list of tags with: + +``` +$ git tag -l +``` + +Once you pick the version you will use, set your local state to match, and +build the protoc plugin: + +``` +$ git checkout tags/[tag_name] +$ swift build -c release +``` + +This will create a binary called `protoc-gen-swift` in the `.build/release` +directory. + +To install, just copy this one executable into a directory that is +part of your `PATH` environment variable. + +NOTE: The Swift runtime support is now included with macOS. If you are +using old Xcode versions or are on older system versions, you might need +to use also use `--static-swift-stdlib` with `swift build`. + +### Alternatively install via Homebrew + +If you prefer using [Homebrew](https://brew.sh): + +``` +$ brew install swift-protobuf +``` + +This will install `protoc` compiler and Swift code generator plugin. + +## Converting .proto files into Swift + +To generate Swift output for your .proto files, you run the `protoc` command as +usual, using the `--swift_out=` option: + +``` +$ protoc --swift_out=. my.proto +``` + +The `protoc` program will automatically look for `protoc-gen-swift` in your +`PATH` and use it. + +Each `.proto` input file will get translated to a corresponding `.pb.swift` +file in the output directory. + +More information about building and using `protoc-gen-swift` can be found +in the [detailed Plugin documentation](Documentation/PLUGIN.md). + +## Adding the SwiftProtobuf library to your project... + +To use the generated code, you need to include the `SwiftProtobuf` library +module in your project. How you do this will vary depending on how +you're building your project. Note that in all cases, we strongly recommend +that you use the version of the SwiftProtobuf library that corresponds to +the version of `protoc-gen-swift` you used to generate the code. + +### ...using `swift build` + +After copying the `.pb.swift` files into your project, you will need to add the +[SwiftProtobuf library](https://github.com/apple/swift-protobuf) to your +project to support the generated code. +If you are using the Swift Package Manager, add a dependency to your +`Package.swift` file and import the `SwiftProtobuf` library into the desired +targets. Adjust the `"1.6.0"` here to match the `[tag_name]` you used to build +the plugin above: + +```swift +dependencies: [ + .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"), +], +targets: [ + .target(name: "MyTarget", dependencies: ["SwiftProtobuf"]), +] +``` + +### ...using Xcode + +If you are using Xcode, then you should: + +* Add the `.pb.swift` source files generated from your protos directly to your + project +* Add the appropriate `SwiftProtobuf_` target from the Xcode project + in this package to your project. + +### ...using CocoaPods + +If you're using CocoaPods, add this to your `Podfile` adjusting the `:tag` to +match the `[tag_name]` you used to build the plugin above: + +```ruby +pod 'SwiftProtobuf', '~> 1.0' +``` + +And run `pod install`. + +NOTE: CocoaPods 1.7 or newer is required. + +### ...using Carthage + +If you're using Carthage, add this to your `Cartfile` but adjust the tag to match the `[tag_name]` you used to build the plugin above: + +```ruby +github "apple/swift-protobuf" ~> 1.0 +``` + +Run `carthage update` and drag `SwiftProtobuf.framework` into your Xcode.project. + +# Quick Start + +Once you have installed the code generator, used it to +generate Swift code from your `.proto` file, and +added the SwiftProtobuf library to your project, you can +just use the generated types as you would any other Swift +struct. + +For example, you might start with the following very simple +proto file: +```protobuf +syntax = "proto3"; + +message BookInfo { + int64 id = 1; + string title = 2; + string author = 3; +} +``` + +Then generate Swift code using: +``` +$ protoc --swift_out=. DataModel.proto +``` + +The generated code will expose a Swift property for +each of the proto fields as well as a selection +of serialization and deserialization capabilities: +```swift +// Create a BookInfo object and populate it: +var info = BookInfo() +info.id = 1734 +info.title = "Really Interesting Book" +info.author = "Jane Smith" + +// As above, but generating a read-only value: +let info2 = BookInfo.with { + $0.id = 1735 + $0.title = "Even More Interesting" + $0.author = "Jane Q. Smith" + } + +// Serialize to binary protobuf format: +let binaryData: Data = try info.serializedData() + +// Deserialize a received Data object from `binaryData` +let decodedInfo = try BookInfo(serializedData: binaryData) + +// Serialize to JSON format as a Data object +let jsonData: Data = try info.jsonUTF8Data() + +// Deserialize from JSON format from `jsonData` +let receivedFromJSON = try BookInfo(jsonUTF8Data: jsonData) +``` + +You can find more information in the detailed +[API Documentation](Documentation/API.md). + +## Report any issues + +If you run into problems, please send us a detailed report. +At a minimum, please include: + +* The specific operating system and version (for example, "macOS 10.12.1" or + "Ubuntu 16.10") +* The version of Swift you have installed (from `swift --version`) +* The version of the protoc compiler you are working with from + `protoc --version` +* The specific version of this source code (you can use `git log -1` to get the + latest commit ID) +* Any local changes you may have diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift new file mode 100644 index 0000000..3eb842a --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift @@ -0,0 +1,467 @@ +// Sources/SwiftProtobuf/AnyMessageStorage.swift - Custom stroage for Any WKT +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Hand written storage class for Google_Protobuf_Any to support on demand +/// transforms between the formats. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +#if !swift(>=4.2) +private let i_2166136261 = Int(bitPattern: 2166136261) +private let i_16777619 = Int(16777619) +#endif + +fileprivate func serializeAnyJSON( + for message: Message, + typeURL: String, + options: JSONEncodingOptions +) throws -> String { + var visitor = try JSONEncodingVisitor(message: message, options: options) + visitor.startObject() + visitor.encodeField(name: "@type", stringValue: typeURL) + if let m = message as? _CustomJSONCodable { + let value = try m.encodedJSONString(options: options) + visitor.encodeField(name: "value", jsonText: value) + } else { + try message.traverse(visitor: &visitor) + } + visitor.endObject() + return visitor.stringResult +} + +fileprivate func emitVerboseTextForm(visitor: inout TextFormatEncodingVisitor, message: Message, typeURL: String) { + let url: String + if typeURL.isEmpty { + url = buildTypeURL(forMessage: message, typePrefix: defaultAnyTypeURLPrefix) + } else { + url = typeURL + } + visitor.visitAnyVerbose(value: message, typeURL: url) +} + +fileprivate func asJSONObject(body: Data) -> Data { + let asciiOpenCurlyBracket = UInt8(ascii: "{") + let asciiCloseCurlyBracket = UInt8(ascii: "}") + var result = Data([asciiOpenCurlyBracket]) + result.append(body) + result.append(asciiCloseCurlyBracket) + return result +} + +fileprivate func unpack(contentJSON: Data, + options: JSONDecodingOptions, + as messageType: Message.Type) throws -> Message { + guard messageType is _CustomJSONCodable.Type else { + let contentJSONAsObject = asJSONObject(body: contentJSON) + return try messageType.init(jsonUTF8Data: contentJSONAsObject, options: options) + } + + var value = String() + try contentJSON.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var scanner = JSONScanner(source: buffer, + messageDepthLimit: options.messageDepthLimit, + ignoreUnknownFields: options.ignoreUnknownFields) + let key = try scanner.nextQuotedString() + if key != "value" { + // The only thing within a WKT should be "value". + throw AnyUnpackError.malformedWellKnownTypeJSON + } + try scanner.skipRequiredColon() // Can't fail + value = try scanner.skip() + if !scanner.complete { + // If that wasn't the end, then there was another key, + // and WKTs should only have the one. + throw AnyUnpackError.malformedWellKnownTypeJSON + } + } + } + return try messageType.init(jsonString: value, options: options) +} + +internal class AnyMessageStorage { + // The two properties generated Google_Protobuf_Any will reference. + var _typeURL = String() + var _value: Data { + // Remapped to the internal `state`. + get { + switch state { + case .binary(let value): + return value + case .message(let message): + do { + return try message.serializedData(partial: true) + } catch { + return Internal.emptyData + } + case .contentJSON(let contentJSON, let options): + guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) else { + return Internal.emptyData + } + do { + let m = try unpack(contentJSON: contentJSON, + options: options, + as: messageType) + return try m.serializedData(partial: true) + } catch { + return Internal.emptyData + } + } + } + set { + state = .binary(newValue) + } + } + + enum InternalState { + // a serialized binary + // Note: Unlike contentJSON below, binary does not bother to capture the + // decoding options. This is because the actual binary format is the binary + // blob, i.e. - when decoding from binary, the spec doesn't include decoding + // the binary blob, it is pass through. Instead there is a public api for + // unpacking that takes new options when a developer decides to decode it. + case binary(Data) + // a message + case message(Message) + // parsed JSON with the @type removed and the decoding options. + case contentJSON(Data, JSONDecodingOptions) + } + var state: InternalState = .binary(Internal.emptyData) + + static let defaultInstance = AnyMessageStorage() + + private init() {} + + init(copying source: AnyMessageStorage) { + _typeURL = source._typeURL + state = source.state + } + + func isA(_ type: M.Type) -> Bool { + if _typeURL.isEmpty { + return false + } + let encodedType = typeName(fromURL: _typeURL) + return encodedType == M.protoMessageName + } + + // This is only ever called with the expactation that target will be fully + // replaced during the unpacking and never as a merge. + func unpackTo( + target: inout M, + extensions: ExtensionMap?, + options: BinaryDecodingOptions + ) throws { + guard isA(M.self) else { + throw AnyUnpackError.typeMismatch + } + + switch state { + case .binary(let data): + target = try M(serializedData: data, extensions: extensions, partial: true, options: options) + + case .message(let msg): + if let message = msg as? M { + // Already right type, copy it over. + target = message + } else { + // Different type, serialize and parse. + let data = try msg.serializedData(partial: true) + target = try M(serializedData: data, extensions: extensions, partial: true) + } + + case .contentJSON(let contentJSON, let options): + target = try unpack(contentJSON: contentJSON, + options: options, + as: M.self) as! M + } + } + + // Called before the message is traversed to do any error preflights. + // Since traverse() will use _value, this is our chance to throw + // when _value can't. + func preTraverse() throws { + switch state { + case .binary: + // Nothing to be checked. + break + + case .message: + // When set from a developer provided message, partial support + // is done. Any message that comes in from another format isn't + // checked, and transcoding the isInitialized requirement is + // never inserted. + break + + case .contentJSON: + // contentJSON requires a good URL and our ability to look up + // the message type to transcode. + if Google_Protobuf_Any.messageType(forTypeURL: _typeURL) == nil { + // Isn't registered, we can't transform it for binary. + throw BinaryEncodingError.anyTranscodeFailure + } + } + } +} + +/// Custom handling for Text format. +extension AnyMessageStorage { + func decodeTextFormat(typeURL url: String, decoder: inout TextFormatDecoder) throws { + // Decoding the verbose form requires knowing the type. + _typeURL = url + guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: url) else { + // The type wasn't registered, can't parse it. + throw TextFormatDecodingError.malformedText + } + let terminator = try decoder.scanner.skipObjectStart() + var subDecoder = try TextFormatDecoder(messageType: messageType, scanner: decoder.scanner, terminator: terminator) + if messageType == Google_Protobuf_Any.self { + var any = Google_Protobuf_Any() + try any.decodeTextFormat(decoder: &subDecoder) + state = .message(any) + } else { + var m = messageType.init() + try m.decodeMessage(decoder: &subDecoder) + state = .message(m) + } + decoder.scanner = subDecoder.scanner + if try decoder.nextFieldNumber() != nil { + // Verbose any can never have additional keys. + throw TextFormatDecodingError.malformedText + } + } + + // Specialized traverse for writing out a Text form of the Any. + // This prefers the more-legible "verbose" format if it can + // use it, otherwise will fall back to simpler forms. + internal func textTraverse(visitor: inout TextFormatEncodingVisitor) { + switch state { + case .binary(let valueData): + if let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) { + // If we can decode it, we can write the readable verbose form: + do { + let m = try messageType.init(serializedData: valueData, partial: true) + emitVerboseTextForm(visitor: &visitor, message: m, typeURL: _typeURL) + return + } catch { + // Fall through to just print the type and raw binary data + } + } + if !_typeURL.isEmpty { + try! visitor.visitSingularStringField(value: _typeURL, fieldNumber: 1) + } + if !valueData.isEmpty { + try! visitor.visitSingularBytesField(value: valueData, fieldNumber: 2) + } + + case .message(let msg): + emitVerboseTextForm(visitor: &visitor, message: msg, typeURL: _typeURL) + + case .contentJSON(let contentJSON, let options): + // If we can decode it, we can write the readable verbose form: + if let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) { + do { + let m = try unpack(contentJSON: contentJSON, + options: options, + as: messageType) + emitVerboseTextForm(visitor: &visitor, message: m, typeURL: _typeURL) + return + } catch { + // Fall through to just print the raw JSON data + } + } + if !_typeURL.isEmpty { + try! visitor.visitSingularStringField(value: _typeURL, fieldNumber: 1) + } + // Build a readable form of the JSON: + let contentJSONAsObject = asJSONObject(body: contentJSON) + visitor.visitAnyJSONDataField(value: contentJSONAsObject) + } + } +} + +/// The obvious goal for Hashable/Equatable conformance would be for +/// hash and equality to behave as if we always decoded the inner +/// object and hashed or compared that. Unfortunately, Any typically +/// stores serialized contents and we don't always have the ability to +/// deserialize it. Since none of our supported serializations are +/// fully deterministic, we can't even ensure that equality will +/// behave this way when the Any contents are in the same +/// serialization. +/// +/// As a result, we can only really perform a "best effort" equality +/// test. Of course, regardless of the above, we must guarantee that +/// hashValue is compatible with equality. +extension AnyMessageStorage { +#if swift(>=4.2) + // Can't use _valueData for a few reasons: + // 1. Since decode is done on demand, two objects could be equal + // but created differently (one from JSON, one for Message, etc.), + // and the hash values have to be equal even if we don't have data + // yet. + // 2. map<> serialization order is undefined. At the time of writing + // the Swift, Objective-C, and Go runtimes all tend to have random + // orders, so the messages could be identical, but in binary form + // they could differ. + public func hash(into hasher: inout Hasher) { + if !_typeURL.isEmpty { + hasher.combine(_typeURL) + } + } +#else // swift(>=4.2) + var hashValue: Int { + var hash: Int = i_2166136261 + if !_typeURL.isEmpty { + hash = (hash &* i_16777619) ^ _typeURL.hashValue + } + return hash + } +#endif // swift(>=4.2) + + func isEqualTo(other: AnyMessageStorage) -> Bool { + if (_typeURL != other._typeURL) { + return false + } + + // Since the library does lazy Any decode, equality is a very hard problem. + // It things exactly match, that's pretty easy, otherwise, one ends up having + // to error on saying they aren't equal. + // + // The best option would be to have Message forms and compare those, as that + // removes issues like map<> serialization order, some other protocol buffer + // implementation details/bugs around serialized form order, etc.; but that + // would also greatly slow down equality tests. + // + // Do our best to compare what is present have... + + // If both have messages, check if they are the same. + if case .message(let myMsg) = state, case .message(let otherMsg) = other.state, type(of: myMsg) == type(of: otherMsg) { + // Since the messages are known to be same type, we can claim both equal and + // not equal based on the equality comparison. + return myMsg.isEqualTo(message: otherMsg) + } + + // If both have serialized data, and they exactly match; the messages are equal. + // Because there could be map in the message, the fact that the data isn't the + // same doesn't always mean the messages aren't equal. Likewise, the binary could + // have been created by a library that doesn't order the fields, or the binary was + // created using the appending ability in of the binary format. + if case .binary(let myValue) = state, case .binary(let otherValue) = other.state, myValue == otherValue { + return true + } + + // If both have contentJSON, and they exactly match; the messages are equal. + // Because there could be map in the message (or the JSON could just be in a different + // order), the fact that the JSON isn't the same doesn't always mean the messages + // aren't equal. + if case .contentJSON(let myJSON, _) = state, + case .contentJSON(let otherJSON, _) = other.state, + myJSON == otherJSON { + return true + } + + // Out of options. To do more compares, the states conversions would have to be + // done to do comparisions; and since equality can be used somewhat removed from + // a developer (if they put protos in a Set, use them as keys to a Dictionary, etc), + // the conversion cost might be to high for those uses. Give up and say they aren't equal. + return false + } +} + +// _CustomJSONCodable support for Google_Protobuf_Any +extension AnyMessageStorage { + // Override the traversal-based JSON encoding + // This builds an Any JSON representation from one of: + // * The message we were initialized with, + // * The JSON fields we last deserialized, or + // * The protobuf field we were deserialized from. + // The last case requires locating the type, deserializing + // into an object, then reserializing back to JSON. + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + switch state { + case .binary(let valueData): + // Transcode by decoding the binary data to a message object + // and then recode back into JSON. + guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) else { + // If we don't have the type available, we can't decode the + // binary value, so we're stuck. (The Google spec does not + // provide a way to just package the binary value for someone + // else to decode later.) + throw JSONEncodingError.anyTranscodeFailure + } + let m = try messageType.init(serializedData: valueData, partial: true) + return try serializeAnyJSON(for: m, typeURL: _typeURL, options: options) + + case .message(let msg): + // We should have been initialized with a typeURL, but + // ensure it wasn't cleared. + let url = !_typeURL.isEmpty ? _typeURL : buildTypeURL(forMessage: msg, typePrefix: defaultAnyTypeURLPrefix) + return try serializeAnyJSON(for: msg, typeURL: url, options: options) + + case .contentJSON(let contentJSON, _): + var jsonEncoder = JSONEncoder() + jsonEncoder.startObject() + jsonEncoder.startField(name: "@type") + jsonEncoder.putStringValue(value: _typeURL) + if !contentJSON.isEmpty { + jsonEncoder.append(staticText: ",") + // NOTE: This doesn't really take `options` into account since it is + // just reflecting out what was taken in originally. + jsonEncoder.append(utf8Data: contentJSON) + } + jsonEncoder.endObject() + return jsonEncoder.stringResult + } + } + + // TODO: If the type is well-known or has already been registered, + // we should consider decoding eagerly. Eager decoding would + // catch certain errors earlier (good) but would probably be + // a performance hit if the Any contents were never accessed (bad). + // Of course, we can't always decode eagerly (we don't always have the + // message type available), so the deferred logic here is still needed. + func decodeJSON(from decoder: inout JSONDecoder) throws { + try decoder.scanner.skipRequiredObjectStart() + // Reset state + _typeURL = String() + state = .binary(Internal.emptyData) + if decoder.scanner.skipOptionalObjectEnd() { + return + } + + var jsonEncoder = JSONEncoder() + while true { + let key = try decoder.scanner.nextQuotedString() + try decoder.scanner.skipRequiredColon() + if key == "@type" { + _typeURL = try decoder.scanner.nextQuotedString() + } else { + jsonEncoder.startField(name: key) + let keyValueJSON = try decoder.scanner.skip() + jsonEncoder.append(text: keyValueJSON) + } + if decoder.scanner.skipOptionalObjectEnd() { + // Capture the options, but set the messageDepthLimit to be what + // was left right now, as that is the limit when the JSON is finally + // parsed. + var updatedOptions = decoder.options + updatedOptions.messageDepthLimit = decoder.scanner.recursionBudget + state = .contentJSON(jsonEncoder.dataResult, updatedOptions) + return + } + try decoder.scanner.skipRequiredComma() + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift new file mode 100644 index 0000000..29fb0d0 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift @@ -0,0 +1,37 @@ +// Sources/SwiftProtobuf/AnyUnpackError.swift - Any Unpacking Errors +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Errors that can be throw when unpacking a Google_Protobuf_Any. +/// +// ----------------------------------------------------------------------------- + +/// Describes errors that can occur when unpacking an `Google_Protobuf_Any` +/// message. +/// +/// `Google_Protobuf_Any` messages can be decoded from protobuf binary, text +/// format, or JSON. The contents are not parsed immediately; the raw data is +/// held in the `Google_Protobuf_Any` message until you `unpack()` it into a +/// message. At this time, any error can occur that might have occurred from a +/// regular decoding operation. There are also other errors that can occur due +/// to problems with the `Any` value's structure. +public enum AnyUnpackError: Error { + /// The `type_url` field in the `Google_Protobuf_Any` message did not match + /// the message type provided to the `unpack()` method. + case typeMismatch + + /// Well-known types being decoded from JSON must have only two fields: the + /// `@type` field and a `value` field containing the specialized JSON coding + /// of the well-known type. + case malformedWellKnownTypeJSON + + /// The `Google_Protobuf_Any` message was malformed in some other way not + /// covered by the other error cases. + case malformedAnyField +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift new file mode 100644 index 0000000..53144d0 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift @@ -0,0 +1,1503 @@ +// Sources/SwiftProtobuf/BinaryDecoder.swift - Binary decoding +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Protobuf binary format decoding engine. +/// +/// This provides the Decoder interface that interacts directly +/// with the generated code. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +internal struct BinaryDecoder: Decoder { + // Current position + private var p : UnsafePointer + // Remaining bytes in input. + private var available : Int + // Position of start of field currently being parsed + private var fieldStartP : UnsafePointer + // Position of end of field currently being parsed, nil if we don't know. + private var fieldEndP : UnsafePointer? + // Whether or not the field value has actually been parsed + private var consumed = true + // Wire format for last-examined field + internal var fieldWireFormat = WireFormat.varint + // Field number for last-parsed field tag + private var fieldNumber: Int = 0 + // Collection of extension fields for this decode + private var extensions: ExtensionMap? + // The current group number. See decodeFullGroup(group:fieldNumber:) for how + // this is used. + private var groupFieldNumber: Int? + // The options for decoding. + private var options: BinaryDecodingOptions + + private var recursionBudget: Int + + // Collects the unknown data found while decoding a message. + private var unknownData: Data? + // Custom data to use as the unknown data while parsing a field. Used only by + // packed repeated enums; see below + private var unknownOverride: Data? + + private var complete: Bool {return available == 0} + + internal init( + forReadingFrom pointer: UnsafePointer, + count: Int, + options: BinaryDecodingOptions, + extensions: ExtensionMap? = nil + ) { + // Assuming baseAddress is not nil. + p = pointer + available = count + fieldStartP = p + self.extensions = extensions + self.options = options + recursionBudget = options.messageDepthLimit + } + + internal init( + forReadingFrom pointer: UnsafePointer, + count: Int, + parent: BinaryDecoder + ) { + self.init(forReadingFrom: pointer, + count: count, + options: parent.options, + extensions: parent.extensions) + recursionBudget = parent.recursionBudget + } + + private mutating func incrementRecursionDepth() throws { + recursionBudget -= 1 + if recursionBudget < 0 { + throw BinaryDecodingError.messageDepthLimit + } + } + + private mutating func decrementRecursionDepth() { + recursionBudget += 1 + // This should never happen, if it does, something is probably corrupting memory, and + // simply throwing doesn't make much sense. + if recursionBudget > options.messageDepthLimit { + fatalError("Somehow BinaryDecoding unwound more objects than it started") + } + } + + internal mutating func handleConflictingOneOf() throws { + /// Protobuf simply allows conflicting oneof values to overwrite + } + + /// Return the next field number or nil if there are no more fields. + internal mutating func nextFieldNumber() throws -> Int? { + // Since this is called for every field, I've taken some pains + // to optimize it, including unrolling a tweaked version of + // the varint parser. + if fieldNumber > 0 { + if let override = unknownOverride { + assert(!options.discardUnknownFields) + assert(fieldWireFormat != .startGroup && fieldWireFormat != .endGroup) + if unknownData == nil { + unknownData = override + } else { + unknownData!.append(override) + } + unknownOverride = nil + } else if !consumed { + if options.discardUnknownFields { + try skip() + } else { + let u = try getRawField() + if unknownData == nil { + unknownData = u + } else { + unknownData!.append(u) + } + } + } + } + + // Quit if end of input + if available == 0 { + return nil + } + + // Get the next field number + fieldStartP = p + fieldEndP = nil + let start = p + let c0 = start[0] + if let wireFormat = WireFormat(rawValue: c0 & 7) { + fieldWireFormat = wireFormat + } else { + throw BinaryDecodingError.malformedProtobuf + } + if (c0 & 0x80) == 0 { + p += 1 + available -= 1 + fieldNumber = Int(c0) >> 3 + } else { + fieldNumber = Int(c0 & 0x7f) >> 3 + if available < 2 { + throw BinaryDecodingError.malformedProtobuf + } + let c1 = start[1] + if (c1 & 0x80) == 0 { + p += 2 + available -= 2 + fieldNumber |= Int(c1) << 4 + } else { + fieldNumber |= Int(c1 & 0x7f) << 4 + if available < 3 { + throw BinaryDecodingError.malformedProtobuf + } + let c2 = start[2] + fieldNumber |= Int(c2 & 0x7f) << 11 + if (c2 & 0x80) == 0 { + p += 3 + available -= 3 + } else { + if available < 4 { + throw BinaryDecodingError.malformedProtobuf + } + let c3 = start[3] + fieldNumber |= Int(c3 & 0x7f) << 18 + if (c3 & 0x80) == 0 { + p += 4 + available -= 4 + } else { + if available < 5 { + throw BinaryDecodingError.malformedProtobuf + } + let c4 = start[4] + if c4 > 15 { + throw BinaryDecodingError.malformedProtobuf + } + fieldNumber |= Int(c4 & 0x7f) << 25 + p += 5 + available -= 5 + } + } + } + } + if fieldNumber != 0 { + consumed = false + + if fieldWireFormat == .endGroup { + if groupFieldNumber == fieldNumber { + // Reached the end of the current group, single the + // end of the message. + return nil + } else { + // .endGroup when not in a group or for a different + // group is an invalid binary. + throw BinaryDecodingError.malformedProtobuf + } + } + return fieldNumber + } + throw BinaryDecodingError.malformedProtobuf + } + + internal mutating func decodeSingularFloatField(value: inout Float) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + try decodeFourByteNumber(value: &value) + consumed = true + } + + internal mutating func decodeSingularFloatField(value: inout Float?) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + value = try decodeFloat() + consumed = true + } + + internal mutating func decodeRepeatedFloatField(value: inout [Float]) throws { + switch fieldWireFormat { + case WireFormat.fixed32: + let i = try decodeFloat() + value.append(i) + consumed = true + case WireFormat.lengthDelimited: + let bodyBytes = try decodeVarint() + if bodyBytes > 0 { + let itemSize = UInt64(MemoryLayout.size) + let itemCount = bodyBytes / itemSize + if bodyBytes % itemSize != 0 || itemCount > UInt64(Int.max) { + throw BinaryDecodingError.truncated + } + value.reserveCapacity(value.count + Int(truncatingIfNeeded: itemCount)) + for _ in 1...itemCount { + value.append(try decodeFloat()) + } + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularDoubleField(value: inout Double) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + value = try decodeDouble() + consumed = true + } + + internal mutating func decodeSingularDoubleField(value: inout Double?) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + value = try decodeDouble() + consumed = true + } + + internal mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { + switch fieldWireFormat { + case WireFormat.fixed64: + let i = try decodeDouble() + value.append(i) + consumed = true + case WireFormat.lengthDelimited: + let bodyBytes = try decodeVarint() + if bodyBytes > 0 { + let itemSize = UInt64(MemoryLayout.size) + let itemCount = bodyBytes / itemSize + if bodyBytes % itemSize != 0 || itemCount > UInt64(Int.max) { + throw BinaryDecodingError.truncated + } + value.reserveCapacity(value.count + Int(truncatingIfNeeded: itemCount)) + for _ in 1...itemCount { + let i = try decodeDouble() + value.append(i) + } + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularInt32Field(value: inout Int32) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = Int32(truncatingIfNeeded: varint) + consumed = true + } + + internal mutating func decodeSingularInt32Field(value: inout Int32?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = Int32(truncatingIfNeeded: varint) + consumed = true + } + + internal mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(Int32(truncatingIfNeeded: varint)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let varint = try decoder.decodeVarint() + value.append(Int32(truncatingIfNeeded: varint)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularInt64Field(value: inout Int64) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let v = try decodeVarint() + value = Int64(bitPattern: v) + consumed = true + } + + internal mutating func decodeSingularInt64Field(value: inout Int64?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = Int64(bitPattern: varint) + consumed = true + } + + internal mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(Int64(bitPattern: varint)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let varint = try decoder.decodeVarint() + value.append(Int64(bitPattern: varint)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularUInt32Field(value: inout UInt32) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = UInt32(truncatingIfNeeded: varint) + consumed = true + } + + internal mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = UInt32(truncatingIfNeeded: varint) + consumed = true + } + + internal mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(UInt32(truncatingIfNeeded: varint)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let t = try decoder.decodeVarint() + value.append(UInt32(truncatingIfNeeded: t)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularUInt64Field(value: inout UInt64) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + value = try decodeVarint() + consumed = true + } + + internal mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + value = try decodeVarint() + consumed = true + } + + internal mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(varint) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let t = try decoder.decodeVarint() + value.append(t) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularSInt32Field(value: inout Int32) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + let t = UInt32(truncatingIfNeeded: varint) + value = ZigZag.decoded(t) + consumed = true + } + + internal mutating func decodeSingularSInt32Field(value: inout Int32?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + let t = UInt32(truncatingIfNeeded: varint) + value = ZigZag.decoded(t) + consumed = true + } + + internal mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + let t = UInt32(truncatingIfNeeded: varint) + value.append(ZigZag.decoded(t)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let varint = try decoder.decodeVarint() + let t = UInt32(truncatingIfNeeded: varint) + value.append(ZigZag.decoded(t)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularSInt64Field(value: inout Int64) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = ZigZag.decoded(varint) + consumed = true + } + + internal mutating func decodeSingularSInt64Field(value: inout Int64?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + value = ZigZag.decoded(varint) + consumed = true + } + + internal mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(ZigZag.decoded(varint)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let varint = try decoder.decodeVarint() + value.append(ZigZag.decoded(varint)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularFixed32Field(value: inout UInt32) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + var i: UInt32 = 0 + try decodeFourByteNumber(value: &i) + value = UInt32(littleEndian: i) + consumed = true + } + + internal mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + var i: UInt32 = 0 + try decodeFourByteNumber(value: &i) + value = UInt32(littleEndian: i) + consumed = true + } + + internal mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { + switch fieldWireFormat { + case WireFormat.fixed32: + var i: UInt32 = 0 + try decodeFourByteNumber(value: &i) + value.append(UInt32(littleEndian: i)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value.reserveCapacity(value.count + n / MemoryLayout.size) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + var i: UInt32 = 0 + while !decoder.complete { + try decoder.decodeFourByteNumber(value: &i) + value.append(UInt32(littleEndian: i)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularFixed64Field(value: inout UInt64) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + var i: UInt64 = 0 + try decodeEightByteNumber(value: &i) + value = UInt64(littleEndian: i) + consumed = true + } + + internal mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + var i: UInt64 = 0 + try decodeEightByteNumber(value: &i) + value = UInt64(littleEndian: i) + consumed = true + } + + internal mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { + switch fieldWireFormat { + case WireFormat.fixed64: + var i: UInt64 = 0 + try decodeEightByteNumber(value: &i) + value.append(UInt64(littleEndian: i)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value.reserveCapacity(value.count + n / MemoryLayout.size) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + var i: UInt64 = 0 + while !decoder.complete { + try decoder.decodeEightByteNumber(value: &i) + value.append(UInt64(littleEndian: i)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularSFixed32Field(value: inout Int32) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + var i: Int32 = 0 + try decodeFourByteNumber(value: &i) + value = Int32(littleEndian: i) + consumed = true + } + + internal mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { + guard fieldWireFormat == WireFormat.fixed32 else { + return + } + var i: Int32 = 0 + try decodeFourByteNumber(value: &i) + value = Int32(littleEndian: i) + consumed = true + } + + internal mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { + switch fieldWireFormat { + case WireFormat.fixed32: + var i: Int32 = 0 + try decodeFourByteNumber(value: &i) + value.append(Int32(littleEndian: i)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value.reserveCapacity(value.count + n / MemoryLayout.size) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + var i: Int32 = 0 + while !decoder.complete { + try decoder.decodeFourByteNumber(value: &i) + value.append(Int32(littleEndian: i)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularSFixed64Field(value: inout Int64) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + var i: Int64 = 0 + try decodeEightByteNumber(value: &i) + value = Int64(littleEndian: i) + consumed = true + } + + internal mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { + guard fieldWireFormat == WireFormat.fixed64 else { + return + } + var i: Int64 = 0 + try decodeEightByteNumber(value: &i) + value = Int64(littleEndian: i) + consumed = true + } + + internal mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { + switch fieldWireFormat { + case WireFormat.fixed64: + var i: Int64 = 0 + try decodeEightByteNumber(value: &i) + value.append(Int64(littleEndian: i)) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value.reserveCapacity(value.count + n / MemoryLayout.size) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + var i: Int64 = 0 + while !decoder.complete { + try decoder.decodeEightByteNumber(value: &i) + value.append(Int64(littleEndian: i)) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularBoolField(value: inout Bool) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + value = try decodeVarint() != 0 + consumed = true + } + + internal mutating func decodeSingularBoolField(value: inout Bool?) throws { + guard fieldWireFormat == WireFormat.varint else { + return + } + value = try decodeVarint() != 0 + consumed = true + } + + internal mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + value.append(varint != 0) + consumed = true + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !decoder.complete { + let t = try decoder.decodeVarint() + value.append(t != 0) + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularStringField(value: inout String) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + if let s = utf8ToString(bytes: p, count: n) { + value = s + consumed = true + } else { + throw BinaryDecodingError.invalidUTF8 + } + } + + internal mutating func decodeSingularStringField(value: inout String?) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + if let s = utf8ToString(bytes: p, count: n) { + value = s + consumed = true + } else { + throw BinaryDecodingError.invalidUTF8 + } + } + + internal mutating func decodeRepeatedStringField(value: inout [String]) throws { + switch fieldWireFormat { + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + if let s = utf8ToString(bytes: p, count: n) { + value.append(s) + consumed = true + } else { + throw BinaryDecodingError.invalidUTF8 + } + default: + return + } + } + + internal mutating func decodeSingularBytesField(value: inout Data) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value = Data(bytes: p, count: n) + consumed = true + } + + internal mutating func decodeSingularBytesField(value: inout Data?) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value = Data(bytes: p, count: n) + consumed = true + } + + internal mutating func decodeRepeatedBytesField(value: inout [Data]) throws { + switch fieldWireFormat { + case WireFormat.lengthDelimited: + var n: Int = 0 + let p = try getFieldBodyBytes(count: &n) + value.append(Data(bytes: p, count: n)) + consumed = true + default: + return + } + } + + internal mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { + value = v + consumed = true + } + } + + internal mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int { + guard fieldWireFormat == WireFormat.varint else { + return + } + let varint = try decodeVarint() + if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { + value = v + consumed = true + } + } + + internal mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int { + switch fieldWireFormat { + case WireFormat.varint: + let varint = try decodeVarint() + if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { + value.append(v) + consumed = true + } + case WireFormat.lengthDelimited: + var n: Int = 0 + var extras: [Int32]? + let p = try getFieldBodyBytes(count: &n) + let ints = Varint.countVarintsInBuffer(start: p, count: n) + value.reserveCapacity(value.count + ints) + var subdecoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) + while !subdecoder.complete { + let u64 = try subdecoder.decodeVarint() + let i32 = Int32(truncatingIfNeeded: u64) + if let v = E(rawValue: Int(i32)) { + value.append(v) + } else if !options.discardUnknownFields { + if extras == nil { + extras = [] + } + extras!.append(i32) + } + } + if let extras = extras { + let fieldTag = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var bodySize = 0 + for v in extras { + bodySize += Varint.encodedSize(of: Int64(v)) + } + let fieldSize = Varint.encodedSize(of: fieldTag.rawValue) + Varint.encodedSize(of: Int64(bodySize)) + bodySize + var field = Data(count: fieldSize) + field.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + var encoder = BinaryEncoder(forWritingInto: pointer) + encoder.startField(tag: fieldTag) + encoder.putVarInt(value: Int64(bodySize)) + for v in extras { + encoder.putVarInt(value: Int64(v)) + } + } + } + unknownOverride = field + } + consumed = true + default: + return + } + } + + internal mutating func decodeSingularMessageField(value: inout M?) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var count: Int = 0 + let p = try getFieldBodyBytes(count: &count) + if value == nil { + value = M() + } + var subDecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) + try subDecoder.decodeFullMessage(message: &value!) + consumed = true + } + + internal mutating func decodeRepeatedMessageField(value: inout [M]) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var count: Int = 0 + let p = try getFieldBodyBytes(count: &count) + var newValue = M() + var subDecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) + try subDecoder.decodeFullMessage(message: &newValue) + value.append(newValue) + consumed = true + } + + internal mutating func decodeFullMessage(message: inout M) throws { + try incrementRecursionDepth() + try message.decodeMessage(decoder: &self) + decrementRecursionDepth() + guard complete else { + throw BinaryDecodingError.trailingGarbage + } + if let unknownData = unknownData { + message.unknownFields.append(protobufData: unknownData) + } + } + + internal mutating func decodeSingularGroupField(value: inout G?) throws { + var group = value ?? G() + if try decodeFullGroup(group: &group, fieldNumber: fieldNumber) { + value = group + consumed = true + } + } + + internal mutating func decodeRepeatedGroupField(value: inout [G]) throws { + var group = G() + if try decodeFullGroup(group: &group, fieldNumber: fieldNumber) { + value.append(group) + consumed = true + } + } + + private mutating func decodeFullGroup(group: inout G, fieldNumber: Int) throws -> Bool { + guard fieldWireFormat == WireFormat.startGroup else { + return false + } + assert(unknownData == nil) + + try incrementRecursionDepth() + + // This works by making a clone of the current decoder state and + // setting `groupFieldNumber` to signal `nextFieldNumber()` to watch + // for that as a marker for having reached the end of a group/message. + // Groups within groups works because this effectively makes a stack + // of decoders, each one looking for their ending tag. + + var subDecoder = self + subDecoder.groupFieldNumber = fieldNumber + // startGroup was read, so current tag/data is done (otherwise the + // startTag will end up in the unknowns of the first thing decoded). + subDecoder.consumed = true + try group.decodeMessage(decoder: &subDecoder) + guard subDecoder.fieldNumber == fieldNumber && subDecoder.fieldWireFormat == .endGroup else { + throw BinaryDecodingError.truncated + } + if let groupUnknowns = subDecoder.unknownData { + group.unknownFields.append(protobufData: groupUnknowns) + } + // Advance over what was parsed. + consume(length: available - subDecoder.available) + assert(recursionBudget == subDecoder.recursionBudget) + decrementRecursionDepth() + return true + } + + internal mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var k: KeyType.BaseType? + var v: ValueType.BaseType? + var count: Int = 0 + let p = try getFieldBodyBytes(count: &count) + var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) + while let tag = try subdecoder.getTag() { + if tag.wireFormat == .endGroup { + throw BinaryDecodingError.malformedProtobuf + } + let fieldNumber = tag.fieldNumber + switch fieldNumber { + case 1: + try KeyType.decodeSingular(value: &k, from: &subdecoder) + case 2: + try ValueType.decodeSingular(value: &v, from: &subdecoder) + default: // Skip any other fields within the map entry object + try subdecoder.skip() + } + } + if !subdecoder.complete { + throw BinaryDecodingError.trailingGarbage + } + // A map<> definition can't provide a default value for the keys/values, + // so it is safe to use the proto3 default to get the right + // integer/string/bytes. The one catch is a proto2 enum (which can be the + // value) can have a non zero value, but that case is the next + // custom decodeMapField<>() method and handles it. + value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType.proto3DefaultValue + consumed = true + } + + internal mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var k: KeyType.BaseType? + var v: ValueType? + var count: Int = 0 + let p = try getFieldBodyBytes(count: &count) + var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) + while let tag = try subdecoder.getTag() { + if tag.wireFormat == .endGroup { + throw BinaryDecodingError.malformedProtobuf + } + let fieldNumber = tag.fieldNumber + switch fieldNumber { + case 1: // Keys are basic types + try KeyType.decodeSingular(value: &k, from: &subdecoder) + case 2: // Value is an Enum type + try subdecoder.decodeSingularEnumField(value: &v) + if v == nil && tag.wireFormat == .varint { + // Enum decode fail and wire format was varint, so this had to + // have been a proto2 unknown enum value. This whole map entry + // into the parent message's unknown fields. If the wire format + // was wrong, treat it like an unknown field and drop it with + // the map entry. + return + } + default: // Skip any other fields within the map entry object + try subdecoder.skip() + } + } + if !subdecoder.complete { + throw BinaryDecodingError.trailingGarbage + } + // A map<> definition can't provide a default value for the keys, so it + // is safe to use the proto3 default to get the right integer/string/bytes. + value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType() + consumed = true + } + + internal mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { + guard fieldWireFormat == WireFormat.lengthDelimited else { + return + } + var k: KeyType.BaseType? + var v: ValueType? + var count: Int = 0 + let p = try getFieldBodyBytes(count: &count) + var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) + while let tag = try subdecoder.getTag() { + if tag.wireFormat == .endGroup { + throw BinaryDecodingError.malformedProtobuf + } + let fieldNumber = tag.fieldNumber + switch fieldNumber { + case 1: // Keys are basic types + try KeyType.decodeSingular(value: &k, from: &subdecoder) + case 2: // Value is a message type + try subdecoder.decodeSingularMessageField(value: &v) + default: // Skip any other fields within the map entry object + try subdecoder.skip() + } + } + if !subdecoder.complete { + throw BinaryDecodingError.trailingGarbage + } + // A map<> definition can't provide a default value for the keys, so it + // is safe to use the proto3 default to get the right integer/string/bytes. + value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType() + consumed = true + } + + internal mutating func decodeExtensionField( + values: inout ExtensionFieldValueSet, + messageType: Message.Type, + fieldNumber: Int + ) throws { + if let ext = extensions?[messageType, fieldNumber] { + try decodeExtensionField(values: &values, + messageType: messageType, + fieldNumber: fieldNumber, + messageExtension: ext) + } + } + + /// Helper to reuse between Extension decoding and MessageSet Extension decoding. + private mutating func decodeExtensionField( + values: inout ExtensionFieldValueSet, + messageType: Message.Type, + fieldNumber: Int, + messageExtension ext: AnyMessageExtension + ) throws { + assert(!consumed) + assert(fieldNumber == ext.fieldNumber) + var fieldValue = values[fieldNumber] + // Message/Group extensions both will call back into the matching + // decode methods, so the recursion depth will be tracked there. + if fieldValue != nil { + try fieldValue!.decodeExtensionField(decoder: &self) + } else { + fieldValue = try ext._protobuf_newField(decoder: &self) + } + if consumed { + if fieldValue != nil { + values[fieldNumber] = fieldValue + } else { + // Really things should never get here, if the decoder says + // the bytes were consumed, then there should have been a + // field that consumed them (existing or created). This + // specific error result is to allow this to be more detectable. + throw BinaryDecodingError.internalExtensionError + } + } + } + + internal mutating func decodeExtensionFieldsAsMessageSet( + values: inout ExtensionFieldValueSet, + messageType: Message.Type + ) throws { + // Spin looking for the Item group, everything else will end up in unknown fields. + while let fieldNumber = try self.nextFieldNumber() { + guard fieldNumber == WireFormat.MessageSet.FieldNumbers.item && + fieldWireFormat == WireFormat.startGroup else { + continue + } + + // This is similiar to decodeFullGroup + + try incrementRecursionDepth() + var subDecoder = self + subDecoder.groupFieldNumber = fieldNumber + subDecoder.consumed = true + + let itemResult = try subDecoder.decodeMessageSetItem(values: &values, + messageType: messageType) + switch itemResult { + case .success: + // Advance over what was parsed. + consume(length: available - subDecoder.available) + consumed = true + case .handleAsUnknown: + // Nothing to do. + break + + case .malformed: + throw BinaryDecodingError.malformedProtobuf + } + + assert(recursionBudget == subDecoder.recursionBudget) + decrementRecursionDepth() + } + } + + private enum DecodeMessageSetItemResult { + case success + case handleAsUnknown + case malformed + } + + private mutating func decodeMessageSetItem( + values: inout ExtensionFieldValueSet, + messageType: Message.Type + ) throws -> DecodeMessageSetItemResult { + // This is loosely based on the C++: + // ExtensionSet::ParseMessageSetItem() + // WireFormat::ParseAndMergeMessageSetItem() + // (yes, there have two versions that are almost the same) + + var msgExtension: AnyMessageExtension? + var fieldData: Data? + + // In this loop, if wire types are wrong, things don't decode, + // just bail instead of letting things go into unknown fields. + // Wrongly formed MessageSets don't seem don't have real + // spelled out behaviors. + while let fieldNumber = try self.nextFieldNumber() { + switch fieldNumber { + case WireFormat.MessageSet.FieldNumbers.typeId: + var extensionFieldNumber: Int32 = 0 + try decodeSingularInt32Field(value: &extensionFieldNumber) + if extensionFieldNumber == 0 { return .malformed } + guard let ext = extensions?[messageType, Int(extensionFieldNumber)] else { + return .handleAsUnknown // Unknown extension. + } + msgExtension = ext + + // If there already was fieldData, decode it. + if let data = fieldData { + var wasDecoded = false + try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + var extDecoder = BinaryDecoder(forReadingFrom: pointer, + count: body.count, + parent: self) + // Prime the decode to be correct. + extDecoder.consumed = false + extDecoder.fieldWireFormat = .lengthDelimited + try extDecoder.decodeExtensionField(values: &values, + messageType: messageType, + fieldNumber: fieldNumber, + messageExtension: ext) + wasDecoded = extDecoder.consumed + } + } + if !wasDecoded { + return .malformed + } + fieldData = nil + } + + case WireFormat.MessageSet.FieldNumbers.message: + if let ext = msgExtension { + assert(consumed == false) + try decodeExtensionField(values: &values, + messageType: messageType, + fieldNumber: ext.fieldNumber, + messageExtension: ext) + if !consumed { + return .malformed + } + } else { + // The C++ references ends up appending the blocks together as length + // delimited blocks, but the parsing will only use the first block. + // So just capture a block, and then skip any others that happen to + // be found. + if fieldData == nil { + var d: Data? + try decodeSingularBytesField(value: &d) + guard let data = d else { return .malformed } + // Save it as length delimited + let payloadSize = Varint.encodedSize(of: Int64(data.count)) + data.count + var payload = Data(count: payloadSize) + payload.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + var encoder = BinaryEncoder(forWritingInto: pointer) + encoder.putBytesValue(value: data) + } + } + fieldData = payload + } else { + guard fieldWireFormat == .lengthDelimited else { return .malformed } + try skip() + consumed = true + } + } + + default: + // Skip everything else + try skip() + consumed = true + } + } + + return .success + } + + // + // Private building blocks for the parsing above. + // + // Having these be private gives the compiler maximum latitude for + // inlining. + // + + /// Private: Advance the current position. + private mutating func consume(length: Int) { + available -= length + p += length + } + + /// Private: Skip the body for the given tag. If the given tag is + /// a group, it parses up through the corresponding group end. + private mutating func skipOver(tag: FieldTag) throws { + switch tag.wireFormat { + case .varint: + if available < 1 { + throw BinaryDecodingError.truncated + } + var c = p[0] + while (c & 0x80) != 0 { + p += 1 + available -= 1 + if available < 1 { + throw BinaryDecodingError.truncated + } + c = p[0] + } + p += 1 + available -= 1 + case .fixed64: + if available < 8 { + throw BinaryDecodingError.truncated + } + p += 8 + available -= 8 + case .lengthDelimited: + let n = try decodeVarint() + if n <= UInt64(available) { + p += Int(n) + available -= Int(n) + } else { + throw BinaryDecodingError.truncated + } + case .startGroup: + try incrementRecursionDepth() + while true { + if let innerTag = try getTagWithoutUpdatingFieldStart() { + if innerTag.wireFormat == .endGroup { + if innerTag.fieldNumber == tag.fieldNumber { + decrementRecursionDepth() + break + } else { + // .endGroup for a something other than the current + // group is an invalid binary. + throw BinaryDecodingError.malformedProtobuf + } + } else { + try skipOver(tag: innerTag) + } + } else { + throw BinaryDecodingError.truncated + } + } + case .endGroup: + throw BinaryDecodingError.malformedProtobuf + case .fixed32: + if available < 4 { + throw BinaryDecodingError.truncated + } + p += 4 + available -= 4 + } + } + + /// Private: Skip to the end of the current field. + /// + /// Assumes that fieldStartP was bookmarked by a previous + /// call to getTagType(). + /// + /// On exit, fieldStartP points to the first byte of the tag, fieldEndP points + /// to the first byte after the field contents, and p == fieldEndP. + private mutating func skip() throws { + if let end = fieldEndP { + p = end + } else { + // Rewind to start of current field. + available += p - fieldStartP + p = fieldStartP + guard let tag = try getTagWithoutUpdatingFieldStart() else { + throw BinaryDecodingError.truncated + } + try skipOver(tag: tag) + fieldEndP = p + } + } + + /// Private: Parse the next raw varint from the input. + private mutating func decodeVarint() throws -> UInt64 { + if available < 1 { + throw BinaryDecodingError.truncated + } + var start = p + var length = available + var c = start[0] + start += 1 + length -= 1 + if c & 0x80 == 0 { + p = start + available = length + return UInt64(c) + } + var value = UInt64(c & 0x7f) + var shift = UInt64(7) + while true { + if length < 1 || shift > 63 { + throw BinaryDecodingError.malformedProtobuf + } + c = start[0] + start += 1 + length -= 1 + value |= UInt64(c & 0x7f) << shift + if c & 0x80 == 0 { + p = start + available = length + return value + } + shift += 7 + } + } + + /// Private: Get the tag that starts a new field. + /// This also bookmarks the start of field for a possible skip(). + internal mutating func getTag() throws -> FieldTag? { + fieldStartP = p + fieldEndP = nil + return try getTagWithoutUpdatingFieldStart() + } + + /// Private: Parse and validate the next tag without + /// bookmarking the start of the field. This is used within + /// skip() to skip over fields within a group. + private mutating func getTagWithoutUpdatingFieldStart() throws -> FieldTag? { + if available < 1 { + return nil + } + let t = try decodeVarint() + if t < UInt64(UInt32.max) { + guard let tag = FieldTag(rawValue: UInt32(truncatingIfNeeded: t)) else { + throw BinaryDecodingError.malformedProtobuf + } + fieldWireFormat = tag.wireFormat + fieldNumber = tag.fieldNumber + return tag + } else { + throw BinaryDecodingError.malformedProtobuf + } + } + + /// Private: Return a Data containing the entirety of + /// the current field, including tag. + private mutating func getRawField() throws -> Data { + try skip() + return Data(bytes: fieldStartP, count: fieldEndP! - fieldStartP) + } + + /// Private: decode a fixed-length four-byte number. This generic + /// helper handles all four-byte number types. + private mutating func decodeFourByteNumber(value: inout T) throws { + guard available >= 4 else {throw BinaryDecodingError.truncated} + withUnsafeMutablePointer(to: &value) { ip -> Void in + let dest = UnsafeMutableRawPointer(ip).assumingMemoryBound(to: UInt8.self) + let src = UnsafeRawPointer(p).assumingMemoryBound(to: UInt8.self) + dest.initialize(from: src, count: 4) + } + consume(length: 4) + } + + /// Private: decode a fixed-length eight-byte number. This generic + /// helper handles all eight-byte number types. + private mutating func decodeEightByteNumber(value: inout T) throws { + guard available >= 8 else {throw BinaryDecodingError.truncated} + withUnsafeMutablePointer(to: &value) { ip -> Void in + let dest = UnsafeMutableRawPointer(ip).assumingMemoryBound(to: UInt8.self) + let src = UnsafeRawPointer(p).assumingMemoryBound(to: UInt8.self) + dest.initialize(from: src, count: 8) + } + consume(length: 8) + } + + private mutating func decodeFloat() throws -> Float { + var littleEndianBytes: UInt32 = 0 + try decodeFourByteNumber(value: &littleEndianBytes) + var nativeEndianBytes = UInt32(littleEndian: littleEndianBytes) + var float: Float = 0 + let n = MemoryLayout.size + memcpy(&float, &nativeEndianBytes, n) + return float + } + + private mutating func decodeDouble() throws -> Double { + var littleEndianBytes: UInt64 = 0 + try decodeEightByteNumber(value: &littleEndianBytes) + var nativeEndianBytes = UInt64(littleEndian: littleEndianBytes) + var double: Double = 0 + let n = MemoryLayout.size + memcpy(&double, &nativeEndianBytes, n) + return double + } + + /// Private: Get the start and length for the body of + // a length-delimited field. + private mutating func getFieldBodyBytes(count: inout Int) throws -> UnsafePointer { + let length = try decodeVarint() + if length <= UInt64(available) { + count = Int(length) + let body = p + consume(length: count) + return body + } + throw BinaryDecodingError.truncated + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift new file mode 100644 index 0000000..6c6d34f --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift @@ -0,0 +1,44 @@ +// Sources/SwiftProtobuf/BinaryDecodingError.swift - Protobuf binary decoding errors +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Protobuf binary format decoding errors +/// +// ----------------------------------------------------------------------------- + +/// Describes errors that can occur when decoding a message from binary format. +public enum BinaryDecodingError: Error { + /// Extraneous data remained after decoding should have been complete. + case trailingGarbage + + /// The decoder unexpectedly reached the end of the data before it was + /// expected. + case truncated + + /// A string field was not encoded as valid UTF-8. + case invalidUTF8 + + /// The binary data was malformed in some way, such as an invalid wire format + /// or field tag. + case malformedProtobuf + + /// The definition of the message or one of its nested messages has required + /// fields but the binary data did not include values for them. You must pass + /// `partial: true` during decoding if you wish to explicitly ignore missing + /// required fields. + case missingRequiredFields + + /// An internal error happened while decoding. If this is ever encountered, + /// please file an issue with SwiftProtobuf with as much details as possible + /// for what happened (proto definitions, bytes being decoded (if possible)). + case internalExtensionError + + /// Reached the nesting limit for messages within messages while decoding. + case messageDepthLimit +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift new file mode 100644 index 0000000..63eefa8 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift @@ -0,0 +1,39 @@ +// Sources/SwiftProtobuf/BinaryDecodingOptions.swift - Binary decoding options +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Binary decoding options +/// +// ----------------------------------------------------------------------------- + +/// Options for JSONDecoding. +public struct BinaryDecodingOptions { + /// The maximum nesting of message with messages. The default is 100. + /// + /// To prevent corrupt or malicious messages from causing stack overflows, + /// this controls how deep messages can be nested within other messages + /// while parsing. + public var messageDepthLimit: Int = 100 + + /// Discard unknown fields while parsing. The default is false, so parsering + /// does not discard unknown fields. + /// + /// The Protobuf binary format allows unknown fields to be still parsed + /// so the schema can be expanded without requiring all readers to be updated. + /// This works in part by haivng any unknown fields preserved so they can + /// be relayed on without loss. For a while the proto3 syntax definition + /// called for unknown fields to be dropped, but that lead to problems in + /// some case. The default is to follow the spec and keep them, but setting + /// this option to `true` allows a developer to strip them during a parse + /// in case they have a specific need to drop the unknown fields from the + /// object graph being created. + public var discardUnknownFields: Bool = false + + public init() {} +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift new file mode 100644 index 0000000..25420a6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift @@ -0,0 +1,227 @@ +// Sources/SwiftProtobuf/BinaryDelimited.swift - Delimited support +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Helpers to read/write message with a length prefix. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Helper methods for reading/writing messages with a length prefix. +public enum BinaryDelimited { + /// Additional errors for delimited message handing. + public enum Error: Swift.Error { + /// If a read/write to the stream fails, but the stream's `streamError` is nil, + /// this error will be throw instead since the stream didn't provide anything + /// more specific. A common cause for this can be failing to open the stream + /// before trying to read/write to it. + case unknownStreamError + + /// While reading/writing to the stream, less than the expected bytes was + /// read/written. + case truncated + } + + /// Serialize a single size-delimited message from the given stream. Delimited + /// format allows a single file or stream to contain multiple messages, + /// whereas normally writing multiple non-delimited messages to the same + /// stream would cause them to be merged. A delimited message is a varint + /// encoding the message size followed by a message of exactly that size. + /// + /// - Parameters: + /// - message: The message to be written. + /// - to: The `OutputStream` to write the message to. The stream is + /// is assumed to be ready to be written to. + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - Throws: `BinaryEncodingError` if encoding fails, throws + /// `BinaryDelimited.Error` for some writing errors, or the + /// underlying `OutputStream.streamError` for a stream error. + public static func serialize( + message: Message, + to stream: OutputStream, + partial: Bool = false + ) throws { + // TODO: Revisit to avoid the extra buffering when encoding is streamed in general. + let serialized = try message.serializedData(partial: partial) + let totalSize = Varint.encodedSize(of: UInt64(serialized.count)) + serialized.count + var data = Data(count: totalSize) + data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + var encoder = BinaryEncoder(forWritingInto: pointer) + encoder.putBytesValue(value: serialized) + } + } + + var written: Int = 0 + data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + written = stream.write(pointer, maxLength: totalSize) + } + } + + if written != totalSize { + if written == -1 { + if let streamError = stream.streamError { + throw streamError + } + throw BinaryDelimited.Error.unknownStreamError + } + throw BinaryDelimited.Error.truncated + } + } + + /// Reads a single size-delimited message from the given stream. Delimited + /// format allows a single file or stream to contain multiple messages, + /// whereas normally parsing consumes the entire input. A delimited message + /// is a varint encoding the message size followed by a message of exactly + /// exactly that size. + /// + /// - Parameters: + /// - messageType: The type of message to read. + /// - from: The `InputStream` to read the data from. The stream is assumed + /// to be ready to read from. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - options: The BinaryDecodingOptions to use. + /// - Returns: The message read. + /// - Throws: `BinaryDecodingError` if decoding fails, throws + /// `BinaryDelimited.Error` for some reading errors, and the + /// underlying InputStream.streamError for a stream error. + public static func parse( + messageType: M.Type, + from stream: InputStream, + extensions: ExtensionMap? = nil, + partial: Bool = false, + options: BinaryDecodingOptions = BinaryDecodingOptions() + ) throws -> M { + var message = M() + try merge(into: &message, + from: stream, + extensions: extensions, + partial: partial, + options: options) + return message + } + + /// Updates the message by reading a single size-delimited message from + /// the given stream. Delimited format allows a single file or stream to + /// contain multiple messages, whereas normally parsing consumes the entire + /// input. A delimited message is a varint encoding the message size + /// followed by a message of exactly that size. + /// + /// - Note: If this method throws an error, the message may still have been + /// partially mutated by the binary data that was decoded before the error + /// occurred. + /// + /// - Parameters: + /// - mergingTo: The message to merge the data into. + /// - from: The `InputStream` to read the data from. The stream is assumed + /// to be ready to read from. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - options: The BinaryDecodingOptions to use. + /// - Throws: `BinaryDecodingError` if decoding fails, throws + /// `BinaryDelimited.Error` for some reading errors, and the + /// underlying InputStream.streamError for a stream error. + public static func merge( + into message: inout M, + from stream: InputStream, + extensions: ExtensionMap? = nil, + partial: Bool = false, + options: BinaryDecodingOptions = BinaryDecodingOptions() + ) throws { + let length = try Int(decodeVarint(stream)) + if length == 0 { + // The message was all defaults, nothing to actually read. + return + } + + var data = Data(count: length) + var bytesRead: Int = 0 + data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + bytesRead = stream.read(pointer, maxLength: length) + } + } + + if bytesRead != length { + if bytesRead == -1 { + if let streamError = stream.streamError { + throw streamError + } + throw BinaryDelimited.Error.unknownStreamError + } + throw BinaryDelimited.Error.truncated + } + + try message.merge(serializedData: data, + extensions: extensions, + partial: partial, + options: options) + } +} + +// TODO: This should go away when encoding/decoding are more stream based +// as that should provide a more direct way to do this. This is basically +// a rewrite of BinaryDecoder.decodeVarint(). +internal func decodeVarint(_ stream: InputStream) throws -> UInt64 { + + // Buffer to reuse within nextByte. + var readBuffer = UnsafeMutablePointer.allocate(capacity: 1) + #if swift(>=4.1) + defer { readBuffer.deallocate() } + #else + defer { readBuffer.deallocate(capacity: 1) } + #endif + + func nextByte() throws -> UInt8 { + let bytesRead = stream.read(readBuffer, maxLength: 1) + if bytesRead != 1 { + if bytesRead == -1 { + if let streamError = stream.streamError { + throw streamError + } + throw BinaryDelimited.Error.unknownStreamError + } + throw BinaryDelimited.Error.truncated + } + return readBuffer[0] + } + + var value: UInt64 = 0 + var shift: UInt64 = 0 + while true { + let c = try nextByte() + value |= UInt64(c & 0x7f) << shift + if c & 0x80 == 0 { + return value + } + shift += 7 + if shift > 63 { + throw BinaryDecodingError.malformedProtobuf + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift new file mode 100644 index 0000000..b3c73f1 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift @@ -0,0 +1,135 @@ +// Sources/SwiftProtobuf/BinaryEncoder.swift - Binary encoding support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Core support for protobuf binary encoding. Note that this is built +/// on the general traversal machinery. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/* + * Encoder for Binary Protocol Buffer format + */ +internal struct BinaryEncoder { + private var pointer: UnsafeMutablePointer + + init(forWritingInto pointer: UnsafeMutablePointer) { + self.pointer = pointer + } + + private mutating func append(_ byte: UInt8) { + pointer.pointee = byte + pointer = pointer.successor() + } + + private mutating func append(contentsOf data: Data) { + let count = data.count + data.copyBytes(to: pointer, count: count) + pointer = pointer.advanced(by: count) + } + + private mutating func append(contentsOf bufferPointer: UnsafeBufferPointer) { + let count = bufferPointer.count + pointer.assign(from: bufferPointer.baseAddress!, count: count) + pointer = pointer.advanced(by: count) + } + + func distance(pointer: UnsafeMutablePointer) -> Int { + return pointer.distance(to: self.pointer) + } + + mutating func appendUnknown(data: Data) { + append(contentsOf: data) + } + + mutating func startField(fieldNumber: Int, wireFormat: WireFormat) { + startField(tag: FieldTag(fieldNumber: fieldNumber, wireFormat: wireFormat)) + } + + mutating func startField(tag: FieldTag) { + putVarInt(value: UInt64(tag.rawValue)) + } + + mutating func putVarInt(value: UInt64) { + var v = value + while v > 127 { + append(UInt8(v & 0x7f | 0x80)) + v >>= 7 + } + append(UInt8(v)) + } + + mutating func putVarInt(value: Int64) { + putVarInt(value: UInt64(bitPattern: value)) + } + + mutating func putVarInt(value: Int) { + putVarInt(value: Int64(value)) + } + + mutating func putZigZagVarInt(value: Int64) { + let coded = ZigZag.encoded(value) + putVarInt(value: coded) + } + + mutating func putBoolValue(value: Bool) { + append(value ? 1 : 0) + } + + mutating func putFixedUInt64(value: UInt64) { + var v = value.littleEndian + let n = MemoryLayout.size + memcpy(pointer, &v, n) + pointer = pointer.advanced(by: n) + } + + mutating func putFixedUInt32(value: UInt32) { + var v = value.littleEndian + let n = MemoryLayout.size + memcpy(pointer, &v, n) + pointer = pointer.advanced(by: n) + } + + mutating func putFloatValue(value: Float) { + let n = MemoryLayout.size + var v = value + var nativeBytes: UInt32 = 0 + memcpy(&nativeBytes, &v, n) + var littleEndianBytes = nativeBytes.littleEndian + memcpy(pointer, &littleEndianBytes, n) + pointer = pointer.advanced(by: n) + } + + mutating func putDoubleValue(value: Double) { + let n = MemoryLayout.size + var v = value + var nativeBytes: UInt64 = 0 + memcpy(&nativeBytes, &v, n) + var littleEndianBytes = nativeBytes.littleEndian + memcpy(pointer, &littleEndianBytes, n) + pointer = pointer.advanced(by: n) + } + + // Write a string field, including the leading index/tag value. + mutating func putStringValue(value: String) { + let count = value.utf8.count + putVarInt(value: count) + for b in value.utf8 { + pointer.pointee = b + pointer = pointer.successor() + } + } + + mutating func putBytesValue(value: Data) { + putVarInt(value: value.count) + append(contentsOf: value) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift new file mode 100644 index 0000000..584d823 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift @@ -0,0 +1,27 @@ +// Sources/SwiftProtobuf/BinaryEncodingError.swift - Error constants +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Enum constants that identify the particular error. +/// +// ----------------------------------------------------------------------------- + +/// Describes errors that can occur when decoding a message from binary format. +public enum BinaryEncodingError: Error { + /// `Any` fields that were decoded from JSON cannot be re-encoded to binary + /// unless the object they hold is a well-known type or a type registered via + /// `Google_Protobuf_Any.register()`. + case anyTranscodeFailure + + /// The definition of the message or one of its nested messages has required + /// fields but the message being encoded did not include values for them. You + /// must pass `partial: true` during encoding if you wish to explicitly ignore + /// missing required fields. + case missingRequiredFields +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift new file mode 100644 index 0000000..ba5af7b --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift @@ -0,0 +1,369 @@ +// Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift - Binary size calculation support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Visitor used during binary encoding that precalcuates the size of a +/// serialized message. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Visitor that calculates the binary-encoded size of a message so that a +/// properly sized `Data` or `UInt8` array can be pre-allocated before +/// serialization. +internal struct BinaryEncodingSizeVisitor: Visitor { + + /// Accumulates the required size of the message during traversal. + var serializedSize: Int = 0 + + init() {} + + mutating func visitUnknown(bytes: Data) throws { + serializedSize += bytes.count + } + + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt64Field(value: Int64(value), fieldNumber: fieldNumber) + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize + serializedSize += tagSize + Varint.encodedSize(of: value) + } + + mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: UInt64(value), fieldNumber: fieldNumber) + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize + serializedSize += tagSize + Varint.encodedSize(of: value) + } + + mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize + serializedSize += tagSize + Varint.encodedSize(of: ZigZag.encoded(value)) + } + + mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize + serializedSize += tagSize + Varint.encodedSize(of: ZigZag.encoded(value)) + } + + mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize + serializedSize += tagSize + MemoryLayout.size + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize + serializedSize += tagSize + 1 + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let count = value.utf8.count + serializedSize += tagSize + Varint.encodedSize(of: Int64(count)) + count + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let count = value.count + serializedSize += tagSize + Varint.encodedSize(of: Int64(count)) + count + } + + mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: v) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: v) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: ZigZag.encoded(v)) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: ZigZag.encoded(v)) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: v) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: v) + } + serializedSize += + tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count * MemoryLayout.size + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize + let dataSize = value.count + serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitSingularEnumField(value: E, + fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .varint).encodedSize + serializedSize += tagSize + let dataSize = Varint.encodedSize(of: Int32(truncatingIfNeeded: value.rawValue)) + serializedSize += dataSize + } + + mutating func visitRepeatedEnumField(value: [E], + fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .varint).encodedSize + serializedSize += value.count * tagSize + for v in value { + let dataSize = Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) + serializedSize += dataSize + } + } + + mutating func visitPackedEnumField(value: [E], + fieldNumber: Int) throws { + guard !value.isEmpty else { + return + } + + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .varint).encodedSize + serializedSize += tagSize + var dataSize = 0 + for v in value { + dataSize += Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) + } + serializedSize += Varint.encodedSize(of: Int64(dataSize)) + dataSize + } + + mutating func visitSingularMessageField(value: M, + fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .lengthDelimited).encodedSize + let messageSize = try value.serializedDataSize() + serializedSize += + tagSize + Varint.encodedSize(of: UInt64(messageSize)) + messageSize + } + + mutating func visitRepeatedMessageField(value: [M], + fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .lengthDelimited).encodedSize + serializedSize += value.count * tagSize + for v in value { + let messageSize = try v.serializedDataSize() + serializedSize += + Varint.encodedSize(of: UInt64(messageSize)) + messageSize + } + } + + mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { + // The wire format doesn't matter here because the encoded size of the + // integer won't change based on the low three bits. + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .startGroup).encodedSize + serializedSize += 2 * tagSize + try value.traverse(visitor: &self) + } + + mutating func visitRepeatedGroupField(value: [G], + fieldNumber: Int) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .startGroup).encodedSize + serializedSize += 2 * value.count * tagSize + for v in value { + try v.traverse(visitor: &self) + } + } + + mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int + ) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .lengthDelimited).encodedSize + for (k,v) in value { + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try ValueType.visitSingular(value: v, fieldNumber: 2, with: &sizer) + let entrySize = sizer.serializedSize + serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize + } + serializedSize += value.count * tagSize + } + + mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int + ) throws where ValueType.RawValue == Int { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .lengthDelimited).encodedSize + for (k,v) in value { + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try sizer.visitSingularEnumField(value: v, fieldNumber: 2) + let entrySize = sizer.serializedSize + serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize + } + serializedSize += value.count * tagSize + } + + mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int + ) throws { + let tagSize = FieldTag(fieldNumber: fieldNumber, + wireFormat: .lengthDelimited).encodedSize + for (k,v) in value { + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try sizer.visitSingularMessageField(value: v, fieldNumber: 2) + let entrySize = sizer.serializedSize + serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize + } + serializedSize += value.count * tagSize + } + + mutating func visitExtensionFieldsAsMessageSet( + fields: ExtensionFieldValueSet, + start: Int, + end: Int + ) throws { + var sizer = BinaryEncodingMessageSetSizeVisitor() + try fields.traverse(visitor: &sizer, start: start, end: end) + serializedSize += sizer.serializedSize + } +} + +extension BinaryEncodingSizeVisitor { + + // Helper Visitor to compute the sizes when writing out the extensions as MessageSets. + internal struct BinaryEncodingMessageSetSizeVisitor: SelectiveVisitor { + var serializedSize: Int = 0 + + init() {} + + mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { + var groupSize = WireFormat.MessageSet.itemTagsEncodedSize + + groupSize += Varint.encodedSize(of: Int32(fieldNumber)) + + let messageSize = try value.serializedDataSize() + groupSize += Varint.encodedSize(of: UInt64(messageSize)) + messageSize + + serializedSize += groupSize + } + + // SelectiveVisitor handles the rest. + } + +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift new file mode 100644 index 0000000..16c68c7 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift @@ -0,0 +1,360 @@ +// Sources/SwiftProtobuf/BinaryEncodingVisitor.swift - Binary encoding support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Core support for protobuf binary encoding. Note that this is built +/// on the general traversal machinery. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Visitor that encodes a message graph in the protobuf binary wire format. +internal struct BinaryEncodingVisitor: Visitor { + + var encoder: BinaryEncoder + + /// Creates a new visitor that writes the binary-coded message into the memory + /// at the given pointer. + /// + /// - Precondition: `pointer` must point to an allocated block of memory that + /// is large enough to hold the entire encoded message. For performance + /// reasons, the encoder does not make any attempts to verify this. + init(forWritingInto pointer: UnsafeMutablePointer) { + encoder = BinaryEncoder(forWritingInto: pointer) + } + + init(encoder: BinaryEncoder) { + self.encoder = encoder + } + + mutating func visitUnknown(bytes: Data) throws { + encoder.appendUnknown(data: bytes) + } + + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed32) + encoder.putFloatValue(value: value) + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed64) + encoder.putDoubleValue(value: value) + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: UInt64(bitPattern: value), fieldNumber: fieldNumber) + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .varint) + encoder.putVarInt(value: value) + } + + mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularSInt64Field(value: Int64(value), fieldNumber: fieldNumber) + } + + mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: ZigZag.encoded(value), fieldNumber: fieldNumber) + } + + mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed32) + encoder.putFixedUInt32(value: value) + } + + mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed64) + encoder.putFixedUInt64(value: value) + } + + mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularFixed32Field(value: UInt32(bitPattern: value), fieldNumber: fieldNumber) + } + + mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularFixed64Field(value: UInt64(bitPattern: value), fieldNumber: fieldNumber) + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: value ? 1 : 0, fieldNumber: fieldNumber) + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putStringValue(value: value) + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putBytesValue(value: value) + } + + mutating func visitSingularEnumField(value: E, + fieldNumber: Int) throws { + try visitSingularUInt64Field(value: UInt64(bitPattern: Int64(value.rawValue)), + fieldNumber: fieldNumber) + } + + mutating func visitSingularMessageField(value: M, + fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + let length = try value.serializedDataSize() + encoder.putVarInt(value: length) + try value.traverse(visitor: &self) + } + + mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .startGroup) + try value.traverse(visitor: &self) + encoder.startField(fieldNumber: fieldNumber, wireFormat: .endGroup) + } + + // Repeated fields are handled by the default implementations in Visitor.swift + + + // Packed Fields + + mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putFloatValue(value: v) + } + } + + mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putDoubleValue(value: v) + } + } + + mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: v) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putVarInt(value: Int64(v)) + } + } + + mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: v) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putVarInt(value: v) + } + } + + mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: ZigZag.encoded(v)) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putZigZagVarInt(value: Int64(v)) + } + } + + mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: ZigZag.encoded(v)) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putZigZagVarInt(value: v) + } + } + + mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: v) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putVarInt(value: UInt64(v)) + } + } + + mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: v) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putVarInt(value: v) + } + } + + mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putFixedUInt32(value: v) + } + } + + mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putFixedUInt64(value: v) + } + } + + mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putFixedUInt32(value: UInt32(bitPattern: v)) + } + } + + mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count * MemoryLayout.size) + for v in value { + encoder.putFixedUInt64(value: UInt64(bitPattern: v)) + } + } + + mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + encoder.putVarInt(value: value.count) + for v in value { + encoder.putVarInt(value: v ? 1 : 0) + } + } + + mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var packedSize = 0 + for v in value { + packedSize += Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) + } + encoder.putVarInt(value: packedSize) + for v in value { + encoder.putVarInt(value: v.rawValue) + } + } + + mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int + ) throws { + for (k,v) in value { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try ValueType.visitSingular(value: v, fieldNumber: 2, with: &sizer) + let entrySize = sizer.serializedSize + encoder.putVarInt(value: entrySize) + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) + try ValueType.visitSingular(value: v, fieldNumber: 2, with: &self) + } + } + + mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int + ) throws where ValueType.RawValue == Int { + for (k,v) in value { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try sizer.visitSingularEnumField(value: v, fieldNumber: 2) + let entrySize = sizer.serializedSize + encoder.putVarInt(value: entrySize) + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) + try visitSingularEnumField(value: v, fieldNumber: 2) + } + } + + mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int + ) throws { + for (k,v) in value { + encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) + var sizer = BinaryEncodingSizeVisitor() + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) + try sizer.visitSingularMessageField(value: v, fieldNumber: 2) + let entrySize = sizer.serializedSize + encoder.putVarInt(value: entrySize) + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) + try visitSingularMessageField(value: v, fieldNumber: 2) + } + } + + mutating func visitExtensionFieldsAsMessageSet( + fields: ExtensionFieldValueSet, + start: Int, + end: Int + ) throws { + var subVisitor = BinaryEncodingMessageSetVisitor(encoder: encoder) + try fields.traverse(visitor: &subVisitor, start: start, end: end) + encoder = subVisitor.encoder + } +} + +extension BinaryEncodingVisitor { + + // Helper Visitor to when writing out the extensions as MessageSets. + internal struct BinaryEncodingMessageSetVisitor: SelectiveVisitor { + var encoder: BinaryEncoder + + init(encoder: BinaryEncoder) { + self.encoder = encoder + } + + mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { + encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.itemStart.rawValue)) + + encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.typeId.rawValue)) + encoder.putVarInt(value: fieldNumber) + + encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.message.rawValue)) + + // Use a normal BinaryEncodingVisitor so any message fields end up in the + // normal wire format (instead of MessageSet format). + let length = try value.serializedDataSize() + encoder.putVarInt(value: length) + // Create the sub encoder after writing the length. + var subVisitor = BinaryEncodingVisitor(encoder: encoder) + try value.traverse(visitor: &subVisitor) + encoder = subVisitor.encoder + + encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.itemEnd.rawValue)) + } + + // SelectiveVisitor handles the rest. + } + +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift new file mode 100644 index 0000000..64689cb --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift @@ -0,0 +1,36 @@ +// Sources/SwiftProtobuf/CustomJSONCodable.swift - Custom JSON support for WKTs +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Custom protocol for the WKTs to support their custom JSON encodings. +/// +// ----------------------------------------------------------------------------- + +/// Allows WKTs to provide their custom JSON encodings. +internal protocol _CustomJSONCodable { + func encodedJSONString(options: JSONEncodingOptions) throws -> String + mutating func decodeJSON(from: inout JSONDecoder) throws + + /// Called when the JSON `null` literal is encountered in a position where + /// a message of the conforming type is expected. The message type can then + /// handle the `null` value differently, if needed; for example, + /// `Google_Protobuf_Value` returns a special instance whose `kind` is set to + /// `.nullValue(.nullValue)`. + /// + /// The default behavior is to return `nil`, which indicates that `null` + /// should be treated as the absence of a message. + static func decodedFromJSONNull() throws -> Self? +} + +extension _CustomJSONCodable { + internal static func decodedFromJSONNull() -> Self? { + // Return nil by default. Concrete types can provide custom logic. + return nil + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift new file mode 100644 index 0000000..5b4e9a8 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift @@ -0,0 +1,33 @@ +// Sources/SwiftProtobuf/Data+Extensions.swift - Extension exposing new Data API +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extension exposing new Data API to Swift versions < 5.0. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +#if !swift(>=5.0) +internal extension Data { + func withUnsafeBytes(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T { + let c = count + return try withUnsafeBytes { (p: UnsafePointer) throws -> T in + try body(UnsafeRawBufferPointer(start: p, count: c)) + } + } + + mutating func withUnsafeMutableBytes(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T { + let c = count + return try withUnsafeMutableBytes { (p: UnsafeMutablePointer) throws -> T in + try body(UnsafeMutableRawBufferPointer(start: p, count: c)) + } + } +} +#endif diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift new file mode 100644 index 0000000..01a8ed8 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift @@ -0,0 +1,150 @@ +// Sources/SwiftProtobuf/Decoder.swift - Basic field setting +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// In this way, the generated code only knows about schema +/// information; the decoder logic knows how to decode particular +/// wire types based on that information. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// This is the abstract protocol used by the generated code +/// to deserialize data. +/// +/// The generated code looks roughly like this: +/// +/// ``` +/// while fieldNumber = try decoder.nextFieldNumber() { +/// switch fieldNumber { +/// case 1: decoder.decodeRepeatedInt32Field(value: &_field) +/// ... etc ... +/// } +/// ``` +/// +/// For performance, this is mostly broken out into a separate method +/// for singular/repeated fields of every supported type. Note that +/// we don't distinguish "packed" here, since all existing decoders +/// treat "packed" the same as "repeated" at this level. (That is, +/// even when the serializer distinguishes packed and non-packed +/// forms, the deserializer always accepts both.) +/// +/// Generics come into play at only a few points: `Enum`s and `Message`s +/// use a generic type to locate the correct initializer. Maps and +/// extensions use generics to avoid the method explosion of having to +/// support a separate method for every map and extension type. Maps +/// do distinguish `Enum`-valued and `Message`-valued maps to avoid +/// polluting the generated `Enum` and `Message` types with all of the +/// necessary generic methods to support this. +public protocol Decoder { + /// Called by a `oneof` when it already has a value and is being asked to + /// accept a new value. Some formats require `oneof` decoding to fail in this + /// case. + mutating func handleConflictingOneOf() throws + + /// Returns the next field number, or nil when the end of the input is + /// reached. + /// + /// For JSON and text format, the decoder translates the field name to a + /// number at this point, based on information it obtained from the message + /// when it was initialized. + mutating func nextFieldNumber() throws -> Int? + + // Primitive field decoders + mutating func decodeSingularFloatField(value: inout Float) throws + mutating func decodeSingularFloatField(value: inout Float?) throws + mutating func decodeRepeatedFloatField(value: inout [Float]) throws + mutating func decodeSingularDoubleField(value: inout Double) throws + mutating func decodeSingularDoubleField(value: inout Double?) throws + mutating func decodeRepeatedDoubleField(value: inout [Double]) throws + mutating func decodeSingularInt32Field(value: inout Int32) throws + mutating func decodeSingularInt32Field(value: inout Int32?) throws + mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws + mutating func decodeSingularInt64Field(value: inout Int64) throws + mutating func decodeSingularInt64Field(value: inout Int64?) throws + mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws + mutating func decodeSingularUInt32Field(value: inout UInt32) throws + mutating func decodeSingularUInt32Field(value: inout UInt32?) throws + mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws + mutating func decodeSingularUInt64Field(value: inout UInt64) throws + mutating func decodeSingularUInt64Field(value: inout UInt64?) throws + mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws + mutating func decodeSingularSInt32Field(value: inout Int32) throws + mutating func decodeSingularSInt32Field(value: inout Int32?) throws + mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws + mutating func decodeSingularSInt64Field(value: inout Int64) throws + mutating func decodeSingularSInt64Field(value: inout Int64?) throws + mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws + mutating func decodeSingularFixed32Field(value: inout UInt32) throws + mutating func decodeSingularFixed32Field(value: inout UInt32?) throws + mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws + mutating func decodeSingularFixed64Field(value: inout UInt64) throws + mutating func decodeSingularFixed64Field(value: inout UInt64?) throws + mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws + mutating func decodeSingularSFixed32Field(value: inout Int32) throws + mutating func decodeSingularSFixed32Field(value: inout Int32?) throws + mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws + mutating func decodeSingularSFixed64Field(value: inout Int64) throws + mutating func decodeSingularSFixed64Field(value: inout Int64?) throws + mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws + mutating func decodeSingularBoolField(value: inout Bool) throws + mutating func decodeSingularBoolField(value: inout Bool?) throws + mutating func decodeRepeatedBoolField(value: inout [Bool]) throws + mutating func decodeSingularStringField(value: inout String) throws + mutating func decodeSingularStringField(value: inout String?) throws + mutating func decodeRepeatedStringField(value: inout [String]) throws + mutating func decodeSingularBytesField(value: inout Data) throws + mutating func decodeSingularBytesField(value: inout Data?) throws + mutating func decodeRepeatedBytesField(value: inout [Data]) throws + + // Decode Enum fields + mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int + mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int + mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int + + // Decode Message fields + mutating func decodeSingularMessageField(value: inout M?) throws + mutating func decodeRepeatedMessageField(value: inout [M]) throws + + // Decode Group fields + mutating func decodeSingularGroupField(value: inout G?) throws + mutating func decodeRepeatedGroupField(value: inout [G]) throws + + // Decode Map fields. + // This is broken into separate methods depending on whether the value + // type is primitive (_ProtobufMap), enum (_ProtobufEnumMap), or message + // (_ProtobufMessageMap) + mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws + mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int + mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws + + // Decode extension fields + mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws + + // Run a decode loop decoding the MessageSet format for Extensions. + mutating func decodeExtensionFieldsAsMessageSet(values: inout ExtensionFieldValueSet, + messageType: Message.Type) throws +} + +/// Most Decoders won't care about Extension handing as in MessageSet +/// format, so provide a default implementation simply looping on the +/// fieldNumbers and feeding through to extension decoding. +extension Decoder { + public mutating func decodeExtensionFieldsAsMessageSet( + values: inout ExtensionFieldValueSet, + messageType: Message.Type + ) throws { + while let fieldNumber = try self.nextFieldNumber() { + try self.decodeExtensionField(values: &values, + messageType: messageType, + fieldNumber: fieldNumber) + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift new file mode 100644 index 0000000..5268aef --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift @@ -0,0 +1,68 @@ +// Sources/SwiftProtobuf/DoubleParser.swift - Generally useful mathematical functions +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Numeric parsing helper for float and double strings +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Support parsing float/double values from UTF-8 +internal class DoubleParser { + // Temporary buffer so we can null-terminate the UTF-8 string + // before calling the C standard libray to parse it. + // In theory, JSON writers should be able to represent any IEEE Double + // in at most 25 bytes, but many writers will emit more digits than + // necessary, so we size this generously. + #if swift(>=4.1) + private var work = + UnsafeMutableRawBufferPointer.allocate(byteCount: 128, + alignment: MemoryLayout.alignment) + #else + private var work = UnsafeMutableRawBufferPointer.allocate(count: 128) + #endif + + deinit { + work.deallocate() + } + + func utf8ToDouble(bytes: UnsafeBufferPointer, + start: UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index) -> Double? { + return utf8ToDouble(bytes: bytes.baseAddress! + start, count: end - start) + } + + func utf8ToDouble(bytes: UnsafePointer, count: Int) -> Double? { + // Reject unreasonably long or short UTF8 number + if work.count <= count || count < 1 { + return nil + } + // Copy it to the work buffer and null-terminate it + let source = UnsafeRawBufferPointer(start: bytes, count: count) + #if swift(>=4.1) + work.copyMemory(from:source) + #else + work.copyBytes(from:source) + #endif + work[count] = 0 + + // Use C library strtod() to parse it + let start = work.baseAddress!.assumingMemoryBound(to: Int8.self) + var e: UnsafeMutablePointer? = start + let d = strtod(start, &e) + + // Fail if strtod() did not consume everything we expected + // or if strtod() thought the number was out of range. + if e != start + count || !d.isFinite { + return nil + } + return d + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift new file mode 100644 index 0000000..850d3d6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift @@ -0,0 +1,93 @@ +// Sources/SwiftProtobuf/Enum.swift - Enum support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Generated enums conform to SwiftProtobuf.Enum +/// +/// See ProtobufTypes and JSONTypes for extension +/// methods to support binary and JSON coding. +/// +// ----------------------------------------------------------------------------- + +/// Generated enum types conform to this protocol. +public protocol Enum: RawRepresentable, Hashable { + /// Creates a new instance of the enum initialized to its default value. + init() + + /// Creates a new instance of the enum from the given raw integer value. + /// + /// For proto2 enums, this initializer will fail if the raw value does not + /// correspond to a valid enum value. For proto3 enums, this initializer never + /// fails; unknown values are created as instances of the `UNRECOGNIZED` case. + /// + /// - Parameter rawValue: The raw integer value from which to create the enum + /// value. + init?(rawValue: Int) + + /// The raw integer value of the enum value. + /// + /// For a recognized enum case, this is the integer value of the case as + /// defined in the .proto file. For `UNRECOGNIZED` cases in proto3, this is + /// the value that was originally decoded. + var rawValue: Int { get } +} + +extension Enum { +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(rawValue) + } +#else // swift(>=4.2) + public var hashValue: Int { + return rawValue + } +#endif // swift(>=4.2) + + /// Internal convenience property representing the name of the enum value (or + /// `nil` if it is an `UNRECOGNIZED` value or doesn't provide names). + /// + /// Since the text format and JSON names are always identical, we don't need + /// to distinguish them. + internal var name: _NameMap.Name? { + guard let nameProviding = Self.self as? _ProtoNameProviding.Type else { + return nil + } + return nameProviding._protobuf_nameMap.names(for: rawValue)?.proto + } + + /// Internal convenience initializer that returns the enum value with the + /// given name, if it provides names. + /// + /// Since the text format and JSON names are always identical, we don't need + /// to distinguish them. + /// + /// - Parameter name: The name of the enum case. + internal init?(name: String) { + guard let nameProviding = Self.self as? _ProtoNameProviding.Type, + let number = nameProviding._protobuf_nameMap.number(forJSONName: name) else { + return nil + } + self.init(rawValue: number) + } + + /// Internal convenience initializer that returns the enum value with the + /// given name, if it provides names. + /// + /// Since the text format and JSON names are always identical, we don't need + /// to distinguish them. + /// + /// - Parameter name: Buffer holding the UTF-8 bytes of the desired name. + internal init?(rawUTF8: UnsafeBufferPointer) { + guard let nameProviding = Self.self as? _ProtoNameProviding.Type, + let number = nameProviding._protobuf_nameMap.number(forJSONName: rawUTF8) else { + return nil + } + self.init(rawValue: number) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift new file mode 100644 index 0000000..73036e5 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift @@ -0,0 +1,39 @@ +// Sources/SwiftProtobuf/ExtensibleMessage.swift - Extension support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Additional capabilities needed by messages that allow extensions. +/// +// ----------------------------------------------------------------------------- + +// Messages that support extensions implement this protocol +public protocol ExtensibleMessage: Message { + var _protobuf_extensionFieldValues: ExtensionFieldValueSet { get set } +} + +extension ExtensibleMessage { + public mutating func setExtensionValue(ext: MessageExtension, value: F.ValueType) { + _protobuf_extensionFieldValues[ext.fieldNumber] = F(protobufExtension: ext, value: value) + } + + public func getExtensionValue(ext: MessageExtension) -> F.ValueType? { + if let fieldValue = _protobuf_extensionFieldValues[ext.fieldNumber] as? F { + return fieldValue.value + } + return nil + } + + public func hasExtensionValue(ext: MessageExtension) -> Bool { + return _protobuf_extensionFieldValues[ext.fieldNumber] is F + } + + public mutating func clearExtensionValue(ext: MessageExtension) { + _protobuf_extensionFieldValues[ext.fieldNumber] = nil + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift new file mode 100644 index 0000000..66343d6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift @@ -0,0 +1,89 @@ +// Sources/SwiftProtobuf/ExtensionFieldValueSet.swift - Extension support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A collection of extension field values on a particular object. +/// This is only used within messages to manage the values of extension fields; +/// it does not need to be very sophisticated. +/// +// ----------------------------------------------------------------------------- + +public struct ExtensionFieldValueSet: Hashable { + fileprivate var values = [Int : AnyExtensionField]() + + public static func ==(lhs: ExtensionFieldValueSet, + rhs: ExtensionFieldValueSet) -> Bool { + guard lhs.values.count == rhs.values.count else { + return false + } + for (index, l) in lhs.values { + if let r = rhs.values[index] { + if type(of: l) != type(of: r) { + return false + } + if !l.isEqual(other: r) { + return false + } + } else { + return false + } + } + return true + } + + public init() {} + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + // AnyExtensionField is not Hashable, and the Self constraint that would + // add breaks some of the uses of it; so the only choice is to manually + // mix things in. However, one must remember to do things in an order + // independent manner. + var hash = 16777619 + for (fieldNumber, v) in values { + var localHasher = hasher + localHasher.combine(fieldNumber) + v.hash(into: &localHasher) + hash = hash &+ localHasher.finalize() + } + hasher.combine(hash) + } +#else // swift(>=4.2) + public var hashValue: Int { + var hash = 16777619 + for (fieldNumber, v) in values { + // Note: This calculation cannot depend on the order of the items. + hash = hash &+ fieldNumber &+ v.hashValue + } + return hash + } +#endif // swift(>=4.2) + + public func traverse(visitor: inout V, start: Int, end: Int) throws { + let validIndexes = values.keys.filter {$0 >= start && $0 < end} + for i in validIndexes.sorted() { + let value = values[i]! + try value.traverse(visitor: &visitor) + } + } + + public subscript(index: Int) -> AnyExtensionField? { + get { return values[index] } + set { values[index] = newValue } + } + + public var isInitialized: Bool { + for (_, v) in values { + if !v.isInitialized { + return false + } + } + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift new file mode 100644 index 0000000..880f3a2 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift @@ -0,0 +1,708 @@ +// Sources/SwiftProtobuf/ExtensionFields.swift - Extension support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Core protocols implemented by generated extensions. +/// +// ----------------------------------------------------------------------------- + +#if !swift(>=4.2) +private let i_2166136261 = Int(bitPattern: 2166136261) +private let i_16777619 = Int(16777619) +#endif + +// +// Type-erased Extension field implementation. +// Note that it has no "self or associated type" references, so can +// be used as a protocol type. (In particular, although it does have +// a hashValue property, it cannot be Hashable.) +// +// This can encode, decode, return a hashValue and test for +// equality with some other extension field; but it's type-sealed +// so you can't actually access the contained value itself. +// +public protocol AnyExtensionField: CustomDebugStringConvertible { +#if swift(>=4.2) + func hash(into hasher: inout Hasher) +#else + var hashValue: Int { get } +#endif + var protobufExtension: AnyMessageExtension { get } + func isEqual(other: AnyExtensionField) -> Bool + + /// Merging field decoding + mutating func decodeExtensionField(decoder: inout T) throws + + /// Fields know their own type, so can dispatch to a visitor + func traverse(visitor: inout V) throws + + /// Check if the field is initialized. + var isInitialized: Bool { get } +} + +extension AnyExtensionField { + // Default implementation for extensions fields. The message types below provide + // custom versions. + public var isInitialized: Bool { return true } +} + +/// +/// The regular ExtensionField type exposes the value directly. +/// +public protocol ExtensionField: AnyExtensionField, Hashable { + associatedtype ValueType + var value: ValueType { get set } + init(protobufExtension: AnyMessageExtension, value: ValueType) + init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws +} + +/// +/// Singular field +/// +public struct OptionalExtensionField: ExtensionField { + public typealias BaseType = T.BaseType + public typealias ValueType = BaseType + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: OptionalExtensionField, + rhs: OptionalExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + + public var debugDescription: String { + get { + return String(reflecting: value) + } + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { return value.hashValue } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! OptionalExtensionField + return self == o + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + var v: ValueType? + try T.decodeSingular(value: &v, from: &decoder) + if let v = v { + value = v + } + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType? + try T.decodeSingular(value: &v, from: &decoder) + if let v = v { + self.init(protobufExtension: protobufExtension, value: v) + } else { + return nil + } + } + + public func traverse(visitor: inout V) throws { + try T.visitSingular(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) + } +} + +/// +/// Repeated fields +/// +public struct RepeatedExtensionField: ExtensionField { + public typealias BaseType = T.BaseType + public typealias ValueType = [BaseType] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: RepeatedExtensionField, + rhs: RepeatedExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! RepeatedExtensionField + return self == o + } + + public var debugDescription: String { + return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try T.decodeRepeated(value: &value, from: &decoder) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try T.decodeRepeated(value: &v, from: &decoder) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try T.visitRepeated(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) + } + } +} + +/// +/// Packed Repeated fields +/// +/// TODO: This is almost (but not quite) identical to RepeatedFields; +/// find a way to collapse the implementations. +/// +public struct PackedExtensionField: ExtensionField { + public typealias BaseType = T.BaseType + public typealias ValueType = [BaseType] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: PackedExtensionField, + rhs: PackedExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! PackedExtensionField + return self == o + } + + public var debugDescription: String { + return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try T.decodeRepeated(value: &value, from: &decoder) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try T.decodeRepeated(value: &v, from: &decoder) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try T.visitPacked(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) + } + } +} + +/// +/// Enum extensions +/// +public struct OptionalEnumExtensionField: ExtensionField where E.RawValue == Int { + public typealias BaseType = E + public typealias ValueType = E + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: OptionalEnumExtensionField, + rhs: OptionalEnumExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + + public var debugDescription: String { + get { + return String(reflecting: value) + } + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { return value.hashValue } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! OptionalEnumExtensionField + return self == o + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + var v: ValueType? + try decoder.decodeSingularEnumField(value: &v) + if let v = v { + value = v + } + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType? + try decoder.decodeSingularEnumField(value: &v) + if let v = v { + self.init(protobufExtension: protobufExtension, value: v) + } else { + return nil + } + } + + public func traverse(visitor: inout V) throws { + try visitor.visitSingularEnumField( + value: value, + fieldNumber: protobufExtension.fieldNumber) + } +} + +/// +/// Repeated Enum fields +/// +public struct RepeatedEnumExtensionField: ExtensionField where E.RawValue == Int { + public typealias BaseType = E + public typealias ValueType = [E] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: RepeatedEnumExtensionField, + rhs: RepeatedEnumExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! RepeatedEnumExtensionField + return self == o + } + + public var debugDescription: String { + return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try decoder.decodeRepeatedEnumField(value: &value) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try decoder.decodeRepeatedEnumField(value: &v) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try visitor.visitRepeatedEnumField( + value: value, + fieldNumber: protobufExtension.fieldNumber) + } + } +} + +/// +/// Packed Repeated Enum fields +/// +/// TODO: This is almost (but not quite) identical to RepeatedEnumFields; +/// find a way to collapse the implementations. +/// +public struct PackedEnumExtensionField: ExtensionField where E.RawValue == Int { + public typealias BaseType = E + public typealias ValueType = [E] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: PackedEnumExtensionField, + rhs: PackedEnumExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! PackedEnumExtensionField + return self == o + } + + public var debugDescription: String { + return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try decoder.decodeRepeatedEnumField(value: &value) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try decoder.decodeRepeatedEnumField(value: &v) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try visitor.visitPackedEnumField( + value: value, + fieldNumber: protobufExtension.fieldNumber) + } + } +} + +// +// ========== Message ========== +// +public struct OptionalMessageExtensionField: + ExtensionField { + public typealias BaseType = M + public typealias ValueType = BaseType + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: OptionalMessageExtensionField, + rhs: OptionalMessageExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + + public var debugDescription: String { + get { + return String(reflecting: value) + } + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + value.hash(into: &hasher) + } +#else // swift(>=4.2) + public var hashValue: Int {return value.hashValue} +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! OptionalMessageExtensionField + return self == o + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + var v: ValueType? = value + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + self.value = v + } + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType? + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + self.init(protobufExtension: protobufExtension, value: v) + } else { + return nil + } + } + + public func traverse(visitor: inout V) throws { + try visitor.visitSingularMessageField( + value: value, fieldNumber: protobufExtension.fieldNumber) + } + + public var isInitialized: Bool { + return value.isInitialized + } +} + +public struct RepeatedMessageExtensionField: + ExtensionField { + public typealias BaseType = M + public typealias ValueType = [BaseType] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: RepeatedMessageExtensionField, + rhs: RepeatedMessageExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + for e in value { + e.hash(into: &hasher) + } + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! RepeatedMessageExtensionField + return self == o + } + + public var debugDescription: String { + return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try decoder.decodeRepeatedMessageField(value: &value) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try decoder.decodeRepeatedMessageField(value: &v) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try visitor.visitRepeatedMessageField( + value: value, fieldNumber: protobufExtension.fieldNumber) + } + } + + public var isInitialized: Bool { + return Internal.areAllInitialized(value) + } +} + +// +// ======== Groups within Messages ======== +// +// Protoc internally treats groups the same as messages, but +// they serialize very differently, so we have separate serialization +// handling here... +public struct OptionalGroupExtensionField: + ExtensionField { + public typealias BaseType = G + public typealias ValueType = BaseType + public var value: G + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: OptionalGroupExtensionField, + rhs: OptionalGroupExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int {return value.hashValue} +#endif // swift(>=4.2) + + public var debugDescription: String { get {return value.debugDescription} } + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! OptionalGroupExtensionField + return self == o + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + var v: ValueType? = value + try decoder.decodeSingularGroupField(value: &v) + if let v = v { + value = v + } + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType? + try decoder.decodeSingularGroupField(value: &v) + if let v = v { + self.init(protobufExtension: protobufExtension, value: v) + } else { + return nil + } + } + + public func traverse(visitor: inout V) throws { + try visitor.visitSingularGroupField( + value: value, fieldNumber: protobufExtension.fieldNumber) + } + + public var isInitialized: Bool { + return value.isInitialized + } +} + +public struct RepeatedGroupExtensionField: + ExtensionField { + public typealias BaseType = G + public typealias ValueType = [BaseType] + public var value: ValueType + public var protobufExtension: AnyMessageExtension + + public static func ==(lhs: RepeatedGroupExtensionField, + rhs: RepeatedGroupExtensionField) -> Bool { + return lhs.value == rhs.value + } + + public init(protobufExtension: AnyMessageExtension, value: ValueType) { + self.protobufExtension = protobufExtension + self.value = value + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + hasher.combine(value) + } +#else // swift(>=4.2) + public var hashValue: Int { + get { + var hash = i_2166136261 + for e in value { + hash = (hash &* i_16777619) ^ e.hashValue + } + return hash + } + } +#endif // swift(>=4.2) + + public var debugDescription: String { + return "[" + value.map{$0.debugDescription}.joined(separator: ",") + "]" + } + + public func isEqual(other: AnyExtensionField) -> Bool { + let o = other as! RepeatedGroupExtensionField + return self == o + } + + public mutating func decodeExtensionField(decoder: inout D) throws { + try decoder.decodeRepeatedGroupField(value: &value) + } + + public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + var v: ValueType = [] + try decoder.decodeRepeatedGroupField(value: &v) + self.init(protobufExtension: protobufExtension, value: v) + } + + public func traverse(visitor: inout V) throws { + if value.count > 0 { + try visitor.visitRepeatedGroupField( + value: value, fieldNumber: protobufExtension.fieldNumber) + } + } + + public var isInitialized: Bool { + return Internal.areAllInitialized(value) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift new file mode 100644 index 0000000..b1115d7 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift @@ -0,0 +1,38 @@ +// Sources/SwiftProtobuf/ExtensionMap.swift - Extension support +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A set of extensions that can be passed into deserializers +/// to provide details of the particular extensions that should +/// be recognized. +/// +// ----------------------------------------------------------------------------- + +/// A collection of extension objects. +/// +/// An `ExtensionMap` is used during decoding to look up +/// extension objects corresponding to the serialized data. +/// +/// This is a protocol so that developers can build their own +/// extension handling if they need something more complex than the +/// standard `SimpleExtensionMap` implementation. +public protocol ExtensionMap { + /// Returns the extension object describing an extension or nil + subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { get } + + /// Returns the field number for a message with a specific field name + /// + /// The field name here matches the format used by the protobuf + /// Text serialization: it typically looks like + /// `package.message.field_name`, where `package` is the package + /// for the proto file and `message` is the name of the message in + /// which the extension was defined. (This is different from the + /// message that is being extended!) + func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift new file mode 100644 index 0000000..139897f --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift @@ -0,0 +1,69 @@ +// Sources/SwiftProtobuf/FieldTag.swift - Describes a binary field tag +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Types related to binary encoded tags (field numbers and wire formats). +/// +// ----------------------------------------------------------------------------- + +/// Encapsulates the number and wire format of a field, which together form the +/// "tag". +/// +/// This type also validates tags in that it will never allow a tag with an +/// improper field number (such as zero) or wire format (such as 6 or 7) to +/// exist. In other words, a `FieldTag`'s properties never need to be tested +/// for validity because they are guaranteed correct at initialization time. +internal struct FieldTag: RawRepresentable { + + typealias RawValue = UInt32 + + /// The raw numeric value of the tag, which contains both the field number and + /// wire format. + let rawValue: UInt32 + + /// The field number component of the tag. + var fieldNumber: Int { + return Int(rawValue >> 3) + } + + /// The wire format component of the tag. + var wireFormat: WireFormat { + // This force-unwrap is safe because there are only two initialization + // paths: one that takes a WireFormat directly (and is guaranteed valid at + // compile-time), or one that takes a raw value but which only lets valid + // wire formats through. + return WireFormat(rawValue: UInt8(rawValue & 7))! + } + + /// A helper property that returns the number of bytes required to + /// varint-encode this tag. + var encodedSize: Int { + return Varint.encodedSize(of: rawValue) + } + + /// Creates a new tag from its raw numeric representation. + /// + /// Note that if the raw value given here is not a valid tag (for example, it + /// has an invalid wire format), this initializer will fail. + init?(rawValue: UInt32) { + // Verify that the field number and wire format are valid and fail if they + // are not. + guard rawValue & ~0x07 != 0, + let _ = WireFormat(rawValue: UInt8(rawValue % 8)) else { + return nil + } + self.rawValue = rawValue + } + + /// Creates a new tag by composing the given field number and wire format. + init(fieldNumber: Int, wireFormat: WireFormat) { + self.rawValue = UInt32(truncatingIfNeeded: fieldNumber) << 3 | + UInt32(wireFormat.rawValue) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift new file mode 100644 index 0000000..ed269ff --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift @@ -0,0 +1,412 @@ +// Sources/SwiftProtobuf/FieldTypes.swift - Proto data types +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Serialization/deserialization support for each proto field type. +/// +/// Note that we cannot just extend the standard Int32, etc, types +/// with serialization information since proto language supports +/// distinct types (with different codings) that use the same +/// in-memory representation. For example, proto "sint32" and +/// "sfixed32" both are represented in-memory as Int32. +/// +/// These types are used generically and also passed into +/// various coding/decoding functions to provide type-specific +/// information. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +// Note: The protobuf- and JSON-specific methods here are defined +// in ProtobufTypeAdditions.swift and JSONTypeAdditions.swift +public protocol FieldType { + // The Swift type used to store data for this field. For example, + // proto "sint32" fields use Swift "Int32" type. + associatedtype BaseType: Hashable + + // The default value for this field type before it has been set. + // This is also used, for example, when JSON decodes a "null" + // value for a field. + static var proto3DefaultValue: BaseType { get } + + // Generic reflector methods for looking up the correct + // encoding/decoding for extension fields, map keys, and map + // values. + static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws + static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws + static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws + static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws + static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws +} + +/// +/// Marker protocol for types that can be used as map keys +/// +public protocol MapKeyType: FieldType { +} + +/// +/// Marker Protocol for types that can be used as map values. +/// +public protocol MapValueType: FieldType { +} + +// +// We have a struct for every basic proto field type which provides +// serialization/deserialization support as static methods. +// + +/// +/// Float traits +/// +public struct ProtobufFloat: FieldType, MapValueType { + public typealias BaseType = Float + public static var proto3DefaultValue: Float {return 0.0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularFloatField(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedFloatField(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularFloatField(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedFloatField(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedFloatField(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Double +/// +public struct ProtobufDouble: FieldType, MapValueType { + public typealias BaseType = Double + public static var proto3DefaultValue: Double {return 0.0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularDoubleField(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedDoubleField(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularDoubleField(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedDoubleField(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedDoubleField(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Int32 +/// +public struct ProtobufInt32: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int32 + public static var proto3DefaultValue: Int32 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularInt32Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedInt32Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedInt32Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Int64 +/// + +public struct ProtobufInt64: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int64 + public static var proto3DefaultValue: Int64 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularInt64Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedInt64Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedInt64Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// UInt32 +/// +public struct ProtobufUInt32: FieldType, MapKeyType, MapValueType { + public typealias BaseType = UInt32 + public static var proto3DefaultValue: UInt32 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularUInt32Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedUInt32Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// UInt64 +/// + +public struct ProtobufUInt64: FieldType, MapKeyType, MapValueType { + public typealias BaseType = UInt64 + public static var proto3DefaultValue: UInt64 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularUInt64Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedUInt64Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// SInt32 +/// +public struct ProtobufSInt32: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int32 + public static var proto3DefaultValue: Int32 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularSInt32Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedSInt32Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularSInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedSInt32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedSInt32Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// SInt64 +/// + +public struct ProtobufSInt64: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int64 + public static var proto3DefaultValue: Int64 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularSInt64Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedSInt64Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularSInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedSInt64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedSInt64Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Fixed32 +/// +public struct ProtobufFixed32: FieldType, MapKeyType, MapValueType { + public typealias BaseType = UInt32 + public static var proto3DefaultValue: UInt32 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularFixed32Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedFixed32Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularFixed32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedFixed32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedFixed32Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Fixed64 +/// +public struct ProtobufFixed64: FieldType, MapKeyType, MapValueType { + public typealias BaseType = UInt64 + public static var proto3DefaultValue: UInt64 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularFixed64Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedFixed64Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularFixed64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedFixed64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedFixed64Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// SFixed32 +/// +public struct ProtobufSFixed32: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int32 + public static var proto3DefaultValue: Int32 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularSFixed32Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedSFixed32Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularSFixed32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedSFixed32Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedSFixed32Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// SFixed64 +/// +public struct ProtobufSFixed64: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Int64 + public static var proto3DefaultValue: Int64 {return 0} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularSFixed64Field(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedSFixed64Field(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularSFixed64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedSFixed64Field(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedSFixed64Field(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// Bool +/// +public struct ProtobufBool: FieldType, MapKeyType, MapValueType { + public typealias BaseType = Bool + public static var proto3DefaultValue: Bool {return false} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularBoolField(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedBoolField(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularBoolField(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedBoolField(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitPackedBoolField(value: value, fieldNumber: fieldNumber) + } +} + +/// +/// String +/// +public struct ProtobufString: FieldType, MapKeyType, MapValueType { + public typealias BaseType = String + public static var proto3DefaultValue: String {return String()} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularStringField(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedStringField(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularStringField(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedStringField(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + assert(false) + } +} + +/// +/// Bytes +/// +public struct ProtobufBytes: FieldType, MapValueType { + public typealias BaseType = Data + public static var proto3DefaultValue: Data {return Internal.emptyData} + public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { + try decoder.decodeSingularBytesField(value: &value) + } + public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { + try decoder.decodeRepeatedBytesField(value: &value) + } + public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitSingularBytesField(value: value, fieldNumber: fieldNumber) + } + public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + try visitor.visitRepeatedBytesField(value: value, fieldNumber: fieldNumber) + } + public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { + assert(false) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift new file mode 100644 index 0000000..d607744 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift @@ -0,0 +1,145 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift - Well-known Any type +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extends the `Google_Protobuf_Any` type with various custom behaviors. +/// +// ----------------------------------------------------------------------------- + +// Explicit import of Foundation is necessary on Linux, +// don't remove unless obsolete on all platforms +import Foundation + +public let defaultAnyTypeURLPrefix: String = "type.googleapis.com" + +extension Google_Protobuf_Any { + /// Initialize an Any object from the provided message. + /// + /// This corresponds to the `pack` operation in the C++ API. + /// + /// Unlike the C++ implementation, the message is not immediately + /// serialized; it is merely stored until the Any object itself + /// needs to be serialized. This design avoids unnecessary + /// decoding/recoding when writing JSON format. + /// + /// - Parameters: + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - typePrefix: The prefix to be used when building the `type_url`. + /// Defaults to "type.googleapis.com". + /// - Throws: `BinaryEncodingError.missingRequiredFields` if `partial` is + /// false and `message` wasn't fully initialized. + public init( + message: Message, + partial: Bool = false, + typePrefix: String = defaultAnyTypeURLPrefix + ) throws { + if !partial && !message.isInitialized { + throw BinaryEncodingError.missingRequiredFields + } + self.init() + typeURL = buildTypeURL(forMessage:message, typePrefix: typePrefix) + _storage.state = .message(message) + } + + /// Creates a new `Google_Protobuf_Any` by decoding the given string + /// containing a serialized message in Protocol Buffer text format. + /// + /// - Parameters: + /// - textFormatString: The text format string to decode. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - Throws: an instance of `TextFormatDecodingError` on failure. + public init( + textFormatString: String, + extensions: ExtensionMap? = nil + ) throws { + self.init() + if !textFormatString.isEmpty { + if let data = textFormatString.data(using: String.Encoding.utf8) { + try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + + var textDecoder = try TextFormatDecoder( + messageType: Google_Protobuf_Any.self, + utf8Pointer: bytes, + count: body.count, + extensions: extensions) + try decodeTextFormat(decoder: &textDecoder) + if !textDecoder.complete { + throw TextFormatDecodingError.trailingGarbage + } + } + } + } + } + } + + /// Returns true if this `Google_Protobuf_Any` message contains the given + /// message type. + /// + /// The check is performed by looking at the passed `Message.Type` and the + /// `typeURL` of this message. + /// + /// - Parameter type: The concrete message type. + /// - Returns: True if the receiver contains the given message type. + public func isA(_ type: M.Type) -> Bool { + return _storage.isA(type) + } + +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + _storage.hash(into: &hasher) + } +#else // swift(>=4.2) + public var hashValue: Int { + return _storage.hashValue + } +#endif // swift(>=4.2) +} + +extension Google_Protobuf_Any { + internal func textTraverse(visitor: inout TextFormatEncodingVisitor) { + _storage.textTraverse(visitor: &visitor) + try! unknownFields.traverse(visitor: &visitor) + } +} + +extension Google_Protobuf_Any: _CustomJSONCodable { + // Custom text format decoding support for Any objects. + // (Note: This is not a part of any protocol; it's invoked + // directly from TextFormatDecoder whenever it sees an attempt + // to decode an Any object) + internal mutating func decodeTextFormat( + decoder: inout TextFormatDecoder + ) throws { + // First, check if this uses the "verbose" Any encoding. + // If it does, and we have the type available, we can + // eagerly decode the contained Message object. + if let url = try decoder.scanner.nextOptionalAnyURL() { + try _uniqueStorage().decodeTextFormat(typeURL: url, decoder: &decoder) + } else { + // This is not using the specialized encoding, so we can use the + // standard path to decode the binary value. + try decodeMessage(decoder: &decoder) + } + } + + internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { + return try _storage.encodedJSONString(options: options) + } + + internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + try _uniqueStorage().decodeJSON(from: &decoder) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift new file mode 100644 index 0000000..1e241d3 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift @@ -0,0 +1,135 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift - Registry for JSON support +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Support for registering and looking up Message types. Used +/// in support of Google_Protobuf_Any. +/// +// ----------------------------------------------------------------------------- + +import Foundation +import Dispatch + +// TODO: Should these first four be exposed as methods to go with +// the general registry support? + +internal func buildTypeURL(forMessage message: Message, typePrefix: String) -> String { + var url = typePrefix + let needsSlash = typePrefix.isEmpty || typePrefix.last != "/" + if needsSlash { + url += "/" + } + return url + typeName(fromMessage: message) +} + +internal func typeName(fromMessage message: Message) -> String { + let messageType = type(of: message) + return messageType.protoMessageName +} + +internal func typeName(fromURL s: String) -> String { + var typeStart = s.startIndex + var i = typeStart + while i < s.endIndex { + let c = s[i] + i = s.index(after: i) + if c == "/" { + typeStart = i + } + } + + return String(s[typeStart.. Bool { + let messageTypeName = messageType.protoMessageName + var result: Bool = false + serialQueue.sync { + if let alreadyRegistered = knownTypes[messageTypeName] { + // Success/failure when something was already registered is + // based on if they are registering the same class or trying + // to register a different type + result = alreadyRegistered == messageType + } else { + knownTypes[messageTypeName] = messageType + result = true + } + } + return result + } + + /// Returns the Message.Type expected for the given type URL. + public static func messageType(forTypeURL url: String) -> Message.Type? { + let messageTypeName = typeName(fromURL: url) + return messageType(forMessageName: messageTypeName) + } + + /// Returns the Message.Type expected for the given proto message name. + public static func messageType(forMessageName name: String) -> Message.Type? { + var result: Message.Type? + serialQueue.sync { + result = knownTypes[name] + } + return result + } + +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift new file mode 100644 index 0000000..c8b5175 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift @@ -0,0 +1,234 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift - Extensions for Duration type +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extends the generated Duration struct with various custom behaviors: +/// * JSON coding and decoding +/// * Arithmetic operations +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let minDurationSeconds: Int64 = -maxDurationSeconds +private let maxDurationSeconds: Int64 = 315576000000 + +private func parseDuration(text: String) throws -> (Int64, Int32) { + var digits = [Character]() + var digitCount = 0 + var total = 0 + var chars = text.makeIterator() + var seconds: Int64? + var nanos: Int32 = 0 + while let c = chars.next() { + switch c { + case "-": + // Only accept '-' as very first character + if total > 0 { + throw JSONDecodingError.malformedDuration + } + digits.append(c) + case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": + digits.append(c) + digitCount += 1 + case ".": + if let _ = seconds { + throw JSONDecodingError.malformedDuration + } + let digitString = String(digits) + if let s = Int64(digitString), + s >= minDurationSeconds && s <= maxDurationSeconds { + seconds = s + } else { + throw JSONDecodingError.malformedDuration + } + digits.removeAll() + digitCount = 0 + case "s": + if let seconds = seconds { + // Seconds already set, digits holds nanos + while (digitCount < 9) { + digits.append(Character("0")) + digitCount += 1 + } + while digitCount > 9 { + digits.removeLast() + digitCount -= 1 + } + let digitString = String(digits) + if let rawNanos = Int32(digitString) { + if seconds < 0 { + nanos = -rawNanos + } else { + nanos = rawNanos + } + } else { + throw JSONDecodingError.malformedDuration + } + } else { + // No fraction, we just have an integral number of seconds + let digitString = String(digits) + if let s = Int64(digitString), + s >= minDurationSeconds && s <= maxDurationSeconds { + seconds = s + } else { + throw JSONDecodingError.malformedDuration + } + } + // Fail if there are characters after 's' + if chars.next() != nil { + throw JSONDecodingError.malformedDuration + } + return (seconds!, nanos) + default: + throw JSONDecodingError.malformedDuration + } + total += 1 + } + throw JSONDecodingError.malformedDuration +} + +private func formatDuration(seconds: Int64, nanos: Int32) -> String? { + let (seconds, nanos) = normalizeForDuration(seconds: seconds, nanos: nanos) + guard seconds >= minDurationSeconds && seconds <= maxDurationSeconds else { + return nil + } + + if nanos == 0 { + return String(format: "%llds", seconds) + } else if nanos % 1000000 == 0 { + return String(format: "%lld.%03ds", seconds, abs(nanos) / 1000000) + } else if nanos % 1000 == 0 { + return String(format: "%lld.%06ds", seconds, abs(nanos) / 1000) + } else { + return String(format: "%lld.%09ds", seconds, abs(nanos)) + } +} + +extension Google_Protobuf_Duration { + /// Creates a new `Google_Protobuf_Duration` equal to the given number of + /// seconds and nanoseconds. + /// + /// - Parameter seconds: The number of seconds. + /// - Parameter nanos: The number of nanoseconds. + public init(seconds: Int64 = 0, nanos: Int32 = 0) { + self.init() + self.seconds = seconds + self.nanos = nanos + } +} + +extension Google_Protobuf_Duration: _CustomJSONCodable { + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + let s = try decoder.scanner.nextQuotedString() + (seconds, nanos) = try parseDuration(text: s) + } + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + if let formatted = formatDuration(seconds: seconds, nanos: nanos) { + return "\"\(formatted)\"" + } else { + throw JSONEncodingError.durationRange + } + } +} + +extension Google_Protobuf_Duration: ExpressibleByFloatLiteral { + public typealias FloatLiteralType = Double + + /// Creates a new `Google_Protobuf_Duration` from a floating point literal + /// that is interpreted as a duration in seconds, rounded to the nearest + /// nanosecond. + public init(floatLiteral value: Double) { + let sd = trunc(value) + let nd = round((value - sd) * TimeInterval(nanosPerSecond)) + let (s, n) = normalizeForDuration(seconds: Int64(sd), nanos: Int32(nd)) + self.init(seconds: s, nanos: n) + } +} + +extension Google_Protobuf_Duration { + /// Creates a new `Google_Protobuf_Duration` that is equal to the given + /// `TimeInterval` (measured in seconds), rounded to the nearest nanosecond. + /// + /// - Parameter timeInterval: The `TimeInterval`. + public init(timeInterval: TimeInterval) { + let sd = trunc(timeInterval) + let nd = round((timeInterval - sd) * TimeInterval(nanosPerSecond)) + let (s, n) = normalizeForDuration(seconds: Int64(sd), nanos: Int32(nd)) + self.init(seconds: s, nanos: n) + } + + /// The `TimeInterval` (measured in seconds) equal to this duration. + public var timeInterval: TimeInterval { + return TimeInterval(self.seconds) + + TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) + } +} + +private func normalizeForDuration( + seconds: Int64, + nanos: Int32 +) -> (seconds: Int64, nanos: Int32) { + var s = seconds + var n = nanos + + // If the magnitude of n exceeds a second then + // we need to factor it into s instead. + if n >= nanosPerSecond || n <= -nanosPerSecond { + s += Int64(n / nanosPerSecond) + n = n % nanosPerSecond + } + + // The Duration spec says that when s != 0, s and + // n must have the same sign. + if s > 0 && n < 0 { + n += nanosPerSecond + s -= 1 + } else if s < 0 && n > 0 { + n -= nanosPerSecond + s += 1 + } + + return (seconds: s, nanos: n) +} + +public prefix func - ( + operand: Google_Protobuf_Duration +) -> Google_Protobuf_Duration { + let (s, n) = normalizeForDuration(seconds: -operand.seconds, + nanos: -operand.nanos) + return Google_Protobuf_Duration(seconds: s, nanos: n) +} + +public func + ( + lhs: Google_Protobuf_Duration, + rhs: Google_Protobuf_Duration +) -> Google_Protobuf_Duration { + let (s, n) = normalizeForDuration(seconds: lhs.seconds + rhs.seconds, + nanos: lhs.nanos + rhs.nanos) + return Google_Protobuf_Duration(seconds: s, nanos: n) +} + +public func - ( + lhs: Google_Protobuf_Duration, + rhs: Google_Protobuf_Duration +) -> Google_Protobuf_Duration { + let (s, n) = normalizeForDuration(seconds: lhs.seconds - rhs.seconds, + nanos: lhs.nanos - rhs.nanos) + return Google_Protobuf_Duration(seconds: s, nanos: n) +} + +public func - ( + lhs: Google_Protobuf_Timestamp, + rhs: Google_Protobuf_Timestamp +) -> Google_Protobuf_Duration { + let (s, n) = normalizeForDuration(seconds: lhs.seconds - rhs.seconds, + nanos: lhs.nanos - rhs.nanos) + return Google_Protobuf_Duration(seconds: s, nanos: n) +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift new file mode 100644 index 0000000..6720c94 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift @@ -0,0 +1,163 @@ +// Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift - Fieldmask extensions +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extend the generated FieldMask message with customized JSON coding and +/// convenience methods. +/// +// ----------------------------------------------------------------------------- + +// TODO: We should have utilities to apply a fieldmask to an arbitrary +// message, intersect two fieldmasks, etc. + +private func ProtoToJSON(name: String) -> String? { + var jsonPath = String() + var chars = name.makeIterator() + while let c = chars.next() { + switch c { + case "_": + if let toupper = chars.next() { + switch toupper { + case "a"..."z": + jsonPath.append(String(toupper).uppercased()) + default: + return nil + } + } else { + return nil + } + case "A"..."Z": + return nil + default: + jsonPath.append(c) + } + } + return jsonPath +} + +private func JSONToProto(name: String) -> String? { + var path = String() + for c in name { + switch c { + case "_": + return nil + case "A"..."Z": + path.append(Character("_")) + path.append(String(c).lowercased()) + default: + path.append(c) + } + } + return path +} + +private func parseJSONFieldNames(names: String) -> [String]? { + // An empty field mask is the empty string (no paths). + guard !names.isEmpty else { return [] } + var fieldNameCount = 0 + var fieldName = String() + var split = [String]() + for c in names { + switch c { + case ",": + if fieldNameCount == 0 { + return nil + } + if let pbName = JSONToProto(name: fieldName) { + split.append(pbName) + } else { + return nil + } + fieldName = String() + fieldNameCount = 0 + default: + fieldName.append(c) + fieldNameCount += 1 + } + } + if fieldNameCount == 0 { // Last field name can't be empty + return nil + } + if let pbName = JSONToProto(name: fieldName) { + split.append(pbName) + } else { + return nil + } + return split +} + +extension Google_Protobuf_FieldMask { + /// Creates a new `Google_Protobuf_FieldMask` from the given array of paths. + /// + /// The paths should match the names used in the .proto file, which may be + /// different than the corresponding Swift property names. + /// + /// - Parameter protoPaths: The paths from which to create the field mask, + /// defined using the .proto names for the fields. + public init(protoPaths: [String]) { + self.init() + paths = protoPaths + } + + /// Creates a new `Google_Protobuf_FieldMask` from the given paths. + /// + /// The paths should match the names used in the .proto file, which may be + /// different than the corresponding Swift property names. + /// + /// - Parameter protoPaths: The paths from which to create the field mask, + /// defined using the .proto names for the fields. + public init(protoPaths: String...) { + self.init(protoPaths: protoPaths) + } + + /// Creates a new `Google_Protobuf_FieldMask` from the given paths. + /// + /// The paths should match the JSON names of the fields, which may be + /// different than the corresponding Swift property names. + /// + /// - Parameter jsonPaths: The paths from which to create the field mask, + /// defined using the JSON names for the fields. + public init?(jsonPaths: String...) { + // TODO: This should fail if any of the conversions from JSON fails + #if swift(>=4.1) + self.init(protoPaths: jsonPaths.compactMap(JSONToProto)) + #else + self.init(protoPaths: jsonPaths.flatMap(JSONToProto)) + #endif + } + + // It would be nice if to have an initializer that accepted Swift property + // names, but translating between swift and protobuf/json property + // names is not entirely deterministic. +} + +extension Google_Protobuf_FieldMask: _CustomJSONCodable { + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + let s = try decoder.scanner.nextQuotedString() + if let names = parseJSONFieldNames(names: s) { + paths = names + } else { + throw JSONDecodingError.malformedFieldMask + } + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + // Note: Proto requires alphanumeric field names, so there + // cannot be a ',' or '"' character to mess up this formatting. + var jsonPaths = [String]() + for p in paths { + if let jsonPath = ProtoToJSON(name: p) { + jsonPaths.append(jsonPath) + } else { + throw JSONEncodingError.fieldMaskConversion + } + } + return "\"" + jsonPaths.joined(separator: ",") + "\"" + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift new file mode 100644 index 0000000..453ea0d --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift @@ -0,0 +1,80 @@ +// Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift - ListValue extensions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// ListValue is a well-known message type that can be used to parse or encode +/// arbitrary JSON arrays without a predefined schema. +/// +// ----------------------------------------------------------------------------- + +extension Google_Protobuf_ListValue: ExpressibleByArrayLiteral { + // TODO: Give this a direct array interface by proxying the interesting + // bits down to values + public typealias Element = Google_Protobuf_Value + + /// Creates a new `Google_Protobuf_ListValue` from an array literal containing + /// `Google_Protobuf_Value` elements. + public init(arrayLiteral elements: Element...) { + self.init(values: elements) + } +} + +extension Google_Protobuf_ListValue: _CustomJSONCodable { + internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var jsonEncoder = JSONEncoder() + jsonEncoder.append(text: "[") + var separator: StaticString = "" + for v in values { + jsonEncoder.append(staticText: separator) + try v.serializeJSONValue(to: &jsonEncoder, options: options) + separator = "," + } + jsonEncoder.append(text: "]") + return jsonEncoder.stringResult + } + + internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + if decoder.scanner.skipOptionalNull() { + return + } + try decoder.scanner.skipRequiredArrayStart() + if decoder.scanner.skipOptionalArrayEnd() { + return + } + while true { + var v = Google_Protobuf_Value() + try v.decodeJSON(from: &decoder) + values.append(v) + if decoder.scanner.skipOptionalArrayEnd() { + return + } + try decoder.scanner.skipRequiredComma() + } + } +} + +extension Google_Protobuf_ListValue { + /// Creates a new `Google_Protobuf_ListValue` from the given array of + /// `Google_Protobuf_Value` elements. + /// + /// - Parameter values: The list of `Google_Protobuf_Value` messages from + /// which to create the `Google_Protobuf_ListValue`. + public init(values: [Google_Protobuf_Value]) { + self.init() + self.values = values + } + + /// Accesses the `Google_Protobuf_Value` at the specified position. + /// + /// - Parameter index: The position of the element to access. + public subscript(index: Int) -> Google_Protobuf_Value { + get {return values[index]} + set(newValue) {values[index] = newValue} + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift new file mode 100644 index 0000000..1a7c31c --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift @@ -0,0 +1,85 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift - Struct extensions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Struct is a well-known message type that can be used to parse or encode +/// arbitrary JSON objects without a predefined schema. +/// +// ----------------------------------------------------------------------------- + +extension Google_Protobuf_Struct: ExpressibleByDictionaryLiteral { + public typealias Key = String + public typealias Value = Google_Protobuf_Value + + /// Creates a new `Google_Protobuf_Struct` from a dictionary of string keys to + /// values of type `Google_Protobuf_Value`. + public init(dictionaryLiteral: (String, Google_Protobuf_Value)...) { + self.init() + for (k,v) in dictionaryLiteral { + fields[k] = v + } + } +} + +extension Google_Protobuf_Struct: _CustomJSONCodable { + internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var jsonEncoder = JSONEncoder() + jsonEncoder.startObject() + var mapVisitor = JSONMapEncodingVisitor(encoder: jsonEncoder, options: options) + for (k,v) in fields { + try mapVisitor.visitSingularStringField(value: k, fieldNumber: 1) + try mapVisitor.visitSingularMessageField(value: v, fieldNumber: 2) + } + mapVisitor.encoder.endObject() + return mapVisitor.encoder.stringResult + } + + internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + try decoder.scanner.skipRequiredObjectStart() + if decoder.scanner.skipOptionalObjectEnd() { + return + } + while true { + let key = try decoder.scanner.nextQuotedString() + try decoder.scanner.skipRequiredColon() + var value = Google_Protobuf_Value() + try value.decodeJSON(from: &decoder) + fields[key] = value + if decoder.scanner.skipOptionalObjectEnd() { + return + } + try decoder.scanner.skipRequiredComma() + } + } +} + +extension Google_Protobuf_Struct { + /// Creates a new `Google_Protobuf_Struct` from a dictionary of string keys to + /// values of type `Google_Protobuf_Value`. + /// + /// - Parameter fields: The dictionary from field names to + /// `Google_Protobuf_Value` messages that should be used to create the + /// `Struct`. + public init(fields: [String: Google_Protobuf_Value]) { + self.init() + self.fields = fields + } + + /// Accesses the `Google_Protobuf_Value` with the given key for reading and + /// writing. + /// + /// This key-based subscript returns the `Value` for the given key if the key + /// is found in the `Struct`, or nil if the key is not found. If you assign + /// nil as the `Value` for the given key, the `Struct` removes that key and + /// its associated `Value`. + public subscript(key: String) -> Google_Protobuf_Value? { + get {return fields[key]} + set(newValue) {fields[key] = newValue} + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift new file mode 100644 index 0000000..11735f6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift @@ -0,0 +1,337 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift - Timestamp extensions +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extend the generated Timestamp message with customized JSON coding, +/// arithmetic operations, and convenience methods. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let minTimestampSeconds: Int64 = -62135596800 // 0001-01-01T00:00:00Z +private let maxTimestampSeconds: Int64 = 253402300799 // 9999-12-31T23:59:59Z + +// TODO: Add convenience methods to interoperate with standard +// date/time classes: an initializer that accepts Unix timestamp as +// Int or Double, an easy way to convert to/from Foundation's +// NSDateTime (on Apple platforms only?), others? + + +// Parse an RFC3339 timestamp into a pair of seconds-since-1970 and nanos. +private func parseTimestamp(s: String) throws -> (Int64, Int32) { + // Convert to an array of integer character values + let value = s.utf8.map{Int($0)} + if value.count < 20 { + throw JSONDecodingError.malformedTimestamp + } + // Since the format is fixed-layout, we can just decode + // directly as follows. + let zero = Int(48) + let nine = Int(57) + let dash = Int(45) + let colon = Int(58) + let plus = Int(43) + let letterT = Int(84) + let letterZ = Int(90) + let period = Int(46) + + func fromAscii2(_ digit0: Int, _ digit1: Int) throws -> Int { + if digit0 < zero || digit0 > nine || digit1 < zero || digit1 > nine { + throw JSONDecodingError.malformedTimestamp + } + return digit0 * 10 + digit1 - 528 + } + + func fromAscii4( + _ digit0: Int, + _ digit1: Int, + _ digit2: Int, + _ digit3: Int + ) throws -> Int { + if (digit0 < zero || digit0 > nine + || digit1 < zero || digit1 > nine + || digit2 < zero || digit2 > nine + || digit3 < zero || digit3 > nine) { + throw JSONDecodingError.malformedTimestamp + } + return digit0 * 1000 + digit1 * 100 + digit2 * 10 + digit3 - 53328 + } + + // Year: 4 digits followed by '-' + let year = try fromAscii4(value[0], value[1], value[2], value[3]) + if value[4] != dash || year < Int(1) || year > Int(9999) { + throw JSONDecodingError.malformedTimestamp + } + + // Month: 2 digits followed by '-' + let month = try fromAscii2(value[5], value[6]) + if value[7] != dash || month < Int(1) || month > Int(12) { + throw JSONDecodingError.malformedTimestamp + } + + // Day: 2 digits followed by 'T' + let mday = try fromAscii2(value[8], value[9]) + if value[10] != letterT || mday < Int(1) || mday > Int(31) { + throw JSONDecodingError.malformedTimestamp + } + + // Hour: 2 digits followed by ':' + let hour = try fromAscii2(value[11], value[12]) + if value[13] != colon || hour > Int(23) { + throw JSONDecodingError.malformedTimestamp + } + + // Minute: 2 digits followed by ':' + let minute = try fromAscii2(value[14], value[15]) + if value[16] != colon || minute > Int(59) { + throw JSONDecodingError.malformedTimestamp + } + + // Second: 2 digits (following char is checked below) + let second = try fromAscii2(value[17], value[18]) + if second > Int(61) { + throw JSONDecodingError.malformedTimestamp + } + + // timegm() is almost entirely useless. It's nonexistent on + // some platforms, broken on others. Everything else I've tried + // is even worse. Hence the code below. + // (If you have a better way to do this, try it and see if it + // passes the test suite on both Linux and OS X.) + + // Day of year + let mdayStart: [Int] = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] + var yday = Int64(mdayStart[month - 1]) + let isleap = (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)) + if isleap && (month > 2) { + yday += 1 + } + yday += Int64(mday - 1) + + // Days since start of epoch (including leap days) + var daysSinceEpoch = yday + daysSinceEpoch += Int64(365 * year) - Int64(719527) + daysSinceEpoch += Int64((year - 1) / 4) + daysSinceEpoch -= Int64((year - 1) / 100) + daysSinceEpoch += Int64((year - 1) / 400) + + // Second within day + var daySec = Int64(hour) + daySec *= 60 + daySec += Int64(minute) + daySec *= 60 + daySec += Int64(second) + + // Seconds since start of epoch + let t = daysSinceEpoch * Int64(86400) + daySec + + // After seconds, comes various optional bits + var pos = 19 + + var nanos: Int32 = 0 + if value[pos] == period { // "." begins fractional seconds + pos += 1 + var digitValue = 100000000 + while pos < value.count && value[pos] >= zero && value[pos] <= nine { + nanos += Int32(digitValue * (value[pos] - zero)) + digitValue /= 10 + pos += 1 + } + } + + var seconds: Int64 = 0 + // "+" or "-" starts Timezone offset + if value[pos] == plus || value[pos] == dash { + if pos + 6 > value.count { + throw JSONDecodingError.malformedTimestamp + } + let hourOffset = try fromAscii2(value[pos + 1], value[pos + 2]) + let minuteOffset = try fromAscii2(value[pos + 4], value[pos + 5]) + if hourOffset > Int(13) || minuteOffset > Int(59) || value[pos + 3] != colon { + throw JSONDecodingError.malformedTimestamp + } + var adjusted: Int64 = t + if value[pos] == plus { + adjusted -= Int64(hourOffset) * Int64(3600) + adjusted -= Int64(minuteOffset) * Int64(60) + } else { + adjusted += Int64(hourOffset) * Int64(3600) + adjusted += Int64(minuteOffset) * Int64(60) + } + if adjusted < minTimestampSeconds || adjusted > maxTimestampSeconds { + throw JSONDecodingError.malformedTimestamp + } + seconds = adjusted + pos += 6 + } else if value[pos] == letterZ { // "Z" indicator for UTC + seconds = t + pos += 1 + } else { + throw JSONDecodingError.malformedTimestamp + } + if pos != value.count { + throw JSONDecodingError.malformedTimestamp + } + return (seconds, nanos) +} + +private func formatTimestamp(seconds: Int64, nanos: Int32) -> String? { + let (seconds, nanos) = normalizeForTimestamp(seconds: seconds, nanos: nanos) + guard seconds >= minTimestampSeconds && seconds <= maxTimestampSeconds else { + return nil + } + + let (hh, mm, ss) = timeOfDayFromSecondsSince1970(seconds: seconds) + let (YY, MM, DD) = gregorianDateFromSecondsSince1970(seconds: seconds) + + if nanos == 0 { + return String(format: "%04d-%02d-%02dT%02d:%02d:%02dZ", + YY, MM, DD, hh, mm, ss) + } else if nanos % 1000000 == 0 { + return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", + YY, MM, DD, hh, mm, ss, nanos / 1000000) + } else if nanos % 1000 == 0 { + return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ", + YY, MM, DD, hh, mm, ss, nanos / 1000) + } else { + return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%09dZ", + YY, MM, DD, hh, mm, ss, nanos) + } +} + +extension Google_Protobuf_Timestamp { + /// Creates a new `Google_Protobuf_Timestamp` equal to the given number of + /// seconds and nanoseconds. + /// + /// - Parameter seconds: The number of seconds. + /// - Parameter nanos: The number of nanoseconds. + public init(seconds: Int64 = 0, nanos: Int32 = 0) { + self.init() + self.seconds = seconds + self.nanos = nanos + } +} + +extension Google_Protobuf_Timestamp: _CustomJSONCodable { + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + let s = try decoder.scanner.nextQuotedString() + (seconds, nanos) = try parseTimestamp(s: s) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + if let formatted = formatTimestamp(seconds: seconds, nanos: nanos) { + return "\"\(formatted)\"" + } else { + throw JSONEncodingError.timestampRange + } + } +} + +extension Google_Protobuf_Timestamp { + /// Creates a new `Google_Protobuf_Timestamp` initialized relative to 00:00:00 + /// UTC on 1 January 1970 by a given number of seconds. + /// + /// - Parameter timeIntervalSince1970: The `TimeInterval`, interpreted as + /// seconds relative to 00:00:00 UTC on 1 January 1970. + public init(timeIntervalSince1970: TimeInterval) { + let sd = floor(timeIntervalSince1970) + let nd = round((timeIntervalSince1970 - sd) * TimeInterval(nanosPerSecond)) + let (s, n) = normalizeForTimestamp(seconds: Int64(sd), nanos: Int32(nd)) + self.init(seconds: s, nanos: n) + } + + /// Creates a new `Google_Protobuf_Timestamp` initialized relative to 00:00:00 + /// UTC on 1 January 2001 by a given number of seconds. + /// + /// - Parameter timeIntervalSinceReferenceDate: The `TimeInterval`, + /// interpreted as seconds relative to 00:00:00 UTC on 1 January 2001. + public init(timeIntervalSinceReferenceDate: TimeInterval) { + let sd = floor(timeIntervalSinceReferenceDate) + let nd = round( + (timeIntervalSinceReferenceDate - sd) * TimeInterval(nanosPerSecond)) + // The addition of timeIntervalBetween1970And... is deliberately delayed + // until the input is separated into an integer part and a fraction + // part, so that we don't unnecessarily lose precision. + let (s, n) = normalizeForTimestamp( + seconds: Int64(sd) + Int64(Date.timeIntervalBetween1970AndReferenceDate), + nanos: Int32(nd)) + self.init(seconds: s, nanos: n) + } + + /// Creates a new `Google_Protobuf_Timestamp` initialized to the same time as + /// the given `Date`. + /// + /// - Parameter date: The `Date` with which to initialize the timestamp. + public init(date: Date) { + // Note: Internally, Date uses the "reference date," not the 1970 date. + // We use it when interacting with Dates so that Date doesn't perform + // any double arithmetic on our behalf, which might cost us precision. + self.init( + timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate) + } + + /// The interval between the timestamp and 00:00:00 UTC on 1 January 1970. + public var timeIntervalSince1970: TimeInterval { + return TimeInterval(self.seconds) + + TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) + } + + /// The interval between the timestamp and 00:00:00 UTC on 1 January 2001. + public var timeIntervalSinceReferenceDate: TimeInterval { + return TimeInterval( + self.seconds - Int64(Date.timeIntervalBetween1970AndReferenceDate)) + + TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) + } + + /// A `Date` initialized to the same time as the timestamp. + public var date: Date { + return Date( + timeIntervalSinceReferenceDate: self.timeIntervalSinceReferenceDate) + } +} + +private func normalizeForTimestamp( + seconds: Int64, + nanos: Int32 +) -> (seconds: Int64, nanos: Int32) { + // The Timestamp spec says that nanos must be in the range [0, 999999999), + // as in actual modular arithmetic. + + let s = seconds + Int64(div(nanos, nanosPerSecond)) + let n = mod(nanos, nanosPerSecond) + return (seconds: s, nanos: n) +} + +public func + ( + lhs: Google_Protobuf_Timestamp, + rhs: Google_Protobuf_Duration +) -> Google_Protobuf_Timestamp { + let (s, n) = normalizeForTimestamp(seconds: lhs.seconds + rhs.seconds, + nanos: lhs.nanos + rhs.nanos) + return Google_Protobuf_Timestamp(seconds: s, nanos: n) +} + +public func + ( + lhs: Google_Protobuf_Duration, + rhs: Google_Protobuf_Timestamp +) -> Google_Protobuf_Timestamp { + let (s, n) = normalizeForTimestamp(seconds: lhs.seconds + rhs.seconds, + nanos: lhs.nanos + rhs.nanos) + return Google_Protobuf_Timestamp(seconds: s, nanos: n) +} + +public func - ( + lhs: Google_Protobuf_Timestamp, + rhs: Google_Protobuf_Duration +) -> Google_Protobuf_Timestamp { + let (s, n) = normalizeForTimestamp(seconds: lhs.seconds - rhs.seconds, + nanos: lhs.nanos - rhs.nanos) + return Google_Protobuf_Timestamp(seconds: s, nanos: n) +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift new file mode 100644 index 0000000..9d4c7d7 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift @@ -0,0 +1,163 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift - Value extensions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Value is a well-known message type that can be used to parse or encode +/// arbitrary JSON without a predefined schema. +/// +// ----------------------------------------------------------------------------- + +extension Google_Protobuf_Value: ExpressibleByIntegerLiteral { + public typealias IntegerLiteralType = Int64 + + /// Creates a new `Google_Protobuf_Value` from an integer literal. + public init(integerLiteral value: Int64) { + self.init(kind: .numberValue(Double(value))) + } +} + +extension Google_Protobuf_Value: ExpressibleByFloatLiteral { + public typealias FloatLiteralType = Double + + /// Creates a new `Google_Protobuf_Value` from a floating point literal. + public init(floatLiteral value: Double) { + self.init(kind: .numberValue(value)) + } +} + +extension Google_Protobuf_Value: ExpressibleByBooleanLiteral { + public typealias BooleanLiteralType = Bool + + /// Creates a new `Google_Protobuf_Value` from a boolean literal. + public init(booleanLiteral value: Bool) { + self.init(kind: .boolValue(value)) + } +} + +extension Google_Protobuf_Value: ExpressibleByStringLiteral { + public typealias StringLiteralType = String + public typealias ExtendedGraphemeClusterLiteralType = String + public typealias UnicodeScalarLiteralType = String + + /// Creates a new `Google_Protobuf_Value` from a string literal. + public init(stringLiteral value: String) { + self.init(kind: .stringValue(value)) + } + + /// Creates a new `Google_Protobuf_Value` from a Unicode scalar literal. + public init(unicodeScalarLiteral value: String) { + self.init(kind: .stringValue(value)) + } + + /// Creates a new `Google_Protobuf_Value` from a character literal. + public init(extendedGraphemeClusterLiteral value: String) { + self.init(kind: .stringValue(value)) + } +} + +extension Google_Protobuf_Value: ExpressibleByNilLiteral { + /// Creates a new `Google_Protobuf_Value` from the nil literal. + public init(nilLiteral: ()) { + self.init(kind: .nullValue(.nullValue)) + } +} + +extension Google_Protobuf_Value: _CustomJSONCodable { + internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var jsonEncoder = JSONEncoder() + try serializeJSONValue(to: &jsonEncoder, options: options) + return jsonEncoder.stringResult + } + + internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + let c = try decoder.scanner.peekOneCharacter() + switch c { + case "n": + if !decoder.scanner.skipOptionalNull() { + throw JSONDecodingError.failure + } + kind = .nullValue(.nullValue) + case "[": + var l = Google_Protobuf_ListValue() + try l.decodeJSON(from: &decoder) + kind = .listValue(l) + case "{": + var s = Google_Protobuf_Struct() + try s.decodeJSON(from: &decoder) + kind = .structValue(s) + case "t", "f": + let b = try decoder.scanner.nextBool() + kind = .boolValue(b) + case "\"": + let s = try decoder.scanner.nextQuotedString() + kind = .stringValue(s) + default: + let d = try decoder.scanner.nextDouble() + kind = .numberValue(d) + } + } + + internal static func decodedFromJSONNull() -> Google_Protobuf_Value? { + return Google_Protobuf_Value(kind: .nullValue(.nullValue)) + } +} + +extension Google_Protobuf_Value { + /// Creates a new `Google_Protobuf_Value` with the given kind. + fileprivate init(kind: OneOf_Kind) { + self.init() + self.kind = kind + } + + /// Creates a new `Google_Protobuf_Value` whose `kind` is `numberValue` with + /// the given floating-point value. + public init(numberValue: Double) { + self.init(kind: .numberValue(numberValue)) + } + + /// Creates a new `Google_Protobuf_Value` whose `kind` is `stringValue` with + /// the given string value. + public init(stringValue: String) { + self.init(kind: .stringValue(stringValue)) + } + + /// Creates a new `Google_Protobuf_Value` whose `kind` is `boolValue` with the + /// given boolean value. + public init(boolValue: Bool) { + self.init(kind: .boolValue(boolValue)) + } + + /// Creates a new `Google_Protobuf_Value` whose `kind` is `structValue` with + /// the given `Google_Protobuf_Struct` value. + public init(structValue: Google_Protobuf_Struct) { + self.init(kind: .structValue(structValue)) + } + + /// Creates a new `Google_Protobuf_Value` whose `kind` is `listValue` with the + /// given `Google_Struct_ListValue` value. + public init(listValue: Google_Protobuf_ListValue) { + self.init(kind: .listValue(listValue)) + } + + /// Writes out the JSON representation of the value to the given encoder. + internal func serializeJSONValue( + to encoder: inout JSONEncoder, + options: JSONEncodingOptions + ) throws { + switch kind { + case .nullValue?: encoder.putNullValue() + case .numberValue(let v)?: encoder.putDoubleValue(value: v) + case .stringValue(let v)?: encoder.putStringValue(value: v) + case .boolValue(let v)?: encoder.putBoolValue(value: v) + case .structValue(let v)?: encoder.append(text: try v.jsonString(options: options)) + case .listValue(let v)?: encoder.append(text: try v.jsonString(options: options)) + case nil: throw JSONEncodingError.missingValue + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift new file mode 100644 index 0000000..2860791 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift @@ -0,0 +1,283 @@ +// Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift - Well-known wrapper type extensions +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extensions to the well-known types in wrapper.proto that customize the JSON +/// format of those messages and provide convenience initializers from literals. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Internal protocol that minimizes the code duplication across the multiple +/// wrapper types extended below. +protocol ProtobufWrapper { + + /// The wrapped protobuf type (for example, `ProtobufDouble`). + associatedtype WrappedType: FieldType + + /// Exposes the generated property to the extensions here. + var value: WrappedType.BaseType { get set } + + /// Exposes the parameterless initializer to the extensions here. + init() + + /// Creates a new instance of the wrapper with the given value. + init(_ value: WrappedType.BaseType) +} + +extension Google_Protobuf_DoubleValue: + ProtobufWrapper, ExpressibleByFloatLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufDouble + public typealias FloatLiteralType = WrappedType.BaseType + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(floatLiteral: FloatLiteralType) { + self.init(floatLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putDoubleValue(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_FloatValue: + ProtobufWrapper, ExpressibleByFloatLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufFloat + public typealias FloatLiteralType = Float + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(floatLiteral: FloatLiteralType) { + self.init(floatLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putFloatValue(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_Int64Value: + ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufInt64 + public typealias IntegerLiteralType = WrappedType.BaseType + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(integerLiteral: IntegerLiteralType) { + self.init(integerLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putInt64(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_UInt64Value: + ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufUInt64 + public typealias IntegerLiteralType = WrappedType.BaseType + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(integerLiteral: IntegerLiteralType) { + self.init(integerLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putUInt64(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_Int32Value: + ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufInt32 + public typealias IntegerLiteralType = WrappedType.BaseType + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(integerLiteral: IntegerLiteralType) { + self.init(integerLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + return String(value) + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_UInt32Value: + ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufUInt32 + public typealias IntegerLiteralType = WrappedType.BaseType + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(integerLiteral: IntegerLiteralType) { + self.init(integerLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + return String(value) + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_BoolValue: + ProtobufWrapper, ExpressibleByBooleanLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufBool + public typealias BooleanLiteralType = Bool + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(booleanLiteral: Bool) { + self.init(booleanLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + return value ? "true" : "false" + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_StringValue: + ProtobufWrapper, ExpressibleByStringLiteral, _CustomJSONCodable { + + public typealias WrappedType = ProtobufString + public typealias StringLiteralType = String + public typealias ExtendedGraphemeClusterLiteralType = String + public typealias UnicodeScalarLiteralType = String + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + public init(stringLiteral: String) { + self.init(stringLiteral) + } + + public init(extendedGraphemeClusterLiteral: String) { + self.init(extendedGraphemeClusterLiteral) + } + + public init(unicodeScalarLiteral: String) { + self.init(unicodeScalarLiteral) + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putStringValue(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} + +extension Google_Protobuf_BytesValue: ProtobufWrapper, _CustomJSONCodable { + + public typealias WrappedType = ProtobufBytes + + public init(_ value: WrappedType.BaseType) { + self.init() + self.value = value + } + + func encodedJSONString(options: JSONEncodingOptions) throws -> String { + var encoder = JSONEncoder() + encoder.putBytesValue(value: value) + return encoder.stringResult + } + + mutating func decodeJSON(from decoder: inout JSONDecoder) throws { + var v: WrappedType.BaseType? + try WrappedType.decodeSingular(value: &v, from: &decoder) + value = v ?? WrappedType.proto3DefaultValue + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift new file mode 100644 index 0000000..240ade1 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift @@ -0,0 +1,408 @@ +// Sources/SwiftProtobuf/HashVisitor.swift - Hashing support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Hashing is basically a serialization problem, so we can leverage the +/// generated traversal methods for that. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let i_2166136261 = Int(bitPattern: 2166136261) +private let i_16777619 = Int(16777619) + +/// Computes the hash of a message by visiting its fields recursively. +/// +/// Note that because this visits every field, it has the potential to be slow +/// for large or deeply nested messages. Users who need to use such messages as +/// dictionary keys or set members can use a wrapper struct around the message +/// and use a custom Hashable implementation that looks at the subset of the +/// message fields they want to include. +internal struct HashVisitor: Visitor { + +#if swift(>=4.2) + internal private(set) var hasher: Hasher +#else // swift(>=4.2) + // Roughly based on FNV hash: http://tools.ietf.org/html/draft-eastlake-fnv-03 + private(set) var hashValue = i_2166136261 + + private mutating func mix(_ hash: Int) { + hashValue = (hashValue ^ hash) &* i_16777619 + } + + private mutating func mixMap(map: Dictionary) { + var mapHash = 0 + for (k, v) in map { + // Note: This calculation cannot depend on the order of the items. + mapHash = mapHash &+ (k.hashValue ^ v.hashValue) + } + mix(mapHash) + } +#endif // swift(>=4.2) + +#if swift(>=4.2) + init(_ hasher: Hasher) { + self.hasher = hasher + } +#else + init() {} +#endif + + mutating func visitUnknown(bytes: Data) throws { + #if swift(>=4.2) + hasher.combine(bytes) + #else + mix(bytes.hashValue) + #endif + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularEnumField(value: E, + fieldNumber: Int) { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitSingularMessageField(value: M, fieldNumber: Int) { + #if swift(>=4.2) + hasher.combine(fieldNumber) + value.hash(into: &hasher) + #else + mix(fieldNumber) + mix(value.hashValue) + #endif + } + + mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + for v in value { + v.hash(into: &hasher) + } + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + for v in value { + v.hash(into: &hasher) + } + #else + mix(fieldNumber) + for v in value { + mix(v.hashValue) + } + #endif + } + + mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int + ) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mixMap(map: value) + #endif + } + + mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int + ) throws where ValueType.RawValue == Int { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mixMap(map: value) + #endif + } + + mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int + ) throws { + #if swift(>=4.2) + hasher.combine(fieldNumber) + hasher.combine(value) + #else + mix(fieldNumber) + mixMap(map: value) + #endif + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift new file mode 100644 index 0000000..6402e22 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift @@ -0,0 +1,51 @@ +// Sources/SwiftProtobuf/Internal.swift - Message support +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Internal helpers on Messages for the library. These are public +/// just so the generated code can call them, but shouldn't be called +/// by developers directly. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Functions that are public only because they are used by generated message +/// implementations. NOT INTENDED TO BE CALLED BY CLIENTS. +public enum Internal { + + /// A singleton instance of an empty data that is used by the generated code + /// for default values. This is a performance enhancement to work around the + /// fact that the `Data` type in Swift involves a new heap allocation every + /// time an empty instance is initialized, instead of sharing a common empty + /// backing storage. + public static let emptyData = Data() + + /// Helper to loop over a list of Messages to see if they are all + /// initialized (see Message.isInitialized for what that means). + public static func areAllInitialized(_ listOfMessages: [Message]) -> Bool { + for msg in listOfMessages { + if !msg.isInitialized { + return false + } + } + return true + } + + /// Helper to loop over dictionary with values that are Messages to see if + /// they are all initialized (see Message.isInitialized for what that means). + public static func areAllInitialized(_ mapToMessages: [K: Message]) -> Bool { + for (_, msg) in mapToMessages { + if !msg.isInitialized { + return false + } + } + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift new file mode 100644 index 0000000..54566b2 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift @@ -0,0 +1,702 @@ +// Sources/SwiftProtobuf/JSONDecoder.swift - JSON format decoding +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON format decoding engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +internal struct JSONDecoder: Decoder { + internal var scanner: JSONScanner + internal var options: JSONDecodingOptions + private var fieldCount = 0 + private var isMapKey = false + private var fieldNameMap: _NameMap? + + mutating func handleConflictingOneOf() throws { + throw JSONDecodingError.conflictingOneOf + } + + internal init(source: UnsafeBufferPointer, options: JSONDecodingOptions) { + self.options = options + self.scanner = JSONScanner(source: source, + messageDepthLimit: self.options.messageDepthLimit, + ignoreUnknownFields: self.options.ignoreUnknownFields) + } + + private init(decoder: JSONDecoder) { + // The scanner is copied over along with the options. + scanner = decoder.scanner + options = decoder.options + } + + mutating func nextFieldNumber() throws -> Int? { + if scanner.skipOptionalObjectEnd() { + return nil + } + if fieldCount > 0 { + try scanner.skipRequiredComma() + } + if let fieldNumber = try scanner.nextFieldNumber(names: fieldNameMap!) { + fieldCount += 1 + return fieldNumber + } + return nil + } + + mutating func decodeSingularFloatField(value: inout Float) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + value = try scanner.nextFloat() + } + + mutating func decodeSingularFloatField(value: inout Float?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextFloat() + } + + mutating func decodeRepeatedFloatField(value: inout [Float]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextFloat() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularDoubleField(value: inout Double) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + value = try scanner.nextDouble() + } + + mutating func decodeSingularDoubleField(value: inout Double?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextDouble() + } + + mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextDouble() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularInt32Field(value: inout Int32) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw JSONDecodingError.numberRange + } + value = Int32(truncatingIfNeeded: n) + } + + mutating func decodeSingularInt32Field(value: inout Int32?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw JSONDecodingError.numberRange + } + value = Int32(truncatingIfNeeded: n) + } + + mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw JSONDecodingError.numberRange + } + value.append(Int32(truncatingIfNeeded: n)) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularInt64Field(value: inout Int64) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + value = try scanner.nextSInt() + } + + mutating func decodeSingularInt64Field(value: inout Int64?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextSInt() + } + + mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextSInt() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularUInt32Field(value: inout UInt32) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw JSONDecodingError.numberRange + } + value = UInt32(truncatingIfNeeded: n) + } + + mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw JSONDecodingError.numberRange + } + value = UInt32(truncatingIfNeeded: n) + } + + mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw JSONDecodingError.numberRange + } + value.append(UInt32(truncatingIfNeeded: n)) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularUInt64Field(value: inout UInt64) throws { + if scanner.skipOptionalNull() { + value = 0 + return + } + value = try scanner.nextUInt() + } + + mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextUInt() + } + + mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextUInt() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularSInt32Field(value: inout Int32) throws { + try decodeSingularInt32Field(value: &value) + } + + mutating func decodeSingularSInt32Field(value: inout Int32?) throws { + try decodeSingularInt32Field(value: &value) + } + + mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { + try decodeRepeatedInt32Field(value: &value) + } + + mutating func decodeSingularSInt64Field(value: inout Int64) throws { + try decodeSingularInt64Field(value: &value) + } + + mutating func decodeSingularSInt64Field(value: inout Int64?) throws { + try decodeSingularInt64Field(value: &value) + } + + mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { + try decodeRepeatedInt64Field(value: &value) + } + + mutating func decodeSingularFixed32Field(value: inout UInt32) throws { + try decodeSingularUInt32Field(value: &value) + } + + mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { + try decodeSingularUInt32Field(value: &value) + } + + mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { + try decodeRepeatedUInt32Field(value: &value) + } + + mutating func decodeSingularFixed64Field(value: inout UInt64) throws { + try decodeSingularUInt64Field(value: &value) + } + + mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { + try decodeSingularUInt64Field(value: &value) + } + + mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { + try decodeRepeatedUInt64Field(value: &value) + } + + mutating func decodeSingularSFixed32Field(value: inout Int32) throws { + try decodeSingularInt32Field(value: &value) + } + + mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { + try decodeSingularInt32Field(value: &value) + } + + mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { + try decodeRepeatedInt32Field(value: &value) + } + + mutating func decodeSingularSFixed64Field(value: inout Int64) throws { + try decodeSingularInt64Field(value: &value) + } + + mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { + try decodeSingularInt64Field(value: &value) + } + + mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { + try decodeRepeatedInt64Field(value: &value) + } + + mutating func decodeSingularBoolField(value: inout Bool) throws { + if scanner.skipOptionalNull() { + value = false + return + } + if isMapKey { + value = try scanner.nextQuotedBool() + } else { + value = try scanner.nextBool() + } + } + + mutating func decodeSingularBoolField(value: inout Bool?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + if isMapKey { + value = try scanner.nextQuotedBool() + } else { + value = try scanner.nextBool() + } + } + + mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextBool() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularStringField(value: inout String) throws { + if scanner.skipOptionalNull() { + value = String() + return + } + value = try scanner.nextQuotedString() + } + + mutating func decodeSingularStringField(value: inout String?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextQuotedString() + } + + mutating func decodeRepeatedStringField(value: inout [String]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextQuotedString() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularBytesField(value: inout Data) throws { + if scanner.skipOptionalNull() { + value = Internal.emptyData + return + } + value = try scanner.nextBytesValue() + } + + mutating func decodeSingularBytesField(value: inout Data?) throws { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextBytesValue() + } + + mutating func decodeRepeatedBytesField(value: inout [Data]) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let n = try scanner.nextBytesValue() + value.append(n) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularEnumField(value: inout E?) throws + where E.RawValue == Int { + if scanner.skipOptionalNull() { + value = nil + return + } + value = try scanner.nextEnumValue() as E + } + + mutating func decodeSingularEnumField(value: inout E) throws + where E.RawValue == Int { + if scanner.skipOptionalNull() { + value = E() + return + } + value = try scanner.nextEnumValue() + } + + mutating func decodeRepeatedEnumField(value: inout [E]) throws + where E.RawValue == Int { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + let e: E = try scanner.nextEnumValue() + value.append(e) + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + internal mutating func decodeFullObject(message: inout M) throws { + guard let nameProviding = (M.self as? _ProtoNameProviding.Type) else { + throw JSONDecodingError.missingFieldNames + } + fieldNameMap = nameProviding._protobuf_nameMap + if let m = message as? _CustomJSONCodable { + var customCodable = m + try customCodable.decodeJSON(from: &self) + message = customCodable as! M + } else { + try scanner.skipRequiredObjectStart() + if scanner.skipOptionalObjectEnd() { + return + } + try message.decodeMessage(decoder: &self) + } + } + + mutating func decodeSingularMessageField(value: inout M?) throws { + if scanner.skipOptionalNull() { + if M.self is _CustomJSONCodable.Type { + value = + try (M.self as! _CustomJSONCodable.Type).decodedFromJSONNull() as? M + return + } + // All other message field types treat 'null' as an unset + value = nil + return + } + if value == nil { + value = M() + } + var subDecoder = JSONDecoder(decoder: self) + try subDecoder.decodeFullObject(message: &value!) + assert(scanner.recursionBudget == subDecoder.scanner.recursionBudget) + scanner = subDecoder.scanner + } + + mutating func decodeRepeatedMessageField( + value: inout [M] + ) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredArrayStart() + if scanner.skipOptionalArrayEnd() { + return + } + while true { + if scanner.skipOptionalNull() { + var appended = false + if M.self is _CustomJSONCodable.Type { + if let message = try (M.self as! _CustomJSONCodable.Type) + .decodedFromJSONNull() as? M { + value.append(message) + appended = true + } + } + if !appended { + throw JSONDecodingError.illegalNull + } + } else { + var message = M() + var subDecoder = JSONDecoder(decoder: self) + try subDecoder.decodeFullObject(message: &message) + value.append(message) + assert(scanner.recursionBudget == subDecoder.scanner.recursionBudget) + scanner = subDecoder.scanner + } + if scanner.skipOptionalArrayEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeSingularGroupField(value: inout G?) throws { + throw JSONDecodingError.schemaMismatch + } + + mutating func decodeRepeatedGroupField(value: inout [G]) throws { + throw JSONDecodingError.schemaMismatch + } + + mutating func decodeMapField( + fieldType: _ProtobufMap.Type, + value: inout _ProtobufMap.BaseType + ) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredObjectStart() + if scanner.skipOptionalObjectEnd() { + return + } + while true { + // Next character must be double quote, because + // map keys must always be quoted strings. + let c = try scanner.peekOneCharacter() + if c != "\"" { + throw JSONDecodingError.unquotedMapKey + } + isMapKey = true + var keyField: KeyType.BaseType? + try KeyType.decodeSingular(value: &keyField, from: &self) + isMapKey = false + try scanner.skipRequiredColon() + var valueField: ValueType.BaseType? + try ValueType.decodeSingular(value: &valueField, from: &self) + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + } else { + throw JSONDecodingError.malformedMap + } + if scanner.skipOptionalObjectEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeMapField( + fieldType: _ProtobufEnumMap.Type, + value: inout _ProtobufEnumMap.BaseType + ) throws where ValueType.RawValue == Int { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredObjectStart() + if scanner.skipOptionalObjectEnd() { + return + } + while true { + // Next character must be double quote, because + // map keys must always be quoted strings. + let c = try scanner.peekOneCharacter() + if c != "\"" { + throw JSONDecodingError.unquotedMapKey + } + isMapKey = true + var keyField: KeyType.BaseType? + try KeyType.decodeSingular(value: &keyField, from: &self) + isMapKey = false + try scanner.skipRequiredColon() + var valueField: ValueType? + try decodeSingularEnumField(value: &valueField) + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + } else { + throw JSONDecodingError.malformedMap + } + if scanner.skipOptionalObjectEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeMapField( + fieldType: _ProtobufMessageMap.Type, + value: inout _ProtobufMessageMap.BaseType + ) throws { + if scanner.skipOptionalNull() { + return + } + try scanner.skipRequiredObjectStart() + if scanner.skipOptionalObjectEnd() { + return + } + while true { + // Next character must be double quote, because + // map keys must always be quoted strings. + let c = try scanner.peekOneCharacter() + if c != "\"" { + throw JSONDecodingError.unquotedMapKey + } + isMapKey = true + var keyField: KeyType.BaseType? + try KeyType.decodeSingular(value: &keyField, from: &self) + isMapKey = false + try scanner.skipRequiredColon() + var valueField: ValueType? + try decodeSingularMessageField(value: &valueField) + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + } else { + throw JSONDecodingError.malformedMap + } + if scanner.skipOptionalObjectEnd() { + return + } + try scanner.skipRequiredComma() + } + } + + mutating func decodeExtensionField( + values: inout ExtensionFieldValueSet, + messageType: Message.Type, + fieldNumber: Int + ) throws { + throw JSONDecodingError.schemaMismatch + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift new file mode 100644 index 0000000..8008eb0 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift @@ -0,0 +1,62 @@ +// Sources/SwiftProtobuf/JSONDecodingError.swift - JSON decoding errors +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON decoding errors +/// +// ----------------------------------------------------------------------------- + +public enum JSONDecodingError: Error { + /// Something was wrong + case failure + /// A number could not be parsed + case malformedNumber + /// Numeric value was out of range or was not an integer value when expected + case numberRange + /// A map could not be parsed + case malformedMap + /// A bool could not be parsed + case malformedBool + /// We expected a quoted string, or a quoted string has a malformed backslash sequence + case malformedString + /// We encountered malformed UTF8 + case invalidUTF8 + /// The message does not have fieldName information + case missingFieldNames + /// The data type does not match the schema description + case schemaMismatch + /// A value (text or numeric) for an enum was not found on the enum + case unrecognizedEnumValue + /// A 'null' token appeared in an illegal location. + /// For example, Protobuf JSON does not allow 'null' tokens to appear + /// in lists. + case illegalNull + /// A map key was not quoted + case unquotedMapKey + /// JSON RFC 7519 does not allow numbers to have extra leading zeros + case leadingZero + /// We hit the end of the JSON string and expected something more... + case truncated + /// A JSON Duration could not be parsed + case malformedDuration + /// A JSON Timestamp could not be parsed + case malformedTimestamp + /// A FieldMask could not be parsed + case malformedFieldMask + /// Extraneous data remained after decoding should have been complete + case trailingGarbage + /// More than one value was specified for the same oneof field + case conflictingOneOf + /// Reached the nesting limit for messages within messages while decoding. + case messageDepthLimit + /// Encountered an unknown field with the given name. When parsing JSON, you + /// can instead instruct the library to ignore this via + /// JSONDecodingOptions.ignoreUnknownFields. + case unknownField(String) +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift new file mode 100644 index 0000000..da539c5 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift @@ -0,0 +1,29 @@ +// Sources/SwiftProtobuf/JSONDecodingOptions.swift - JSON decoding options +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON decoding options +/// +// ----------------------------------------------------------------------------- + +/// Options for JSONDecoding. +public struct JSONDecodingOptions { + /// The maximum nesting of message with messages. The default is 100. + /// + /// To prevent corrupt or malicious messages from causing stack overflows, + /// this controls how deep messages can be nested within other messages + /// while parsing. + public var messageDepthLimit: Int = 100 + + /// If unknown fields in the JSON should be ignored. If they aren't + /// ignored, an error will be raised if one is encountered. + public var ignoreUnknownFields: Bool = false + + public init() {} +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift new file mode 100644 index 0000000..7e811b7 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift @@ -0,0 +1,370 @@ +// Sources/SwiftProtobuf/JSONEncoder.swift - JSON Encoding support +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON serialization engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let asciiZero = UInt8(ascii: "0") +private let asciiOne = UInt8(ascii: "1") +private let asciiTwo = UInt8(ascii: "2") +private let asciiThree = UInt8(ascii: "3") +private let asciiFour = UInt8(ascii: "4") +private let asciiFive = UInt8(ascii: "5") +private let asciiSix = UInt8(ascii: "6") +private let asciiSeven = UInt8(ascii: "7") +private let asciiEight = UInt8(ascii: "8") +private let asciiNine = UInt8(ascii: "9") +private let asciiMinus = UInt8(ascii: "-") +private let asciiPlus = UInt8(ascii: "+") +private let asciiEquals = UInt8(ascii: "=") +private let asciiColon = UInt8(ascii: ":") +private let asciiComma = UInt8(ascii: ",") +private let asciiDoubleQuote = UInt8(ascii: "\"") +private let asciiBackslash = UInt8(ascii: "\\") +private let asciiForwardSlash = UInt8(ascii: "/") +private let asciiOpenSquareBracket = UInt8(ascii: "[") +private let asciiCloseSquareBracket = UInt8(ascii: "]") +private let asciiOpenCurlyBracket = UInt8(ascii: "{") +private let asciiCloseCurlyBracket = UInt8(ascii: "}") +private let asciiUpperA = UInt8(ascii: "A") +private let asciiUpperB = UInt8(ascii: "B") +private let asciiUpperC = UInt8(ascii: "C") +private let asciiUpperD = UInt8(ascii: "D") +private let asciiUpperE = UInt8(ascii: "E") +private let asciiUpperF = UInt8(ascii: "F") +private let asciiUpperZ = UInt8(ascii: "Z") +private let asciiLowerA = UInt8(ascii: "a") +private let asciiLowerZ = UInt8(ascii: "z") + +private let base64Digits: [UInt8] = { + var digits = [UInt8]() + digits.append(contentsOf: asciiUpperA...asciiUpperZ) + digits.append(contentsOf: asciiLowerA...asciiLowerZ) + digits.append(contentsOf: asciiZero...asciiNine) + digits.append(asciiPlus) + digits.append(asciiForwardSlash) + return digits +}() + +private let hexDigits: [UInt8] = { + var digits = [UInt8]() + digits.append(contentsOf: asciiZero...asciiNine) + digits.append(contentsOf: asciiUpperA...asciiUpperF) + return digits +}() + +internal struct JSONEncoder { + private var data = [UInt8]() + private var separator: UInt8? + + internal init() {} + + internal var dataResult: Data { return Data(data) } + + internal var stringResult: String { + get { + return String(bytes: data, encoding: String.Encoding.utf8)! + } + } + + /// Append a `StaticString` to the JSON text. Because + /// `StaticString` is already UTF8 internally, this is faster + /// than appending a regular `String`. + internal mutating func append(staticText: StaticString) { + let buff = UnsafeBufferPointer(start: staticText.utf8Start, count: staticText.utf8CodeUnitCount) + data.append(contentsOf: buff) + } + + /// Append a `_NameMap.Name` to the JSON text surrounded by quotes. + /// As with StaticString above, a `_NameMap.Name` provides pre-converted + /// UTF8 bytes, so this is much faster than appending a regular + /// `String`. + internal mutating func appendQuoted(name: _NameMap.Name) { + data.append(asciiDoubleQuote) + data.append(contentsOf: name.utf8Buffer) + data.append(asciiDoubleQuote) + } + + /// Append a `String` to the JSON text. + internal mutating func append(text: String) { + data.append(contentsOf: text.utf8) + } + + /// Append a raw utf8 in a `Data` to the JSON text. + internal mutating func append(utf8Data: Data) { + data.append(contentsOf: utf8Data) + } + + /// Begin a new field whose name is given as a `_NameMap.Name` + internal mutating func startField(name: _NameMap.Name) { + if let s = separator { + data.append(s) + } + appendQuoted(name: name) + data.append(asciiColon) + separator = asciiComma + } + + /// Begin a new field whose name is given as a `String`. + internal mutating func startField(name: String) { + if let s = separator { + data.append(s) + } + data.append(asciiDoubleQuote) + // Can avoid overhead of putStringValue, since + // the JSON field names are always clean ASCII. + data.append(contentsOf: name.utf8) + append(staticText: "\":") + separator = asciiComma + } + + /// Append an open square bracket `[` to the JSON. + internal mutating func startArray() { + data.append(asciiOpenSquareBracket) + separator = nil + } + + /// Append a close square bracket `]` to the JSON. + internal mutating func endArray() { + data.append(asciiCloseSquareBracket) + separator = asciiComma + } + + /// Append a comma `,` to the JSON. + internal mutating func comma() { + data.append(asciiComma) + } + + /// Append an open curly brace `{` to the JSON. + internal mutating func startObject() { + if let s = separator { + data.append(s) + } + data.append(asciiOpenCurlyBracket) + separator = nil + } + + /// Append a close curly brace `}` to the JSON. + internal mutating func endObject() { + data.append(asciiCloseCurlyBracket) + separator = asciiComma + } + + /// Write a JSON `null` token to the output. + internal mutating func putNullValue() { + append(staticText: "null") + } + + /// Append a float value to the output. + /// This handles Nan and infinite values by + /// writing well-known string values. + internal mutating func putFloatValue(value: Float) { + if value.isNaN { + append(staticText: "\"NaN\"") + } else if !value.isFinite { + if value < 0 { + append(staticText: "\"-Infinity\"") + } else { + append(staticText: "\"Infinity\"") + } + } else { + data.append(contentsOf: value.debugDescription.utf8) + } + } + + /// Append a double value to the output. + /// This handles Nan and infinite values by + /// writing well-known string values. + internal mutating func putDoubleValue(value: Double) { + if value.isNaN { + append(staticText: "\"NaN\"") + } else if !value.isFinite { + if value < 0 { + append(staticText: "\"-Infinity\"") + } else { + append(staticText: "\"Infinity\"") + } + } else { + data.append(contentsOf: value.debugDescription.utf8) + } + } + + /// Append a UInt64 to the output (without quoting). + private mutating func appendUInt(value: UInt64) { + if value >= 10 { + appendUInt(value: value / 10) + } + data.append(asciiZero + UInt8(value % 10)) + } + + /// Append an Int64 to the output (without quoting). + private mutating func appendInt(value: Int64) { + if value < 0 { + data.append(asciiMinus) + // This is the twos-complement negation of value, + // computed in a way that won't overflow a 64-bit + // signed integer. + appendUInt(value: 1 + ~UInt64(bitPattern: value)) + } else { + appendUInt(value: UInt64(bitPattern: value)) + } + } + + /// Write an Enum as an int. + internal mutating func putEnumInt(value: Int) { + appendInt(value: Int64(value)) + } + + /// Write an `Int64` using protobuf JSON quoting conventions. + internal mutating func putInt64(value: Int64) { + data.append(asciiDoubleQuote) + appendInt(value: value) + data.append(asciiDoubleQuote) + } + + /// Write an `Int32` with quoting suitable for + /// using the value as a map key. + internal mutating func putQuotedInt32(value: Int32) { + data.append(asciiDoubleQuote) + appendInt(value: Int64(value)) + data.append(asciiDoubleQuote) + } + + /// Write an `Int32` in the default format. + internal mutating func putInt32(value: Int32) { + appendInt(value: Int64(value)) + } + + /// Write a `UInt64` using protobuf JSON quoting conventions. + internal mutating func putUInt64(value: UInt64) { + data.append(asciiDoubleQuote) + appendUInt(value: value) + data.append(asciiDoubleQuote) + } + + /// Write a `UInt32` with quoting suitable for + /// using the value as a map key. + internal mutating func putQuotedUInt32(value: UInt32) { + data.append(asciiDoubleQuote) + appendUInt(value: UInt64(value)) + data.append(asciiDoubleQuote) + } + + /// Write a `UInt32` in the default format. + internal mutating func putUInt32(value: UInt32) { + appendUInt(value: UInt64(value)) + } + + /// Write a `Bool` with quoting suitable for + /// using the value as a map key. + internal mutating func putQuotedBoolValue(value: Bool) { + data.append(asciiDoubleQuote) + putBoolValue(value: value) + data.append(asciiDoubleQuote) + } + + /// Write a `Bool` in the default format. + internal mutating func putBoolValue(value: Bool) { + if value { + append(staticText: "true") + } else { + append(staticText: "false") + } + } + + /// Append a string value escaping special characters as needed. + internal mutating func putStringValue(value: String) { + data.append(asciiDoubleQuote) + for c in value.unicodeScalars { + switch c.value { + // Special two-byte escapes + case 8: append(staticText: "\\b") + case 9: append(staticText: "\\t") + case 10: append(staticText: "\\n") + case 12: append(staticText: "\\f") + case 13: append(staticText: "\\r") + case 34: append(staticText: "\\\"") + case 92: append(staticText: "\\\\") + case 0...31, 127...159: // Hex form for C0 control chars + append(staticText: "\\u00") + data.append(hexDigits[Int(c.value / 16)]) + data.append(hexDigits[Int(c.value & 15)]) + case 23...126: + data.append(UInt8(truncatingIfNeeded: c.value)) + case 0x80...0x7ff: + data.append(0xc0 + UInt8(truncatingIfNeeded: c.value >> 6)) + data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) + case 0x800...0xffff: + data.append(0xe0 + UInt8(truncatingIfNeeded: c.value >> 12)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) + default: + data.append(0xf0 + UInt8(truncatingIfNeeded: c.value >> 18)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 12) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) + } + } + data.append(asciiDoubleQuote) + } + + /// Append a bytes value using protobuf JSON Base-64 encoding. + internal mutating func putBytesValue(value: Data) { + data.append(asciiDoubleQuote) + if value.count > 0 { + value.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let p = baseAddress.assumingMemoryBound(to: UInt8.self) + + var t: Int = 0 + var bytesInGroup: Int = 0 + for i in 0..> 18) & 63]) + data.append(base64Digits[(t >> 12) & 63]) + data.append(base64Digits[(t >> 6) & 63]) + data.append(base64Digits[t & 63]) + t = 0 + bytesInGroup = 0 + } + t = (t << 8) + Int(p[i]) + bytesInGroup += 1 + } + switch bytesInGroup { + case 3: + data.append(base64Digits[(t >> 18) & 63]) + data.append(base64Digits[(t >> 12) & 63]) + data.append(base64Digits[(t >> 6) & 63]) + data.append(base64Digits[t & 63]) + case 2: + t <<= 8 + data.append(base64Digits[(t >> 18) & 63]) + data.append(base64Digits[(t >> 12) & 63]) + data.append(base64Digits[(t >> 6) & 63]) + data.append(asciiEquals) + case 1: + t <<= 16 + data.append(base64Digits[(t >> 18) & 63]) + data.append(base64Digits[(t >> 12) & 63]) + data.append(asciiEquals) + data.append(asciiEquals) + default: + break + } + } + } + } + data.append(asciiDoubleQuote) + } +} + diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift new file mode 100644 index 0000000..26f828c --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift @@ -0,0 +1,35 @@ +// Sources/SwiftProtobuf/JSONEncodingError.swift - Error constants +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Enum constants that identify the particular error. +/// +// ----------------------------------------------------------------------------- + +public enum JSONEncodingError: Error { + /// Any fields that were decoded from binary format cannot be + /// re-encoded into JSON unless the object they hold is a + /// well-known type or a type registered with via + /// Google_Protobuf_Any.register() + case anyTranscodeFailure + /// Timestamp values can only be JSON encoded if they hold a value + /// between 0001-01-01Z00:00:00 and 9999-12-31Z23:59:59. + case timestampRange + /// Duration values can only be JSON encoded if they hold a value + /// less than +/- 100 years. + case durationRange + /// Field masks get edited when converting between JSON and protobuf + case fieldMaskConversion + /// Field names were not compiled into the binary + case missingFieldNames + /// Instances of `Google_Protobuf_Value` can only be encoded if they have a + /// valid `kind` (that is, they represent a null value, number, boolean, + /// string, struct, or list). + case missingValue +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift new file mode 100644 index 0000000..8274e08 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift @@ -0,0 +1,26 @@ +// Sources/SwiftProtobuf/JSONEncodingOptions.swift - JSON encoding options +// +// Copyright (c) 2014 - 2018 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON encoding options +/// +// ----------------------------------------------------------------------------- + +/// Options for JSONEncoding. +public struct JSONEncodingOptions { + + /// Always print enums as ints. By default they are printed as strings. + public var alwaysPrintEnumsAsInts: Bool = false + + /// Whether to preserve proto field names. + /// By default they are converted to JSON(lowerCamelCase) names. + public var preserveProtoFieldNames: Bool = false + + public init() {} +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift new file mode 100644 index 0000000..844bbeb --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift @@ -0,0 +1,352 @@ +// Sources/SwiftProtobuf/JSONEncodingVisitor.swift - JSON encoding visitor +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Visitor that writes a message in JSON format. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Visitor that serializes a message into JSON format. +internal struct JSONEncodingVisitor: Visitor { + + private var encoder = JSONEncoder() + private var nameMap: _NameMap + private let options: JSONEncodingOptions + + /// The JSON text produced by the visitor, as raw UTF8 bytes. + var dataResult: Data { + return encoder.dataResult + } + + /// The JSON text produced by the visitor, as a String. + internal var stringResult: String { + return encoder.stringResult + } + + /// Creates a new visitor for serializing a message of the given type to JSON + /// format. + init(type: Message.Type, options: JSONEncodingOptions) throws { + if let nameProviding = type as? _ProtoNameProviding.Type { + self.nameMap = nameProviding._protobuf_nameMap + } else { + throw JSONEncodingError.missingFieldNames + } + self.options = options + } + + /// Creates a new visitor that serializes the given message to JSON format. + init(message: Message, options: JSONEncodingOptions) throws { + if let nameProviding = message as? _ProtoNameProviding { + self.nameMap = type(of: nameProviding)._protobuf_nameMap + } else { + throw JSONEncodingError.missingFieldNames + } + self.options = options + } + + mutating func startArray() { + encoder.startArray() + } + + mutating func endArray() { + encoder.endArray() + } + + mutating func startObject() { + encoder.startObject() + } + + mutating func endObject() { + encoder.endObject() + } + + mutating func encodeField(name: String, stringValue value: String) { + encoder.startField(name: name) + encoder.putStringValue(value: value) + } + + mutating func encodeField(name: String, jsonText text: String) { + encoder.startField(name: name) + encoder.append(text: text) + } + + mutating func visitUnknown(bytes: Data) throws { + // JSON encoding has no provision for carrying proto2 unknown fields. + } + + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putFloatValue(value: value) + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putDoubleValue(value: value) + } + + mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putInt32(value: value) + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putInt64(value: value) + } + + mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putUInt32(value: value) + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putUInt64(value: value) + } + + mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putUInt32(value: value) + } + + mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putInt32(value: value) + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putBoolValue(value: value) + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putStringValue(value: value) + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.putBytesValue(value: value) + } + + private mutating func _visitRepeated( + value: [T], + fieldNumber: Int, + encode: (inout JSONEncoder, T) throws -> () + ) throws { + try startField(for: fieldNumber) + var comma = false + encoder.startArray() + for v in value { + if comma { + encoder.comma() + } + comma = true + try encode(&encoder, v) + } + encoder.endArray() + } + + mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { + try startField(for: fieldNumber) + if !options.alwaysPrintEnumsAsInts, let n = value.name { + encoder.appendQuoted(name: n) + } else { + encoder.putEnumInt(value: value.rawValue) + } + } + + mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { + try startField(for: fieldNumber) + let json = try value.jsonUTF8Data(options: options) + encoder.append(utf8Data: json) + } + + mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { + // Google does not serialize groups into JSON + } + + mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Float) in + encoder.putFloatValue(value: v) + } + } + + mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Double) in + encoder.putDoubleValue(value: v) + } + } + + mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Int32) in + encoder.putInt32(value: v) + } + } + + mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Int64) in + encoder.putInt64(value: v) + } + } + + mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: UInt32) in + encoder.putUInt32(value: v) + } + } + + mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: UInt64) in + encoder.putUInt64(value: v) + } + } + + mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { + try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { + try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Bool) in + encoder.putBoolValue(value: v) + } + } + + mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: String) in + encoder.putStringValue(value: v) + } + } + + mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: Data) in + encoder.putBytesValue(value: v) + } + } + + mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { + let alwaysPrintEnumsAsInts = options.alwaysPrintEnumsAsInts + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: E) throws in + if !alwaysPrintEnumsAsInts, let n = v.name { + encoder.appendQuoted(name: n) + } else { + encoder.putEnumInt(value: v.rawValue) + } + } + } + + mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { + let localOptions = options + try _visitRepeated(value: value, fieldNumber: fieldNumber) { + (encoder: inout JSONEncoder, v: M) throws in + let json = try v.jsonUTF8Data(options: localOptions) + encoder.append(utf8Data: json) + } + } + + mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { + // Google does not serialize groups into JSON + } + + // Packed fields are handled the same as non-packed fields, so JSON just + // relies on the default implementations in Visitor.swift + + + + mutating func visitMapField(fieldType: _ProtobufMap.Type, value: _ProtobufMap.BaseType, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.append(text: "{") + var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) + for (k,v) in value { + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) + try ValueType.visitSingular(value: v, fieldNumber: 2, with: &mapVisitor) + } + encoder = mapVisitor.encoder + encoder.append(text: "}") + } + + mutating func visitMapField(fieldType: _ProtobufEnumMap.Type, value: _ProtobufEnumMap.BaseType, fieldNumber: Int) throws where ValueType.RawValue == Int { + try startField(for: fieldNumber) + encoder.append(text: "{") + var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) + for (k, v) in value { + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) + try mapVisitor.visitSingularEnumField(value: v, fieldNumber: 2) + } + encoder = mapVisitor.encoder + encoder.append(text: "}") + } + + mutating func visitMapField(fieldType: _ProtobufMessageMap.Type, value: _ProtobufMessageMap.BaseType, fieldNumber: Int) throws { + try startField(for: fieldNumber) + encoder.append(text: "{") + var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) + for (k,v) in value { + try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) + try mapVisitor.visitSingularMessageField(value: v, fieldNumber: 2) + } + encoder = mapVisitor.encoder + encoder.append(text: "}") + } + + /// Called for each extension range. + mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { + // JSON does not store extensions + } + + /// Helper function that throws an error if the field number could not be + /// resolved. + private mutating func startField(for number: Int) throws { + let name: _NameMap.Name? + + if options.preserveProtoFieldNames { + name = nameMap.names(for: number)?.proto + } else { + name = nameMap.names(for: number)?.json + } + + if let nm = name { + encoder.startField(name: nm) + } else { + throw JSONEncodingError.missingFieldNames + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift new file mode 100644 index 0000000..319e51d --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift @@ -0,0 +1,174 @@ +// Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift - JSON map encoding visitor +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Visitor that writes out the key/value pairs for a JSON map. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Visitor that serializes a message into JSON map format. +/// +/// This expects to alternately visit the keys and values for a JSON +/// map. It only accepts singular values. Keys should be identified +/// as `fieldNumber:1`, values should be identified as `fieldNumber:2` +/// +internal struct JSONMapEncodingVisitor: SelectiveVisitor { + private var separator: StaticString? + internal var encoder: JSONEncoder + private let options: JSONEncodingOptions + + init(encoder: JSONEncoder, options: JSONEncodingOptions) { + self.encoder = encoder + self.options = options + } + + private mutating func startKey() { + if let s = separator { + encoder.append(staticText: s) + } else { + separator = "," + } + } + + private mutating func startValue() { + encoder.append(staticText: ":") + } + + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + // Doubles/Floats can never be map keys, only values + assert(fieldNumber == 2) + startValue() + encoder.putFloatValue(value: value) + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + // Doubles/Floats can never be map keys, only values + assert(fieldNumber == 2) + startValue() + encoder.putDoubleValue(value: value) + } + + mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + encoder.putQuotedInt32(value: value) + } else { + startValue() + encoder.putInt32(value: value) + } + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + } else { + startValue() + } + // Int64 fields are always quoted anyway + encoder.putInt64(value: value) + } + + mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + encoder.putQuotedUInt32(value: value) + } else { + startValue() + encoder.putUInt32(value: value) + } + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + } else { + startValue() + } + encoder.putUInt64(value: value) + } + + mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + try visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + encoder.putQuotedBoolValue(value: value) + } else { + startValue() + encoder.putBoolValue(value: value) + } + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + if fieldNumber == 1 { + startKey() + } else { + startValue() + } + encoder.putStringValue(value: value) + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + // Bytes can only be map values, never keys + assert(fieldNumber == 2) + startValue() + encoder.putBytesValue(value: value) + } + + mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { + // Enums can only be map values, never keys + assert(fieldNumber == 2) + startValue() + if !options.alwaysPrintEnumsAsInts, let n = value.name { + encoder.putStringValue(value: String(describing: n)) + } else { + encoder.putEnumInt(value: value.rawValue) + } + } + + mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { + // Messages can only be map values, never keys + assert(fieldNumber == 2) + startValue() + let json = try value.jsonString(options: options) + encoder.append(text: json) + } + + // SelectiveVisitor will block: + // - single Groups + // - everything repeated + // - everything packed + // - all maps + // - unknown fields + // - extensions +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift new file mode 100644 index 0000000..20e07c6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift @@ -0,0 +1,1512 @@ +// Sources/SwiftProtobuf/JSONScanner.swift - JSON format decoding +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// JSON format decoding engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let asciiBell = UInt8(7) +private let asciiBackspace = UInt8(8) +private let asciiTab = UInt8(9) +private let asciiNewLine = UInt8(10) +private let asciiVerticalTab = UInt8(11) +private let asciiFormFeed = UInt8(12) +private let asciiCarriageReturn = UInt8(13) +private let asciiZero = UInt8(ascii: "0") +private let asciiOne = UInt8(ascii: "1") +private let asciiSeven = UInt8(ascii: "7") +private let asciiNine = UInt8(ascii: "9") +private let asciiColon = UInt8(ascii: ":") +private let asciiPeriod = UInt8(ascii: ".") +private let asciiPlus = UInt8(ascii: "+") +private let asciiComma = UInt8(ascii: ",") +private let asciiSemicolon = UInt8(ascii: ";") +private let asciiDoubleQuote = UInt8(ascii: "\"") +private let asciiSingleQuote = UInt8(ascii: "\'") +private let asciiBackslash = UInt8(ascii: "\\") +private let asciiForwardSlash = UInt8(ascii: "/") +private let asciiHash = UInt8(ascii: "#") +private let asciiEqualSign = UInt8(ascii: "=") +private let asciiUnderscore = UInt8(ascii: "_") +private let asciiQuestionMark = UInt8(ascii: "?") +private let asciiSpace = UInt8(ascii: " ") +private let asciiOpenSquareBracket = UInt8(ascii: "[") +private let asciiCloseSquareBracket = UInt8(ascii: "]") +private let asciiOpenCurlyBracket = UInt8(ascii: "{") +private let asciiCloseCurlyBracket = UInt8(ascii: "}") +private let asciiOpenAngleBracket = UInt8(ascii: "<") +private let asciiCloseAngleBracket = UInt8(ascii: ">") +private let asciiMinus = UInt8(ascii: "-") +private let asciiLowerA = UInt8(ascii: "a") +private let asciiUpperA = UInt8(ascii: "A") +private let asciiLowerB = UInt8(ascii: "b") +private let asciiLowerE = UInt8(ascii: "e") +private let asciiUpperE = UInt8(ascii: "E") +private let asciiLowerF = UInt8(ascii: "f") +private let asciiUpperI = UInt8(ascii: "I") +private let asciiLowerL = UInt8(ascii: "l") +private let asciiLowerN = UInt8(ascii: "n") +private let asciiUpperN = UInt8(ascii: "N") +private let asciiLowerR = UInt8(ascii: "r") +private let asciiLowerS = UInt8(ascii: "s") +private let asciiLowerT = UInt8(ascii: "t") +private let asciiLowerU = UInt8(ascii: "u") +private let asciiLowerZ = UInt8(ascii: "z") +private let asciiUpperZ = UInt8(ascii: "Z") + +private func fromHexDigit(_ c: UnicodeScalar) -> UInt32? { + let n = c.value + if n >= 48 && n <= 57 { + return UInt32(n - 48) + } + switch n { + case 65, 97: return 10 + case 66, 98: return 11 + case 67, 99: return 12 + case 68, 100: return 13 + case 69, 101: return 14 + case 70, 102: return 15 + default: + return nil + } +} + +// Decode both the RFC 4648 section 4 Base 64 encoding and the RFC +// 4648 section 5 Base 64 variant. The section 5 variant is also +// known as "base64url" or the "URL-safe alphabet". +// Note that both "-" and "+" decode to 62 and "/" and "_" both +// decode as 63. +let base64Values: [Int] = [ +/* 0x00 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0x10 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0x20 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, +/* 0x30 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, +/* 0x40 */ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +/* 0x50 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, +/* 0x60 */ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, +/* 0x70 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, +/* 0x80 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0x90 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xa0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xb0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xc0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xd0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xe0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +/* 0xf0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +] + +/// Returns a `Data` value containing bytes equivalent to the given +/// Base64-encoded string, or nil if the conversion fails. +/// +/// Notes on Google's implementation (Base64Unescape() in strutil.cc): +/// * Google's C++ implementation accepts arbitrary whitespace +/// mixed in with the base-64 characters +/// * Google's C++ implementation ignores missing '=' characters +/// but if present, there must be the exact correct number of them. +/// * The conformance test requires us to accept both standard RFC4648 +/// Base 64 encoding and the "URL and Filename Safe Alphabet" variant. +/// +private func parseBytes( + source: UnsafeBufferPointer, + index: inout UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index +) throws -> Data { + let c = source[index] + if c != asciiDoubleQuote { + throw JSONDecodingError.malformedString + } + source.formIndex(after: &index) + + // Count the base-64 digits + // Ignore most unrecognized characters in this first pass, + // stop at the closing double quote. + let digitsStart = index + var rawChars = 0 + var sawSection4Characters = false + var sawSection5Characters = false + while index != end { + var digit = source[index] + if digit == asciiDoubleQuote { + break + } + + if digit == asciiBackslash { + source.formIndex(after: &index) + if index == end { + throw JSONDecodingError.malformedString + } + let escaped = source[index] + switch escaped { + case asciiLowerU: + // TODO: Parse hex escapes such as \u0041. Note that + // such escapes are going to be extremely rare, so + // there's little point in optimizing for them. + throw JSONDecodingError.malformedString + case asciiForwardSlash: + digit = escaped + default: + // Reject \b \f \n \r \t \" or \\ and all illegal escapes + throw JSONDecodingError.malformedString + } + } + + if digit == asciiPlus || digit == asciiForwardSlash { + sawSection4Characters = true + } else if digit == asciiMinus || digit == asciiUnderscore { + sawSection5Characters = true + } + let k = base64Values[Int(digit)] + if k >= 0 { + rawChars += 1 + } + source.formIndex(after: &index) + } + + // We reached the end without seeing the close quote + if index == end { + throw JSONDecodingError.malformedString + } + // Reject mixed encodings. + if sawSection4Characters && sawSection5Characters { + throw JSONDecodingError.malformedString + } + + // Allocate a Data object of exactly the right size + var value = Data(count: rawChars * 3 / 4) + + // Scan the digits again and populate the Data object. + // In this pass, we check for (and fail) if there are + // unexpected characters. But we don't check for end-of-input, + // because the loop above already verified that there was + // a closing double quote. + index = digitsStart + try value.withUnsafeMutableBytes { + (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + var p = baseAddress.assumingMemoryBound(to: UInt8.self) + var n = 0 + var chars = 0 // # chars in current group + var padding = 0 // # padding '=' chars + digits: while true { + let digit = source[index] + var k = base64Values[Int(digit)] + if k < 0 { + switch digit { + case asciiDoubleQuote: + break digits + case asciiBackslash: + source.formIndex(after: &index) + let escaped = source[index] + switch escaped { + case asciiForwardSlash: + k = base64Values[Int(escaped)] + default: + // Note: Invalid backslash escapes were caught + // above; we should never get here. + throw JSONDecodingError.malformedString + } + case asciiSpace: + source.formIndex(after: &index) + continue digits + case asciiEqualSign: // Count padding + while true { + switch source[index] { + case asciiDoubleQuote: + break digits + case asciiSpace: + break + case 61: + padding += 1 + default: // Only '=' and whitespace permitted + throw JSONDecodingError.malformedString + } + source.formIndex(after: &index) + } + default: + throw JSONDecodingError.malformedString + } + } + n <<= 6 + n |= k + chars += 1 + if chars == 4 { + p[0] = UInt8(truncatingIfNeeded: n >> 16) + p[1] = UInt8(truncatingIfNeeded: n >> 8) + p[2] = UInt8(truncatingIfNeeded: n) + p += 3 + chars = 0 + n = 0 + } + source.formIndex(after: &index) + } + switch chars { + case 3: + p[0] = UInt8(truncatingIfNeeded: n >> 10) + p[1] = UInt8(truncatingIfNeeded: n >> 2) + if padding == 1 || padding == 0 { + return + } + case 2: + p[0] = UInt8(truncatingIfNeeded: n >> 4) + if padding == 2 || padding == 0 { + return + } + case 0: + if padding == 0 { + return + } + default: + break + } + throw JSONDecodingError.malformedString + } + } + source.formIndex(after: &index) + return value +} + +// JSON encoding allows a variety of \-escapes, including +// escaping UTF-16 code points (which may be surrogate pairs). +private func decodeString(_ s: String) -> String? { + var out = String.UnicodeScalarView() + var chars = s.unicodeScalars.makeIterator() + while let c = chars.next() { + switch c.value { + case UInt32(asciiBackslash): // backslash + if let escaped = chars.next() { + switch escaped.value { + case UInt32(asciiLowerU): // "\u" + // Exactly 4 hex digits: + if let digit1 = chars.next(), + let d1 = fromHexDigit(digit1), + let digit2 = chars.next(), + let d2 = fromHexDigit(digit2), + let digit3 = chars.next(), + let d3 = fromHexDigit(digit3), + let digit4 = chars.next(), + let d4 = fromHexDigit(digit4) { + let codePoint = ((d1 * 16 + d2) * 16 + d3) * 16 + d4 + if let scalar = UnicodeScalar(codePoint) { + out.append(scalar) + } else if codePoint < 0xD800 || codePoint >= 0xE000 { + // Not a valid Unicode scalar. + return nil + } else if codePoint >= 0xDC00 { + // Low surrogate without a preceding high surrogate. + return nil + } else { + // We have a high surrogate (in the range 0xD800..<0xDC00), so + // verify that it is followed by a low surrogate. + guard chars.next() == "\\", chars.next() == "u" else { + // High surrogate was not followed by a Unicode escape sequence. + return nil + } + if let digit1 = chars.next(), + let d1 = fromHexDigit(digit1), + let digit2 = chars.next(), + let d2 = fromHexDigit(digit2), + let digit3 = chars.next(), + let d3 = fromHexDigit(digit3), + let digit4 = chars.next(), + let d4 = fromHexDigit(digit4) { + let follower = ((d1 * 16 + d2) * 16 + d3) * 16 + d4 + guard 0xDC00 <= follower && follower < 0xE000 else { + // High surrogate was not followed by a low surrogate. + return nil + } + let high = codePoint - 0xD800 + let low = follower - 0xDC00 + let composed = 0x10000 | high << 10 | low + guard let composedScalar = UnicodeScalar(composed) else { + // Composed value is not a valid Unicode scalar. + return nil + } + out.append(composedScalar) + } else { + // Malformed \u escape for low surrogate + return nil + } + } + } else { + // Malformed \u escape + return nil + } + case UInt32(asciiLowerB): // \b + out.append("\u{08}") + case UInt32(asciiLowerF): // \f + out.append("\u{0c}") + case UInt32(asciiLowerN): // \n + out.append("\u{0a}") + case UInt32(asciiLowerR): // \r + out.append("\u{0d}") + case UInt32(asciiLowerT): // \t + out.append("\u{09}") + case UInt32(asciiDoubleQuote), UInt32(asciiBackslash), + UInt32(asciiForwardSlash): // " \ / + out.append(escaped) + default: + return nil // Unrecognized escape + } + } else { + return nil // Input ends with backslash + } + default: + out.append(c) + } + } + return String(out) +} + +/// +/// The basic scanner support is entirely private +/// +/// For performance, it works directly against UTF-8 bytes in memory. +/// +internal struct JSONScanner { + private let source: UnsafeBufferPointer + private var index: UnsafeBufferPointer.Index + private var numberParser = DoubleParser() + internal var recursionLimit: Int + internal var recursionBudget: Int + private var ignoreUnknownFields: Bool + + /// True if the scanner has read all of the data from the source, with the + /// exception of any trailing whitespace (which is consumed by reading this + /// property). + internal var complete: Bool { + mutating get { + skipWhitespace() + return !hasMoreContent + } + } + + /// True if the scanner has not yet reached the end of the source. + private var hasMoreContent: Bool { + return index != source.endIndex + } + + /// The byte (UTF-8 code unit) at the scanner's current position. + private var currentByte: UInt8 { + return source[index] + } + + internal init( + source: UnsafeBufferPointer, + messageDepthLimit: Int, + ignoreUnknownFields: Bool + ) { + self.source = source + self.index = source.startIndex + self.recursionLimit = messageDepthLimit + self.recursionBudget = messageDepthLimit + self.ignoreUnknownFields = ignoreUnknownFields + } + + private mutating func incrementRecursionDepth() throws { + recursionBudget -= 1 + if recursionBudget < 0 { + throw JSONDecodingError.messageDepthLimit + } + } + + private mutating func decrementRecursionDepth() { + recursionBudget += 1 + // This should never happen, if it does, something is probably corrupting memory, and + // simply throwing doesn't make much sense. + if recursionBudget > recursionLimit { + fatalError("Somehow JSONDecoding unwound more objects than it started") + } + } + + /// Advances the scanner to the next position in the source. + private mutating func advance() { + source.formIndex(after: &index) + } + + /// Skip whitespace + private mutating func skipWhitespace() { + while hasMoreContent { + let u = currentByte + switch u { + case asciiSpace, asciiTab, asciiNewLine, asciiCarriageReturn: + advance() + default: + return + } + } + } + + /// Returns (but does not consume) the next non-whitespace + /// character. This is used by google.protobuf.Value, for + /// example, for custom JSON parsing. + internal mutating func peekOneCharacter() throws -> Character { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + return Character(UnicodeScalar(UInt32(currentByte))!) + } + + // Parse the leading UInt64 from the provided utf8 bytes. + // + // This is called in three different situations: + // + // * Unquoted number. + // + // * Simple quoted number. If a number is quoted but has no + // backslashes, the caller can use this directly on the UTF8 by + // just verifying the quote marks. This code returns `nil` if it + // sees a backslash, in which case the caller will need to handle ... + // + // * Complex quoted number. In this case, the caller must parse the + // quoted value as a string, then convert the string to utf8 and + // use this to parse the result. This is slow but fortunately + // rare. + // + // In the common case where the number is written in integer form, + // this code does a simple straight conversion. If the number is in + // floating-point format, this uses a slower and less accurate + // approach: it identifies a substring comprising a float, and then + // uses Double() and UInt64() to convert that string to an unsigned + // integer. In particular, it cannot preserve full 64-bit integer + // values when they are written in floating-point format. + // + // If it encounters a "\" backslash character, it returns a nil. This + // is used by callers that are parsing quoted numbers. See nextSInt() + // and nextUInt() below. + private func parseBareUInt64( + source: UnsafeBufferPointer, + index: inout UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index + ) throws -> UInt64? { + if index == end { + throw JSONDecodingError.truncated + } + let start = index + let c = source[index] + switch c { + case asciiZero: // 0 + source.formIndex(after: &index) + if index != end { + let after = source[index] + switch after { + case asciiZero...asciiNine: // 0...9 + // leading '0' forbidden unless it is the only digit + throw JSONDecodingError.leadingZero + case asciiPeriod, asciiLowerE, asciiUpperE: // . e + // Slow path: JSON numbers can be written in floating-point notation + index = start + if let d = try parseBareDouble(source: source, + index: &index, + end: end) { + if let u = UInt64(exactly: d) { + return u + } + } + throw JSONDecodingError.malformedNumber + case asciiBackslash: + return nil + default: + return 0 + } + } + return 0 + case asciiOne...asciiNine: // 1...9 + var n = 0 as UInt64 + while index != end { + let digit = source[index] + switch digit { + case asciiZero...asciiNine: // 0...9 + let val = UInt64(digit - asciiZero) + if n > UInt64.max / 10 || n * 10 > UInt64.max - val { + throw JSONDecodingError.numberRange + } + source.formIndex(after: &index) + n = n * 10 + val + case asciiPeriod, asciiLowerE, asciiUpperE: // . e + // Slow path: JSON allows floating-point notation for integers + index = start + if let d = try parseBareDouble(source: source, + index: &index, + end: end) { + if let u = UInt64(exactly: d) { + return u + } + } + throw JSONDecodingError.malformedNumber + case asciiBackslash: + return nil + default: + return n + } + } + return n + case asciiBackslash: + return nil + default: + throw JSONDecodingError.malformedNumber + } + } + + // Parse the leading Int64 from the provided utf8. + // + // This uses parseBareUInt64() to do the heavy lifting; + // we just check for a leading minus and negate the result + // as necessary. + // + // As with parseBareUInt64(), if it encounters a "\" backslash + // character, it returns a nil. This allows callers to use this to + // do a "fast-path" decode of simple quoted numbers by parsing the + // UTF8 directly, only falling back to a full String decode when + // absolutely necessary. + private func parseBareSInt64( + source: UnsafeBufferPointer, + index: inout UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index + ) throws -> Int64? { + if index == end { + throw JSONDecodingError.truncated + } + let c = source[index] + if c == asciiMinus { // - + source.formIndex(after: &index) + if index == end { + throw JSONDecodingError.truncated + } + // character after '-' must be digit + let digit = source[index] + if digit < asciiZero || digit > asciiNine { + throw JSONDecodingError.malformedNumber + } + if let n = try parseBareUInt64(source: source, index: &index, end: end) { + let limit: UInt64 = 0x8000000000000000 // -Int64.min + if n >= limit { + if n > limit { + // Too large negative number + throw JSONDecodingError.numberRange + } else { + return Int64.min // Special case for Int64.min + } + } + return -Int64(bitPattern: n) + } else { + return nil + } + } else if let n = try parseBareUInt64(source: source, index: &index, end: end) { + if n > UInt64(bitPattern: Int64.max) { + throw JSONDecodingError.numberRange + } + return Int64(bitPattern: n) + } else { + return nil + } + } + + // Identify a floating-point token in the upcoming UTF8 bytes. + // + // This implements the full grammar defined by the JSON RFC 7159. + // Note that Swift's string-to-number conversions are much more + // lenient, so this is necessary if we want to accurately reject + // malformed JSON numbers. + // + // This is used by nextDouble() and nextFloat() to parse double and + // floating-point values, including values that happen to be in quotes. + // It's also used by the slow path in parseBareSInt64() and parseBareUInt64() + // above to handle integer values that are written in float-point notation. + private func parseBareDouble( + source: UnsafeBufferPointer, + index: inout UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index + ) throws -> Double? { + // RFC 7159 defines the grammar for JSON numbers as: + // number = [ minus ] int [ frac ] [ exp ] + if index == end { + throw JSONDecodingError.truncated + } + let start = index + var c = source[index] + if c == asciiBackslash { + return nil + } + + // Optional leading minus sign + if c == asciiMinus { // - + source.formIndex(after: &index) + if index == end { + index = start + throw JSONDecodingError.truncated + } + c = source[index] + if c == asciiBackslash { + return nil + } + } else if c == asciiUpperN { // Maybe NaN? + // Return nil, let the caller deal with it. + return nil + } + + if c == asciiUpperI { // Maybe Infinity, Inf, -Infinity, or -Inf ? + // Return nil, let the caller deal with it. + return nil + } + + // Integer part can be zero or a series of digits not starting with zero + // int = zero / (digit1-9 *DIGIT) + switch c { + case asciiZero: + // First digit can be zero only if not followed by a digit + source.formIndex(after: &index) + if index == end { + return 0.0 + } + c = source[index] + if c == asciiBackslash { + return nil + } + if c >= asciiZero && c <= asciiNine { + throw JSONDecodingError.leadingZero + } + case asciiOne...asciiNine: + while c >= asciiZero && c <= asciiNine { + source.formIndex(after: &index) + if index == end { + if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { + return d + } else { + throw JSONDecodingError.invalidUTF8 + } + } + c = source[index] + if c == asciiBackslash { + return nil + } + } + default: + // Integer part cannot be empty + throw JSONDecodingError.malformedNumber + } + + // frac = decimal-point 1*DIGIT + if c == asciiPeriod { + source.formIndex(after: &index) + if index == end { + // decimal point must have a following digit + throw JSONDecodingError.truncated + } + c = source[index] + switch c { + case asciiZero...asciiNine: // 0...9 + while c >= asciiZero && c <= asciiNine { + source.formIndex(after: &index) + if index == end { + if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { + return d + } else { + throw JSONDecodingError.invalidUTF8 + } + } + c = source[index] + if c == asciiBackslash { + return nil + } + } + case asciiBackslash: + return nil + default: + // decimal point must be followed by at least one digit + throw JSONDecodingError.malformedNumber + } + } + + // exp = e [ minus / plus ] 1*DIGIT + if c == asciiLowerE || c == asciiUpperE { + source.formIndex(after: &index) + if index == end { + // "e" must be followed by +,-, or digit + throw JSONDecodingError.truncated + } + c = source[index] + if c == asciiBackslash { + return nil + } + if c == asciiPlus || c == asciiMinus { // + - + source.formIndex(after: &index) + if index == end { + // must be at least one digit in exponent + throw JSONDecodingError.truncated + } + c = source[index] + if c == asciiBackslash { + return nil + } + } + switch c { + case asciiZero...asciiNine: + while c >= asciiZero && c <= asciiNine { + source.formIndex(after: &index) + if index == end { + if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { + return d + } else { + throw JSONDecodingError.invalidUTF8 + } + } + c = source[index] + if c == asciiBackslash { + return nil + } + } + default: + // must be at least one digit in exponent + throw JSONDecodingError.malformedNumber + } + } + if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { + return d + } else { + throw JSONDecodingError.invalidUTF8 + } + } + + /// Returns a fully-parsed string with all backslash escapes + /// correctly processed, or nil if next token is not a string. + /// + /// Assumes the leading quote has been verified (but not consumed) + private mutating func parseOptionalQuotedString() -> String? { + // Caller has already asserted that currentByte == quote here + var sawBackslash = false + advance() + let start = index + while hasMoreContent { + switch currentByte { + case asciiDoubleQuote: // " + let s = utf8ToString(bytes: source, start: start, end: index) + advance() + if let t = s { + if sawBackslash { + return decodeString(t) + } else { + return t + } + } else { + return nil // Invalid UTF8 + } + case asciiBackslash: // \ + advance() + guard hasMoreContent else { + return nil // Unterminated escape + } + sawBackslash = true + default: + break + } + advance() + } + return nil // Unterminated quoted string + } + + /// Parse an unsigned integer, whether or not its quoted. + /// This also handles cases such as quoted numbers that have + /// backslash escapes in them. + /// + /// This supports the full range of UInt64 (whether quoted or not) + /// unless the number is written in floating-point format. In that + /// case, we decode it with only Double precision. + internal mutating func nextUInt() throws -> UInt64 { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + if c == asciiDoubleQuote { + let start = index + advance() + if let u = try parseBareUInt64(source: source, + index: &index, + end: source.endIndex) { + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.malformedNumber + } + advance() + return u + } else { + // Couldn't parse because it had a "\" in the string, + // so parse out the quoted string and then reparse + // the result to get a UInt + index = start + let s = try nextQuotedString() + let raw = s.data(using: String.Encoding.utf8)! + let n = try raw.withUnsafeBytes { + (body: UnsafeRawBufferPointer) -> UInt64? in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var index = buffer.startIndex + let end = buffer.endIndex + if let u = try parseBareUInt64(source: buffer, + index: &index, + end: end) { + if index == end { + return u + } + } + } + return nil + } + if let n = n { + return n + } + } + } else if let u = try parseBareUInt64(source: source, + index: &index, + end: source.endIndex) { + return u + } + throw JSONDecodingError.malformedNumber + } + + /// Parse a signed integer, quoted or not, including handling + /// backslash escapes for quoted values. + /// + /// This supports the full range of Int64 (whether quoted or not) + /// unless the number is written in floating-point format. In that + /// case, we decode it with only Double precision. + internal mutating func nextSInt() throws -> Int64 { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + if c == asciiDoubleQuote { + let start = index + advance() + if let s = try parseBareSInt64(source: source, + index: &index, + end: source.endIndex) { + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.malformedNumber + } + advance() + return s + } else { + // Couldn't parse because it had a "\" in the string, + // so parse out the quoted string and then reparse + // the result as an SInt + index = start + let s = try nextQuotedString() + let raw = s.data(using: String.Encoding.utf8)! + let n = try raw.withUnsafeBytes { + (body: UnsafeRawBufferPointer) -> Int64? in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var index = buffer.startIndex + let end = buffer.endIndex + if let s = try parseBareSInt64(source: buffer, + index: &index, + end: end) { + if index == end { + return s + } + } + } + return nil + } + if let n = n { + return n + } + } + } else if let s = try parseBareSInt64(source: source, + index: &index, + end: source.endIndex) { + return s + } + throw JSONDecodingError.malformedNumber + } + + /// Parse the next Float value, regardless of whether it + /// is quoted, including handling backslash escapes for + /// quoted strings. + internal mutating func nextFloat() throws -> Float { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + if c == asciiDoubleQuote { // " + let start = index + advance() + if let d = try parseBareDouble(source: source, + index: &index, + end: source.endIndex) { + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.malformedNumber + } + advance() + return Float(d) + } else { + // Slow Path: parseBareDouble returned nil: It might be + // a valid float, but had something that + // parseBareDouble cannot directly handle. So we reset, + // try a full string parse, then examine the result: + index = start + let s = try nextQuotedString() + switch s { + case "NaN": return Float.nan + case "Inf": return Float.infinity + case "-Inf": return -Float.infinity + case "Infinity": return Float.infinity + case "-Infinity": return -Float.infinity + default: + let raw = s.data(using: String.Encoding.utf8)! + let n = try raw.withUnsafeBytes { + (body: UnsafeRawBufferPointer) -> Float? in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var index = buffer.startIndex + let end = buffer.endIndex + if let d = try parseBareDouble(source: buffer, + index: &index, + end: end) { + let f = Float(d) + if index == end && f.isFinite { + return f + } + } + } + return nil + } + if let n = n { + return n + } + } + } + } else { + if let d = try parseBareDouble(source: source, + index: &index, + end: source.endIndex) { + let f = Float(d) + if f.isFinite { + return f + } + } + } + throw JSONDecodingError.malformedNumber + } + + /// Parse the next Double value, regardless of whether it + /// is quoted, including handling backslash escapes for + /// quoted strings. + internal mutating func nextDouble() throws -> Double { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + if c == asciiDoubleQuote { // " + let start = index + advance() + if let d = try parseBareDouble(source: source, + index: &index, + end: source.endIndex) { + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.malformedNumber + } + advance() + return d + } else { + // Slow Path: parseBareDouble returned nil: It might be + // a valid float, but had something that + // parseBareDouble cannot directly handle. So we reset, + // try a full string parse, then examine the result: + index = start + let s = try nextQuotedString() + switch s { + case "NaN": return Double.nan + case "Inf": return Double.infinity + case "-Inf": return -Double.infinity + case "Infinity": return Double.infinity + case "-Infinity": return -Double.infinity + default: + let raw = s.data(using: String.Encoding.utf8)! + let n = try raw.withUnsafeBytes { + (body: UnsafeRawBufferPointer) -> Double? in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var index = buffer.startIndex + let end = buffer.endIndex + if let d = try parseBareDouble(source: buffer, + index: &index, + end: end) { + if index == end { + return d + } + } + } + return nil + } + if let n = n { + return n + } + } + } + } else { + if let d = try parseBareDouble(source: source, + index: &index, + end: source.endIndex) { + return d + } + } + throw JSONDecodingError.malformedNumber + } + + /// Return the contents of the following quoted string, + /// or throw an error if the next token is not a string. + internal mutating func nextQuotedString() throws -> String { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + if c != asciiDoubleQuote { + throw JSONDecodingError.malformedString + } + if let s = parseOptionalQuotedString() { + return s + } else { + throw JSONDecodingError.malformedString + } + } + + /// Return the contents of the following quoted string, + /// or nil if the next token is not a string. + /// This will only throw an error if the next token starts + /// out as a string but is malformed in some way. + internal mutating func nextOptionalQuotedString() throws -> String? { + skipWhitespace() + guard hasMoreContent else { + return nil + } + let c = currentByte + if c != asciiDoubleQuote { + return nil + } + return try nextQuotedString() + } + + /// Return a Data with the decoded contents of the + /// following base-64 string. + /// + /// Notes on Google's implementation: + /// * Google's C++ implementation accepts arbitrary whitespace + /// mixed in with the base-64 characters + /// * Google's C++ implementation ignores missing '=' characters + /// but if present, there must be the exact correct number of them. + /// * Google's C++ implementation accepts both "regular" and + /// "web-safe" base-64 variants (it seems to prefer the + /// web-safe version as defined in RFC 4648 + internal mutating func nextBytesValue() throws -> Data { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + return try parseBytes(source: source, index: &index, end: source.endIndex) + } + + /// Private function to help parse keywords. + private mutating func skipOptionalKeyword(bytes: [UInt8]) -> Bool { + let start = index + for b in bytes { + guard hasMoreContent else { + index = start + return false + } + let c = currentByte + if c != b { + index = start + return false + } + advance() + } + if hasMoreContent { + let c = currentByte + if (c >= asciiUpperA && c <= asciiUpperZ) || + (c >= asciiLowerA && c <= asciiLowerZ) { + index = start + return false + } + } + return true + } + + /// If the next token is the identifier "null", consume it and return true. + internal mutating func skipOptionalNull() -> Bool { + skipWhitespace() + if hasMoreContent && currentByte == asciiLowerN { + return skipOptionalKeyword(bytes: [ + asciiLowerN, asciiLowerU, asciiLowerL, asciiLowerL + ]) + } + return false + } + + /// Return the following Bool "true" or "false", including + /// full processing of quoted boolean values. (Used in map + /// keys, for instance.) + internal mutating func nextBool() throws -> Bool { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let c = currentByte + switch c { + case asciiLowerF: // f + if skipOptionalKeyword(bytes: [ + asciiLowerF, asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE + ]) { + return false + } + case asciiLowerT: // t + if skipOptionalKeyword(bytes: [ + asciiLowerT, asciiLowerR, asciiLowerU, asciiLowerE + ]) { + return true + } + default: + break + } + throw JSONDecodingError.malformedBool + } + + /// Return the following Bool "true" or "false", including + /// full processing of quoted boolean values. (Used in map + /// keys, for instance.) + internal mutating func nextQuotedBool() throws -> Bool { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.unquotedMapKey + } + if let s = parseOptionalQuotedString() { + switch s { + case "false": return false + case "true": return true + default: break + } + } + throw JSONDecodingError.malformedBool + } + + /// Returns pointer/count spanning the UTF8 bytes of the next regular + /// key or nil if the key contains a backslash (and therefore requires + /// the full string-parsing logic to properly parse). + private mutating func nextOptionalKey() throws -> UnsafeBufferPointer? { + skipWhitespace() + let stringStart = index + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte != asciiDoubleQuote { + return nil + } + advance() + let nameStart = index + while hasMoreContent && currentByte != asciiDoubleQuote { + if currentByte == asciiBackslash { + index = stringStart // Reset to open quote + return nil + } + advance() + } + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let buff = UnsafeBufferPointer( + start: source.baseAddress! + nameStart, + count: index - nameStart) + advance() + return buff + } + + /// Parse a field name, look it up in the provided field name map, + /// and return the corresponding field number. + /// + /// Throws if field name cannot be parsed. + /// If it encounters an unknown field name, it silently skips + /// the value and looks at the following field name. + internal mutating func nextFieldNumber(names: _NameMap) throws -> Int? { + while true { + if let key = try nextOptionalKey() { + // Fast path: We parsed it as UTF8 bytes... + try skipRequiredCharacter(asciiColon) // : + if let fieldNumber = names.number(forJSONName: key) { + return fieldNumber + } + if !ignoreUnknownFields { + let fieldName = utf8ToString(bytes: key.baseAddress!, count: key.count)! + throw JSONDecodingError.unknownField(fieldName) + } + } else { + // Slow path: We parsed a String; lookups from String are slower. + let key = try nextQuotedString() + try skipRequiredCharacter(asciiColon) // : + if let fieldNumber = names.number(forJSONName: key) { + return fieldNumber + } + if !ignoreUnknownFields { + throw JSONDecodingError.unknownField(key) + } + } + // Unknown field, skip it and try to parse the next field name + try skipValue() + if skipOptionalObjectEnd() { + return nil + } + try skipRequiredComma() + } + } + + /// Parse the next token as a string or numeric enum value. Throws + /// unrecognizedEnumValue if the string/number can't initialize the + /// enum. Will throw other errors if the JSON is malformed. + internal mutating func nextEnumValue() throws -> E { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + if currentByte == asciiDoubleQuote { + if let name = try nextOptionalKey() { + if let e = E(rawUTF8: name) { + return e + } else { + throw JSONDecodingError.unrecognizedEnumValue + } + } + let name = try nextQuotedString() + if let e = E(name: name) { + return e + } else { + throw JSONDecodingError.unrecognizedEnumValue + } + } else { + let n = try nextSInt() + if let i = Int(exactly: n) { + if let e = E(rawValue: i) { + return e + } else { + throw JSONDecodingError.unrecognizedEnumValue + } + } else { + throw JSONDecodingError.numberRange + } + } + } + + /// Helper for skipping a single-character token. + private mutating func skipRequiredCharacter(_ required: UInt8) throws { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + let next = currentByte + if next == required { + advance() + return + } + throw JSONDecodingError.failure + } + + /// Skip "{", throw if that's not the next character + internal mutating func skipRequiredObjectStart() throws { + try skipRequiredCharacter(asciiOpenCurlyBracket) // { + try incrementRecursionDepth() + } + + /// Skip ",", throw if that's not the next character + internal mutating func skipRequiredComma() throws { + try skipRequiredCharacter(asciiComma) + } + + /// Skip ":", throw if that's not the next character + internal mutating func skipRequiredColon() throws { + try skipRequiredCharacter(asciiColon) + } + + /// Skip "[", throw if that's not the next character + internal mutating func skipRequiredArrayStart() throws { + try skipRequiredCharacter(asciiOpenSquareBracket) // [ + } + + /// Helper for skipping optional single-character tokens + private mutating func skipOptionalCharacter(_ c: UInt8) -> Bool { + skipWhitespace() + if hasMoreContent && currentByte == c { + advance() + return true + } + return false + } + + /// If the next non-whitespace character is "]", skip it + /// and return true. Otherwise, return false. + internal mutating func skipOptionalArrayEnd() -> Bool { + return skipOptionalCharacter(asciiCloseSquareBracket) // ] + } + + /// If the next non-whitespace character is "}", skip it + /// and return true. Otherwise, return false. + internal mutating func skipOptionalObjectEnd() -> Bool { + let result = skipOptionalCharacter(asciiCloseCurlyBracket) // } + if result { + decrementRecursionDepth() + } + return result + } + + /// Return the next complete JSON structure as a string. + /// For example, this might return "true", or "123.456", + /// or "{\"foo\": 7, \"bar\": [8, 9]}" + /// + /// Used by Any to get the upcoming JSON value as a string. + /// Note: The value might be an object or array. + internal mutating func skip() throws -> String { + skipWhitespace() + let start = index + try skipValue() + if let s = utf8ToString(bytes: source, start: start, end: index) { + return s + } else { + throw JSONDecodingError.invalidUTF8 + } + } + + /// Advance index past the next value. This is used + /// by skip() and by unknown field handling. + private mutating func skipValue() throws { + skipWhitespace() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + switch currentByte { + case asciiDoubleQuote: // " begins a string + try skipString() + case asciiOpenCurlyBracket: // { begins an object + try skipObject() + case asciiOpenSquareBracket: // [ begins an array + try skipArray() + case asciiLowerN: // n must be null + if !skipOptionalKeyword(bytes: [ + asciiLowerN, asciiLowerU, asciiLowerL, asciiLowerL + ]) { + throw JSONDecodingError.truncated + } + case asciiLowerF: // f must be false + if !skipOptionalKeyword(bytes: [ + asciiLowerF, asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE + ]) { + throw JSONDecodingError.truncated + } + case asciiLowerT: // t must be true + if !skipOptionalKeyword(bytes: [ + asciiLowerT, asciiLowerR, asciiLowerU, asciiLowerE + ]) { + throw JSONDecodingError.truncated + } + default: // everything else is a number token + _ = try nextDouble() + } + } + + /// Advance the index past the next complete {...} construct. + private mutating func skipObject() throws { + try skipRequiredObjectStart() + if skipOptionalObjectEnd() { + return + } + while true { + skipWhitespace() + try skipString() + try skipRequiredColon() + try skipValue() + if skipOptionalObjectEnd() { + return + } + try skipRequiredComma() + } + } + + /// Advance the index past the next complete [...] construct. + private mutating func skipArray() throws { + try skipRequiredArrayStart() + if skipOptionalArrayEnd() { + return + } + while true { + try skipValue() + if skipOptionalArrayEnd() { + return + } + try skipRequiredComma() + } + } + + /// Advance the index past the next complete quoted string. + /// + // Caveat: This does not fully validate; it will accept + // strings that have malformed \ escapes. + // + // It would be nice to do better, but I don't think it's critical, + // since there are many reasons that strings (and other tokens for + // that matter) may be skippable but not parseable. For example: + // Old clients that don't know new field types will skip fields + // they don't know; newer clients may reject the same input due to + // schema mismatches or other issues. + private mutating func skipString() throws { + if currentByte != asciiDoubleQuote { + throw JSONDecodingError.malformedString + } + advance() + while hasMoreContent { + let c = currentByte + switch c { + case asciiDoubleQuote: + advance() + return + case asciiBackslash: + advance() + guard hasMoreContent else { + throw JSONDecodingError.truncated + } + advance() + default: + advance() + } + } + throw JSONDecodingError.truncated + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift new file mode 100644 index 0000000..6ae9b1c --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift @@ -0,0 +1,40 @@ +// Sources/SwiftProtobuf/MathUtils.swift - Generally useful mathematical functions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Generally useful mathematical and arithmetic functions. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Remainder in standard modular arithmetic (modulo). This coincides with (%) +/// when a > 0. +/// +/// - Parameters: +/// - a: The dividend. Can be positive, 0 or negative. +/// - b: The divisor. This must be positive, and is an error if 0 or negative. +/// - Returns: The unique value r such that 0 <= r < b and b * q + r = a for some q. +internal func mod(_ a: T, _ b: T) -> T { + assert(b > 0) + let r = a % b + return r >= 0 ? r : r + b +} + +/// Quotient in standard modular arithmetic (Euclidean division). This coincides +/// with (/) when a > 0. +/// +/// - Parameters: +/// - a: The dividend. Can be positive, 0 or negative. +/// - b: The divisor. This must be positive, and is an error if 0 or negative. +/// - Returns: The unique value q such that for some 0 <= r < b, b * q + r = a. +internal func div(_ a: T, _ b: T) -> T { + assert(b > 0) + return a >= 0 ? a / b : (a + 1) / b - 1 +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift new file mode 100644 index 0000000..7023d64 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift @@ -0,0 +1,45 @@ +// Sources/SwiftProtobuf/Message+AnyAdditions.swift - Any-related Message extensions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extends the `Message` type with `Google_Protobuf_Any`-specific behavior. +/// +// ----------------------------------------------------------------------------- + +extension Message { + /// Initialize this message from the provided `google.protobuf.Any` + /// well-known type. + /// + /// This corresponds to the `unpack` method in the Google C++ API. + /// + /// If the Any object was decoded from Protobuf Binary or JSON + /// format, then the enclosed field data was stored and is not + /// fully decoded until you unpack the Any object into a message. + /// As such, this method will typically need to perform a full + /// deserialization of the enclosed data and can fail for any + /// reason that deserialization can fail. + /// + /// See `Google_Protobuf_Any.unpackTo()` for more discussion. + /// + /// - Parameter unpackingAny: the message to decode. + /// - Parameter extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - Parameter options: The BinaryDecodingOptions to use. + /// - Throws: an instance of `AnyUnpackError`, `JSONDecodingError`, or + /// `BinaryDecodingError` on failure. + public init( + unpackingAny: Google_Protobuf_Any, + extensions: ExtensionMap? = nil, + options: BinaryDecodingOptions = BinaryDecodingOptions() + ) throws { + self.init() + try unpackingAny._storage.unpackTo(target: &self, extensions: extensions, options: options) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift new file mode 100644 index 0000000..dd57617 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift @@ -0,0 +1,126 @@ +// Sources/SwiftProtobuf/Message+BinaryAdditions.swift - Per-type binary coding +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extensions to `Message` to provide binary coding and decoding. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Binary encoding and decoding methods for messages. +extension Message { + /// Returns a `Data` value containing the Protocol Buffer binary format + /// serialization of the message. + /// + /// - Parameters: + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - Returns: A `Data` value containing the binary serialization of the + /// message. + /// - Throws: `BinaryEncodingError` if encoding fails. + public func serializedData(partial: Bool = false) throws -> Data { + if !partial && !isInitialized { + throw BinaryEncodingError.missingRequiredFields + } + let requiredSize = try serializedDataSize() + var data = Data(count: requiredSize) + try data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + + var visitor = BinaryEncodingVisitor(forWritingInto: pointer) + try traverse(visitor: &visitor) + // Currently not exposing this from the api because it really would be + // an internal error in the library and should never happen. + assert(requiredSize == visitor.encoder.distance(pointer: pointer)) + } + } + return data + } + + /// Returns the size in bytes required to encode the message in binary format. + /// This is used by `serializedData()` to precalculate the size of the buffer + /// so that encoding can proceed without bounds checks or reallocation. + internal func serializedDataSize() throws -> Int { + // Note: since this api is internal, it doesn't currently worry about + // needing a partial argument to handle proto2 syntax required fields. + // If this become public, it will need that added. + var visitor = BinaryEncodingSizeVisitor() + try traverse(visitor: &visitor) + return visitor.serializedSize + } + + /// Creates a new message by decoding the given `Data` value containing a + /// serialized message in Protocol Buffer binary format. + /// + /// - Parameters: + /// - serializedData: The binary-encoded message data to decode. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - options: The BinaryDecodingOptions to use. + /// - Throws: `BinaryDecodingError` if decoding fails. + public init( + serializedData data: Data, + extensions: ExtensionMap? = nil, + partial: Bool = false, + options: BinaryDecodingOptions = BinaryDecodingOptions() + ) throws { + self.init() + try merge(serializedData: data, extensions: extensions, partial: partial, options: options) + } + + /// Updates the message by decoding the given `Data` value containing a + /// serialized message in Protocol Buffer binary format into the receiver. + /// + /// - Note: If this method throws an error, the message may still have been + /// partially mutated by the binary data that was decoded before the error + /// occurred. + /// + /// - Parameters: + /// - serializedData: The binary-encoded message data to decode. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - partial: If `false` (the default), this method will check + /// `Message.isInitialized` before encoding to verify that all required + /// fields are present. If any are missing, this method throws + /// `BinaryEncodingError.missingRequiredFields`. + /// - options: The BinaryDecodingOptions to use. + /// - Throws: `BinaryDecodingError` if decoding fails. + public mutating func merge( + serializedData data: Data, + extensions: ExtensionMap? = nil, + partial: Bool = false, + options: BinaryDecodingOptions = BinaryDecodingOptions() + ) throws { + if !data.isEmpty { + try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) + var decoder = BinaryDecoder(forReadingFrom: pointer, + count: body.count, + options: options, + extensions: extensions) + try decoder.decodeFullMessage(message: &self) + } + } + } + if !partial && !isInitialized { + throw BinaryDecodingError.missingRequiredFields + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift new file mode 100644 index 0000000..4982d18 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift @@ -0,0 +1,117 @@ +// Sources/SwiftProtobuf/Message+JSONAdditions.swift - JSON format primitive types +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extensions to `Message` to support JSON encoding/decoding. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// JSON encoding and decoding methods for messages. +extension Message { + /// Returns a string containing the JSON serialization of the message. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to JSON. + /// + /// - Returns: A string containing the JSON serialization of the message. + /// - Parameters: + /// - options: The JSONEncodingOptions to use. + /// - Throws: `JSONEncodingError` if encoding fails. + public func jsonString( + options: JSONEncodingOptions = JSONEncodingOptions() + ) throws -> String { + let data = try jsonUTF8Data(options: options) + return String(data: data, encoding: String.Encoding.utf8)! + } + + /// Returns a Data containing the UTF-8 JSON serialization of the message. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to JSON. + /// + /// - Returns: A Data containing the JSON serialization of the message. + /// - Parameters: + /// - options: The JSONEncodingOptions to use. + /// - Throws: `JSONEncodingError` if encoding fails. + public func jsonUTF8Data( + options: JSONEncodingOptions = JSONEncodingOptions() + ) throws -> Data { + if let m = self as? _CustomJSONCodable { + let string = try m.encodedJSONString(options: options) + let data = string.data(using: String.Encoding.utf8)! // Cannot fail! + return data + } + var visitor = try JSONEncodingVisitor(message: self, options: options) + visitor.startObject() + try traverse(visitor: &visitor) + visitor.endObject() + return visitor.dataResult + } + + /// Creates a new message by decoding the given string containing a + /// serialized message in JSON format. + /// + /// - Parameter jsonString: The JSON-formatted string to decode. + /// - Parameter options: The JSONDecodingOptions to use. + /// - Throws: `JSONDecodingError` if decoding fails. + public init( + jsonString: String, + options: JSONDecodingOptions = JSONDecodingOptions() + ) throws { + if jsonString.isEmpty { + throw JSONDecodingError.truncated + } + if let data = jsonString.data(using: String.Encoding.utf8) { + try self.init(jsonUTF8Data: data, options: options) + } else { + throw JSONDecodingError.truncated + } + } + + /// Creates a new message by decoding the given `Data` containing a + /// serialized message in JSON format, interpreting the data as UTF-8 encoded + /// text. + /// + /// - Parameter jsonUTF8Data: The JSON-formatted data to decode, represented + /// as UTF-8 encoded text. + /// - Parameter options: The JSONDecodingOptions to use. + /// - Throws: `JSONDecodingError` if decoding fails. + public init( + jsonUTF8Data: Data, + options: JSONDecodingOptions = JSONDecodingOptions() + ) throws { + self.init() + try jsonUTF8Data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var decoder = JSONDecoder(source: buffer, options: options) + if !decoder.scanner.skipOptionalNull() { + try decoder.decodeFullObject(message: &self) + } else if Self.self is _CustomJSONCodable.Type { + if let message = try (Self.self as! _CustomJSONCodable.Type) + .decodedFromJSONNull() { + self = message as! Self + } else { + throw JSONDecodingError.illegalNull + } + } else { + throw JSONDecodingError.illegalNull + } + if !decoder.scanner.complete { + throw JSONDecodingError.trailingGarbage + } + } + } + } +} + diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift new file mode 100644 index 0000000..38bf9f3 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift @@ -0,0 +1,111 @@ +// Sources/SwiftProtobuf/Array+JSONAdditions.swift - JSON format primitive types +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extensions to `Array` to support JSON encoding/decoding. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// JSON encoding and decoding methods for arrays of messages. +extension Message { + /// Returns a string containing the JSON serialization of the messages. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to JSON. + /// + /// - Returns: A string containing the JSON serialization of the messages. + /// - Parameters: + /// - collection: The list of messages to encode. + /// - options: The JSONEncodingOptions to use. + /// - Throws: `JSONEncodingError` if encoding fails. + public static func jsonString( + from collection: C, + options: JSONEncodingOptions = JSONEncodingOptions() + ) throws -> String where C.Iterator.Element == Self { + let data = try jsonUTF8Data(from: collection, options: options) + return String(data: data, encoding: String.Encoding.utf8)! + } + + /// Returns a Data containing the UTF-8 JSON serialization of the messages. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to JSON. + /// + /// - Returns: A Data containing the JSON serialization of the messages. + /// - Parameters: + /// - collection: The list of messages to encode. + /// - options: The JSONEncodingOptions to use. + /// - Throws: `JSONEncodingError` if encoding fails. + public static func jsonUTF8Data( + from collection: C, + options: JSONEncodingOptions = JSONEncodingOptions() + ) throws -> Data where C.Iterator.Element == Self { + var visitor = try JSONEncodingVisitor(type: Self.self, options: options) + visitor.startArray() + for message in collection { + visitor.startObject() + try message.traverse(visitor: &visitor) + visitor.endObject() + } + visitor.endArray() + return visitor.dataResult + } + + /// Creates a new array of messages by decoding the given string containing a + /// serialized array of messages in JSON format. + /// + /// - Parameter jsonString: The JSON-formatted string to decode. + /// - Parameter options: The JSONDecodingOptions to use. + /// - Throws: `JSONDecodingError` if decoding fails. + public static func array( + fromJSONString jsonString: String, + options: JSONDecodingOptions = JSONDecodingOptions() + ) throws -> [Self] { + if jsonString.isEmpty { + throw JSONDecodingError.truncated + } + if let data = jsonString.data(using: String.Encoding.utf8) { + return try array(fromJSONUTF8Data: data, options: options) + } else { + throw JSONDecodingError.truncated + } + } + + /// Creates a new array of messages by decoding the given `Data` containing a + /// serialized array of messages in JSON format, interpreting the data as + /// UTF-8 encoded text. + /// + /// - Parameter jsonUTF8Data: The JSON-formatted data to decode, represented + /// as UTF-8 encoded text. + /// - Parameter options: The JSONDecodingOptions to use. + /// - Throws: `JSONDecodingError` if decoding fails. + public static func array( + fromJSONUTF8Data jsonUTF8Data: Data, + options: JSONDecodingOptions = JSONDecodingOptions() + ) throws -> [Self] { + return try jsonUTF8Data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + var array = [Self]() + + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + let buffer = UnsafeBufferPointer(start: bytes, count: body.count) + var decoder = JSONDecoder(source: buffer, options: options) + try decoder.decodeRepeatedMessageField(value: &array) + if !decoder.scanner.complete { + throw JSONDecodingError.trailingGarbage + } + } + + return array + } + } + +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift new file mode 100644 index 0000000..19b8370 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift @@ -0,0 +1,89 @@ +// Sources/SwiftProtobuf/Message+TextFormatAdditions.swift - Text format primitive types +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Extensions to `Message` to support text format encoding/decoding. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Text format encoding and decoding methods for messages. +extension Message { + /// Returns a string containing the Protocol Buffer text format serialization + /// of the message. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to text format. + /// + /// - Returns: A string containing the text format serialization of the + /// message. + public func textFormatString() -> String { + // This is implemented as a separate zero-argument function + // to preserve binary compatibility. + return textFormatString(options: TextFormatEncodingOptions()) + } + + /// Returns a string containing the Protocol Buffer text format serialization + /// of the message. + /// + /// Unlike binary encoding, presence of required fields is not enforced when + /// serializing to JSON. + /// + /// - Returns: A string containing the text format serialization of the message. + /// - Parameters: + /// - options: The TextFormatEncodingOptions to use. + public func textFormatString( + options: TextFormatEncodingOptions + ) -> String { + var visitor = TextFormatEncodingVisitor(message: self, options: options) + if let any = self as? Google_Protobuf_Any { + any._storage.textTraverse(visitor: &visitor) + } else { + // Although the general traversal/encoding infrastructure supports + // throwing errors (needed for JSON/Binary WKTs support, binary format + // missing required fields); TextEncoding never actually does throw. + try! traverse(visitor: &visitor) + } + return visitor.result + } + + /// Creates a new message by decoding the given string containing a + /// serialized message in Protocol Buffer text format. + /// + /// - Parameters: + /// - textFormatString: The text format string to decode. + /// - extensions: An `ExtensionMap` used to look up and decode any + /// extensions in this message or messages nested within this message's + /// fields. + /// - Throws: an instance of `TextFormatDecodingError` on failure. + public init( + textFormatString: String, + extensions: ExtensionMap? = nil + ) throws { + self.init() + if !textFormatString.isEmpty { + if let data = textFormatString.data(using: String.Encoding.utf8) { + try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) + var decoder = try TextFormatDecoder(messageType: Self.self, + utf8Pointer: bytes, + count: body.count, + extensions: extensions) + try decodeMessage(decoder: &decoder) + if !decoder.complete { + throw TextFormatDecodingError.trailingGarbage + } + } + } + } + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift new file mode 100644 index 0000000..b6b9b3b --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift @@ -0,0 +1,216 @@ +// Sources/SwiftProtobuf/Message.swift - Message support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// + +/// The protocol which all generated protobuf messages implement. +/// `Message` is the protocol type you should use whenever +/// you need an argument or variable which holds "some message". +/// +/// Generated messages also implement `Hashable`, and thus `Equatable`. +/// However, the protocol conformance is declared on a different protocol. +/// This allows you to use `Message` as a type directly: +/// +/// func consume(message: Message) { ... } +/// +/// Instead of needing to use it as a type constraint on a generic declaration: +/// +/// func consume(message: M) { ... } +/// +/// If you need to convince the compiler that your message is `Hashable` so +/// you can insert it into a `Set` or use it as a `Dictionary` key, use +/// a generic declaration with a type constraint: +/// +/// func insertIntoSet(message: M) { +/// mySet.insert(message) +/// } +/// +/// The actual functionality is implemented either in the generated code or in +/// default implementations of the below methods and properties. +public protocol Message: CustomDebugStringConvertible { + /// Creates a new message with all of its fields initialized to their default + /// values. + init() + + // Metadata + // Basic facts about this class and the proto message it was generated from + // Used by various encoders and decoders + + /// The fully-scoped name of the message from the original .proto file, + /// including any relevant package name. + static var protoMessageName: String { get } + + /// True if all required fields (if any) on this message and any nested + /// messages (recursively) have values set; otherwise, false. + var isInitialized: Bool { get } + + /// Some formats include enough information to transport fields that were + /// not known at generation time. When encountered, they are stored here. + var unknownFields: UnknownStorage { get set } + + // + // General serialization/deserialization machinery + // + + /// Decode all of the fields from the given decoder. + /// + /// This is a simple loop that repeatedly gets the next field number + /// from `decoder.nextFieldNumber()` and then uses the number returned + /// and the type information from the original .proto file to decide + /// what type of data should be decoded for that field. The corresponding + /// method on the decoder is then called to get the field value. + /// + /// This is the core method used by the deserialization machinery. It is + /// `public` to enable users to implement their own encoding formats by + /// conforming to `Decoder`; it should not be called otherwise. + /// + /// Note that this is not specific to binary encodng; formats that use + /// textual identifiers translate those to field numbers and also go + /// through this to decode messages. + /// + /// - Parameters: + /// - decoder: a `Decoder`; the `Message` will call the method + /// corresponding to the type of this field. + /// - Throws: an error on failure or type mismatch. The type of error + /// thrown depends on which decoder is used. + mutating func decodeMessage(decoder: inout D) throws + + /// Traverses the fields of the message, calling the appropriate methods + /// of the passed `Visitor` object. + /// + /// This is used internally by: + /// + /// * Protobuf binary serialization + /// * JSON serialization (with some twists to account for specialty JSON) + /// * Protobuf Text serialization + /// * `Hashable` computation + /// + /// Conceptually, serializers create visitor objects that are + /// then passed recursively to every message and field via generated + /// `traverse` methods. The details get a little involved due to + /// the need to allow particular messages to override particular + /// behaviors for specific encodings, but the general idea is quite simple. + func traverse(visitor: inout V) throws + + // Standard utility properties and methods. + // Most of these are simple wrappers on top of the visitor machinery. + // They are implemented in the protocol, not in the generated structs, + // so can be overridden in user code by defining custom extensions to + // the generated struct. + +#if swift(>=4.2) + /// An implementation of hash(into:) to provide conformance with the + /// `Hashable` protocol. + func hash(into hasher: inout Hasher) +#else // swift(>=4.2) + /// The hash value generated from this message's contents, for conformance + /// with the `Hashable` protocol. + var hashValue: Int { get } +#endif // swift(>=4.2) + + /// Helper to compare `Message`s when not having a specific type to use + /// normal `Equatable`. `Equatable` is provided with specific generated + /// types. + func isEqualTo(message: Message) -> Bool +} + +extension Message { + /// Generated proto2 messages that contain required fields, nested messages + /// that contain required fields, and/or extensions will provide their own + /// implementation of this property that tests that all required fields are + /// set. Users of the generated code SHOULD NOT override this property. + public var isInitialized: Bool { + // The generated code will include a specialization as needed. + return true + } + + /// A hash based on the message's full contents. +#if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + var visitor = HashVisitor(hasher) + try? traverse(visitor: &visitor) + hasher = visitor.hasher + } +#else // swift(>=4.2) + public var hashValue: Int { + var visitor = HashVisitor() + try? traverse(visitor: &visitor) + return visitor.hashValue + } +#endif // swift(>=4.2) + + /// A description generated by recursively visiting all fields in the message, + /// including messages. + public var debugDescription: String { + // TODO Ideally there would be something like serializeText() that can + // take a prefix so we could do something like: + // [class name]( + // [text format] + // ) + let className = String(reflecting: type(of: self)) + let header = "\(className):\n" + return header + textFormatString() + } + + /// Creates an instance of the message type on which this method is called, + /// executes the given block passing the message in as its sole `inout` + /// argument, and then returns the message. + /// + /// This method acts essentially as a "builder" in that the initialization of + /// the message is captured within the block, allowing the returned value to + /// be set in an immutable variable. For example, + /// + /// let msg = MyMessage.with { $0.myField = "foo" } + /// msg.myOtherField = 5 // error: msg is immutable + /// + /// - Parameter populator: A block or function that populates the new message, + /// which is passed into the block as an `inout` argument. + /// - Returns: The message after execution of the block. + public static func with( + _ populator: (inout Self) throws -> () + ) rethrows -> Self { + var message = Self() + try populator(&message) + return message + } +} + +/// Implementation base for all messages; not intended for client use. +/// +/// In general, use `SwiftProtobuf.Message` instead when you need a variable or +/// argument that can hold any type of message. Occasionally, you can use +/// `SwiftProtobuf.Message & Equatable` or `SwiftProtobuf.Message & Hashable` as +/// generic constraints if you need to write generic code that can be applied to +/// multiple message types that uses equality tests, puts messages in a `Set`, +/// or uses them as `Dictionary` keys. +public protocol _MessageImplementationBase: Message, Hashable { + + // Legacy function; no longer used, but left to maintain source compatibility. + func _protobuf_generated_isEqualTo(other: Self) -> Bool +} + +extension _MessageImplementationBase { + public func isEqualTo(message: Message) -> Bool { + guard let other = message as? Self else { + return false + } + return self == other + } + + // Legacy default implementation that is used by old generated code, current + // versions of the plugin/generator provide this directly, but this is here + // just to avoid breaking source compatibility. + public static func ==(lhs: Self, rhs: Self) -> Bool { + return lhs._protobuf_generated_isEqualTo(other: rhs) + } + + // Legacy function that is generated by old versions of the plugin/generator, + // defaulted to keep things simple without changing the api surface. + public func _protobuf_generated_isEqualTo(other: Self) -> Bool { + return self == other + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift new file mode 100644 index 0000000..42c75da --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift @@ -0,0 +1,41 @@ +// Sources/SwiftProtobuf/MessageExtension.swift - Extension support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A 'Message Extension' is an immutable class object that describes +/// a particular extension field, including string and number +/// identifiers, serialization details, and the identity of the +/// message that is being extended. +/// +// ----------------------------------------------------------------------------- + +/// Type-erased MessageExtension field implementation. +public protocol AnyMessageExtension { + var fieldNumber: Int { get } + var fieldName: String { get } + var messageType: Message.Type { get } + func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? +} + +/// A "Message Extension" relates a particular extension field to +/// a particular message. The generic constraints allow +/// compile-time compatibility checks. +public class MessageExtension: AnyMessageExtension { + public let fieldNumber: Int + public let fieldName: String + public let messageType: Message.Type + public init(_protobuf_fieldNumber: Int, fieldName: String) { + self.fieldNumber = _protobuf_fieldNumber + self.fieldName = fieldName + self.messageType = MessageType.self + } + public func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? { + return try FieldType(protobufExtension: self, decoder: &decoder) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift new file mode 100644 index 0000000..3405ebe --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift @@ -0,0 +1,286 @@ +// Sources/SwiftProtobuf/NameMap.swift - Bidirectional number/name mapping +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- + +/// TODO: Right now, only the NameMap and the NameDescription enum +/// (which are directly used by the generated code) are public. +/// This means that code outside the library has no way to actually +/// use this data. We should develop and publicize a suitable API +/// for that purpose. (Which might be the same as the internal API.) + +/// This must be exactly the same as the corresponding code in the +/// protoc-gen-swift code generator. Changing it will break +/// compatibility of the library with older generated code. +/// +/// It does not necessarily need to match protoc's JSON field naming +/// logic, however. +private func toJsonFieldName(_ s: String) -> String { + var result = String() + var capitalizeNext = false + for c in s { + if c == "_" { + capitalizeNext = true + } else if capitalizeNext { + result.append(String(c).uppercased()) + capitalizeNext = false + } else { + result.append(String(c)) + } + } + return result +} + +/// Allocate static memory buffers to intern UTF-8 +/// string data. Track the buffers and release all of those buffers +/// in case we ever get deallocated. +fileprivate class InternPool { + private var interned = [UnsafeBufferPointer]() + + func intern(utf8: String.UTF8View) -> UnsafeBufferPointer { + let bytePointer = UnsafeMutablePointer.allocate(capacity: utf8.count) + let mutable = UnsafeMutableBufferPointer(start: bytePointer, count: utf8.count) + _ = mutable.initialize(from: utf8) + let immutable = UnsafeBufferPointer(start: bytePointer, count: utf8.count) + interned.append(immutable) + return immutable + } + + deinit { + for buff in interned { + #if swift(>=4.1) + buff.deallocate() + #else + let p = UnsafeMutableRawPointer(mutating: buff.baseAddress)! + p.deallocate(bytes: buff.count, alignedTo: 1) + #endif + } + } +} + +#if !swift(>=4.2) +// Constants for FNV hash http://tools.ietf.org/html/draft-eastlake-fnv-03 +private let i_2166136261 = Int(bitPattern: 2166136261) +private let i_16777619 = Int(16777619) +#endif + +/// An immutable bidirectional mapping between field/enum-case names +/// and numbers, used to record field names for text-based +/// serialization (JSON and text). These maps are lazily instantiated +/// for each message as needed, so there is no run-time overhead for +/// users who do not use text-based serialization formats. +public struct _NameMap: ExpressibleByDictionaryLiteral { + + /// An immutable interned string container. The `utf8Start` pointer + /// is guaranteed valid for the lifetime of the `NameMap` that you + /// fetched it from. Since `NameMap`s are only instantiated as + /// immutable static values, that should be the lifetime of the + /// program. + /// + /// Internally, this uses `StaticString` (which refers to a fixed + /// block of UTF-8 data) where possible. In cases where the string + /// has to be computed, it caches the UTF-8 bytes in an + /// unmovable and immutable heap area. + internal struct Name: Hashable, CustomStringConvertible { + // This is safe to use elsewhere in this library + internal init(staticString: StaticString) { + self.nameString = .staticString(staticString) + self.utf8Buffer = UnsafeBufferPointer(start: staticString.utf8Start, count: staticString.utf8CodeUnitCount) + } + + // This should not be used outside of this file, as it requires + // coordinating the lifecycle with the lifecycle of the pool + // where the raw UTF8 gets interned. + fileprivate init(string: String, pool: InternPool) { + let utf8 = string.utf8 + self.utf8Buffer = pool.intern(utf8: utf8) + self.nameString = .string(string) + } + + // This is for building a transient `Name` object sufficient for lookup purposes. + // It MUST NOT be exposed outside of this file. + fileprivate init(transientUtf8Buffer: UnsafeBufferPointer) { + self.nameString = .staticString("") + self.utf8Buffer = transientUtf8Buffer + } + + private(set) var utf8Buffer: UnsafeBufferPointer + + private enum NameString { + case string(String) + case staticString(StaticString) + } + private var nameString: NameString + + public var description: String { + switch nameString { + case .string(let s): return s + case .staticString(let s): return s.description + } + } + + #if swift(>=4.2) + public func hash(into hasher: inout Hasher) { + for byte in utf8Buffer { + hasher.combine(byte) + } + } + #else // swift(>=4.2) + public var hashValue: Int { + var h = i_2166136261 + for byte in utf8Buffer { + h = (h ^ Int(byte)) &* i_16777619 + } + return h + } + #endif // swift(>=4.2) + + public static func ==(lhs: Name, rhs: Name) -> Bool { + if lhs.utf8Buffer.count != rhs.utf8Buffer.count { + return false + } + return lhs.utf8Buffer.elementsEqual(rhs.utf8Buffer) + } + } + + /// The JSON and proto names for a particular field, enum case, or extension. + internal struct Names { + private(set) var json: Name? + private(set) var proto: Name + } + + /// A description of the names for a particular field or enum case. + /// The different forms here let us minimize the amount of string + /// data that we store in the binary. + /// + /// These are only used in the generated code to initialize a NameMap. + public enum NameDescription { + + /// The proto (text format) name and the JSON name are the same string. + case same(proto: StaticString) + + /// The JSON name can be computed from the proto string + case standard(proto: StaticString) + + /// The JSON and text format names are just different. + case unique(proto: StaticString, json: StaticString) + + /// Used for enum cases only to represent a value's primary proto name (the + /// first defined case) and its aliases. The JSON and text format names for + /// enums are always the same. + case aliased(proto: StaticString, aliases: [StaticString]) + } + + private var internPool = InternPool() + + /// The mapping from field/enum-case numbers to names. + private var numberToNameMap: [Int: Names] = [:] + + /// The mapping from proto/text names to field/enum-case numbers. + private var protoToNumberMap: [Name: Int] = [:] + + /// The mapping from JSON names to field/enum-case numbers. + /// Note that this also contains all of the proto/text names, + /// as required by Google's spec for protobuf JSON. + private var jsonToNumberMap: [Name: Int] = [:] + + /// Creates a new empty field/enum-case name/number mapping. + public init() {} + + /// Build the bidirectional maps between numbers and proto/JSON names. + public init(dictionaryLiteral elements: (Int, NameDescription)...) { + for (number, description) in elements { + switch description { + + case .same(proto: let p): + let protoName = Name(staticString: p) + let names = Names(json: protoName, proto: protoName) + numberToNameMap[number] = names + protoToNumberMap[protoName] = number + jsonToNumberMap[protoName] = number + + case .standard(proto: let p): + let protoName = Name(staticString: p) + let jsonString = toJsonFieldName(protoName.description) + let jsonName = Name(string: jsonString, pool: internPool) + let names = Names(json: jsonName, proto: protoName) + numberToNameMap[number] = names + protoToNumberMap[protoName] = number + jsonToNumberMap[protoName] = number + jsonToNumberMap[jsonName] = number + + case .unique(proto: let p, json: let j): + let jsonName = Name(staticString: j) + let protoName = Name(staticString: p) + let names = Names(json: jsonName, proto: protoName) + numberToNameMap[number] = names + protoToNumberMap[protoName] = number + jsonToNumberMap[protoName] = number + jsonToNumberMap[jsonName] = number + + case .aliased(proto: let p, aliases: let aliases): + let protoName = Name(staticString: p) + let names = Names(json: protoName, proto: protoName) + numberToNameMap[number] = names + protoToNumberMap[protoName] = number + jsonToNumberMap[protoName] = number + for alias in aliases { + let protoName = Name(staticString: alias) + protoToNumberMap[protoName] = number + jsonToNumberMap[protoName] = number + } + } + } + } + + /// Returns the name bundle for the field/enum-case with the given number, or + /// `nil` if there is no match. + internal func names(for number: Int) -> Names? { + return numberToNameMap[number] + } + + /// Returns the field/enum-case number that has the given JSON name, + /// or `nil` if there is no match. + /// + /// This is used by the Text format parser to look up field or enum + /// names using a direct reference to the un-decoded UTF8 bytes. + internal func number(forProtoName raw: UnsafeBufferPointer) -> Int? { + let n = Name(transientUtf8Buffer: raw) + return protoToNumberMap[n] + } + + /// Returns the field/enum-case number that has the given JSON name, + /// or `nil` if there is no match. + /// + /// This accepts a regular `String` and is used in JSON parsing + /// only when a field name or enum name was decoded from a string + /// containing backslash escapes. + /// + /// JSON parsing must interpret *both* the JSON name of the + /// field/enum-case provided by the descriptor *as well as* its + /// original proto/text name. + internal func number(forJSONName name: String) -> Int? { + let utf8 = Array(name.utf8) + return utf8.withUnsafeBufferPointer { (buffer: UnsafeBufferPointer) in + let n = Name(transientUtf8Buffer: buffer) + return jsonToNumberMap[n] + } + } + + /// Returns the field/enum-case number that has the given JSON name, + /// or `nil` if there is no match. + /// + /// This is used by the JSON parser when a field name or enum name + /// required no special processing. As a result, we can avoid + /// copying the name and look up the number using a direct reference + /// to the un-decoded UTF8 bytes. + internal func number(forJSONName raw: UnsafeBufferPointer) -> Int? { + let n = Name(transientUtf8Buffer: raw) + return jsonToNumberMap[n] + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift new file mode 100644 index 0000000..42ed9b4 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift @@ -0,0 +1,23 @@ +// Sources/SwiftProtobuf/ProtoNameProviding.swift - Support for accessing proto names +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- + + +/// SwiftProtobuf Internal: Common support looking up field names. +/// +/// Messages conform to this protocol to provide the proto/text and JSON field +/// names for their fields. This allows these names to be pulled out into +/// extensions in separate files so that users can omit them in release builds +/// (reducing bloat and minimizing leaks of field names). +public protocol _ProtoNameProviding { + + /// The mapping between field numbers and proto/JSON field names defined in + /// the conforming message type. + static var _protobuf_nameMap: _NameMap { get } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift new file mode 100644 index 0000000..eed776e --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift @@ -0,0 +1,43 @@ +// Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift - Version checking +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A scheme that ensures that generated protos cannot be compiled or linked +/// against a version of the runtime with which they are not compatible. +/// +/// In many cases, API changes themselves might introduce incompatibilities +/// between generated code and the runtime library, but we also want to protect +/// against cases where breaking behavioral changes (without affecting the API) +/// would cause generated code to be incompatible with a particular version of +/// the runtime. +/// +// ----------------------------------------------------------------------------- + + +/// An empty protocol that encodes the version of the runtime library. +/// +/// This protocol will be replaced with one containing a different version +/// number any time that breaking changes are made to the Swift Protobuf API. +/// Combined with the protocol below, this lets us verify that generated code is +/// never compiled against a version of the API with which it is incompatible. +/// +/// The version associated with a particular build of the compiler is defined as +/// `Version.compatibilityVersion` in `protoc-gen-swift`. That version and this +/// version must match for the generated protos to be compatible, so if you +/// update one, make sure to update it here and in the associated type below. +public protocol ProtobufAPIVersion_2 {} + +/// This protocol is expected to be implemented by a `fileprivate` type in each +/// source file emitted by `protoc-gen-swift`. It effectively creates a binding +/// between the version of the generated code and the version of this library, +/// causing a compile-time error (with reasonable diagnostics) if they are +/// incompatible. +public protocol ProtobufAPIVersionCheck { + associatedtype Version: ProtobufAPIVersion_2 +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift new file mode 100644 index 0000000..911ff8b --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift @@ -0,0 +1,39 @@ +// Sources/SwiftProtobuf/ProtobufMap.swift - Map<> support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Generic type representing proto map<> fields. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// SwiftProtobuf Internal: Support for Encoding/Decoding. +public struct _ProtobufMap +{ + public typealias Key = KeyType.BaseType + public typealias Value = ValueType.BaseType + public typealias BaseType = Dictionary +} + +/// SwiftProtobuf Internal: Support for Encoding/Decoding. +public struct _ProtobufMessageMap +{ + public typealias Key = KeyType.BaseType + public typealias Value = ValueType + public typealias BaseType = Dictionary +} + +/// SwiftProtobuf Internal: Support for Encoding/Decoding. +public struct _ProtobufEnumMap +{ + public typealias Key = KeyType.BaseType + public typealias Value = ValueType + public typealias BaseType = Dictionary +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift new file mode 100644 index 0000000..f6fc5d7 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift @@ -0,0 +1,268 @@ +// Sources/SwiftProtobuf/SelectiveVisitor.swift - Base for custom Visitors +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A base for Visitors that only expect a subset of things to called. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// A base for Visitors that only expects a subset of things to called. +internal protocol SelectiveVisitor: Visitor { + // Adds nothing. +} + +/// Default impls for everything so things using this only have to write the +/// methods they expect. Asserts to catch developer errors, but becomes +/// nothing in release to keep code size small. +/// +/// NOTE: This is an impl for *everything*. This means the default impls +/// provided by Visitor to bridge packed->repeated, repeated->singular, etc +/// won't kick in. +extension SelectiveVisitor { + internal mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int) throws { + assert(false) + } + + internal mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int + ) throws where ValueType.RawValue == Int { + assert(false) + } + + internal mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int + ) throws { + assert(false) + } + + internal mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { + assert(false) + } + + internal mutating func visitExtensionFieldsAsMessageSet( + fields: ExtensionFieldValueSet, + start: Int, + end: Int + ) throws { + assert(false) + } + + internal mutating func visitUnknown(bytes: Data) throws { + assert(false) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift new file mode 100644 index 0000000..986a8c3 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift @@ -0,0 +1,112 @@ +// Sources/SwiftProtobuf/SimpleExtensionMap.swift - Extension support +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A default implementation of ExtensionMap. +/// +// ----------------------------------------------------------------------------- + + +// Note: The generated code only relies on ExpressibleByArrayLiteral +public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral, CustomDebugStringConvertible { + public typealias Element = AnyMessageExtension + + // Since type objects aren't Hashable, we can't do much better than this... + internal var fields = [Int: Array]() + + public init() {} + + public init(arrayLiteral: Element...) { + insert(contentsOf: arrayLiteral) + } + + public init(_ others: SimpleExtensionMap...) { + for other in others { + formUnion(other) + } + } + + public subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { + get { + if let l = fields[fieldNumber] { + for e in l { + if messageType == e.messageType { + return e + } + } + } + return nil + } + } + + public func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? { + // TODO: Make this faster... + for (_, list) in fields { + for e in list { + if e.fieldName == protoFieldName && e.messageType == messageType { + return e.fieldNumber + } + } + } + return nil + } + + public mutating func insert(_ newValue: Element) { + let fieldNumber = newValue.fieldNumber + if let l = fields[fieldNumber] { + let messageType = newValue.messageType + var newL = l.filter { return $0.messageType != messageType } + newL.append(newValue) + fields[fieldNumber] = newL + } else { + fields[fieldNumber] = [newValue] + } + } + + public mutating func insert(contentsOf: [Element]) { + for e in contentsOf { + insert(e) + } + } + + public mutating func formUnion(_ other: SimpleExtensionMap) { + for (fieldNumber, otherList) in other.fields { + if let list = fields[fieldNumber] { + var newList = list.filter { + for o in otherList { + if $0.messageType == o.messageType { return false } + } + return true + } + newList.append(contentsOf: otherList) + fields[fieldNumber] = newList + } else { + fields[fieldNumber] = otherList + } + } + } + + public func union(_ other: SimpleExtensionMap) -> SimpleExtensionMap { + var out = self + out.formUnion(other) + return out + } + + public var debugDescription: String { + var names = [String]() + for (_, list) in fields { + for e in list { + names.append("\(e.fieldName):(\(e.fieldNumber))") + } + } + let d = names.joined(separator: ",") + return "SimpleExtensionMap(\(d))" + } + +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift new file mode 100644 index 0000000..d799e72 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift @@ -0,0 +1,73 @@ +// Sources/SwiftProtobuf/StringUtils.swift - String utility functions +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Utility functions for converting UTF8 bytes into Strings. +/// These functions must: +/// * Accept any valid UTF8, including a zero byte (which is +/// a valid UTF8 encoding of U+0000) +/// * Return nil for any invalid UTF8 +/// * Be fast (since they're extensively used by all decoders +/// and even some of the encoders) +/// +// ----------------------------------------------------------------------------- + +import Foundation + +// Wrapper that takes a buffer and start/end offsets +internal func utf8ToString( + bytes: UnsafeBufferPointer, + start: UnsafeBufferPointer.Index, + end: UnsafeBufferPointer.Index +) -> String? { + return utf8ToString(bytes: bytes.baseAddress! + start, count: end - start) +} + + +// Swift 4 introduced new faster String facilities +// that seem to work consistently across all platforms. + +// Notes on performance: +// +// The pre-verification here only takes about 10% of +// the time needed for constructing the string. +// Eliminating it would provide only a very minor +// speed improvement. +// +// On macOS, this is only about 25% faster than +// the Foundation initializer used below for Swift 3. +// On Linux, the Foundation initializer is much +// slower than on macOS, so this is a much bigger +// win there. +internal func utf8ToString(bytes: UnsafePointer, count: Int) -> String? { + if count == 0 { + return String() + } + let codeUnits = UnsafeBufferPointer(start: bytes, count: count) + let sourceEncoding = Unicode.UTF8.self + + // Verify that the UTF-8 is valid. + var p = sourceEncoding.ForwardParser() + var i = codeUnits.makeIterator() + Loop: + while true { + switch p.parseScalar(from: &i) { + case .valid(_): + break + case .error: + return nil + case .emptyInput: + break Loop + } + } + + // This initializer is fast but does not reject broken + // UTF-8 (which is why we validate the UTF-8 above). + return String(decoding: codeUnits, as: sourceEncoding) + } diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift new file mode 100644 index 0000000..bc8176a --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift @@ -0,0 +1,713 @@ +// Sources/SwiftProtobuf/TextFormatDecoder.swift - Text format decoding +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Test format decoding engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// +/// Provides a higher-level interface to the token stream coming +/// from a TextFormatScanner. In particular, this provides +/// single-token pushback and convenience functions for iterating +/// over complex structures. +/// +internal struct TextFormatDecoder: Decoder { + internal var scanner: TextFormatScanner + private var fieldCount = 0 + private var terminator: UInt8? + private var fieldNameMap: _NameMap? + private var messageType: Message.Type? + + internal var complete: Bool { + mutating get { + return scanner.complete + } + } + + internal init(messageType: Message.Type, utf8Pointer: UnsafePointer, count: Int, extensions: ExtensionMap?) throws { + scanner = TextFormatScanner(utf8Pointer: utf8Pointer, count: count, extensions: extensions) + guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { + throw TextFormatDecodingError.missingFieldNames + } + fieldNameMap = nameProviding._protobuf_nameMap + self.messageType = messageType + } + + internal init(messageType: Message.Type, scanner: TextFormatScanner, terminator: UInt8?) throws { + self.scanner = scanner + self.terminator = terminator + guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { + throw TextFormatDecodingError.missingFieldNames + } + fieldNameMap = nameProviding._protobuf_nameMap + self.messageType = messageType + } + + + mutating func handleConflictingOneOf() throws { + throw TextFormatDecodingError.conflictingOneOf + } + + mutating func nextFieldNumber() throws -> Int? { + if let terminator = terminator { + if scanner.skipOptionalObjectEnd(terminator) { + return nil + } + } + if fieldCount > 0 { + scanner.skipOptionalSeparator() + } + if let key = try scanner.nextOptionalExtensionKey() { + // Extension key; look up in the extension registry + if let fieldNumber = scanner.extensions?.fieldNumberForProto(messageType: messageType!, protoFieldName: key) { + fieldCount += 1 + return fieldNumber + } else { + throw TextFormatDecodingError.unknownField + } + } else if let fieldNumber = try scanner.nextFieldNumber(names: fieldNameMap!) { + fieldCount += 1 + return fieldNumber + } else if terminator == nil { + return nil + } else { + throw TextFormatDecodingError.truncated + } + + } + + mutating func decodeSingularFloatField(value: inout Float) throws { + try scanner.skipRequiredColon() + value = try scanner.nextFloat() + } + mutating func decodeSingularFloatField(value: inout Float?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextFloat() + } + mutating func decodeRepeatedFloatField(value: inout [Float]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextFloat() + value.append(n) + } + } else { + let n = try scanner.nextFloat() + value.append(n) + } + } + mutating func decodeSingularDoubleField(value: inout Double) throws { + try scanner.skipRequiredColon() + value = try scanner.nextDouble() + } + mutating func decodeSingularDoubleField(value: inout Double?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextDouble() + } + mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextDouble() + value.append(n) + } + } else { + let n = try scanner.nextDouble() + value.append(n) + } + } + mutating func decodeSingularInt32Field(value: inout Int32) throws { + try scanner.skipRequiredColon() + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw TextFormatDecodingError.malformedNumber + } + value = Int32(truncatingIfNeeded: n) + } + mutating func decodeSingularInt32Field(value: inout Int32?) throws { + try scanner.skipRequiredColon() + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw TextFormatDecodingError.malformedNumber + } + value = Int32(truncatingIfNeeded: n) + } + mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw TextFormatDecodingError.malformedNumber + } + value.append(Int32(truncatingIfNeeded: n)) + } + } else { + let n = try scanner.nextSInt() + if n > Int64(Int32.max) || n < Int64(Int32.min) { + throw TextFormatDecodingError.malformedNumber + } + value.append(Int32(truncatingIfNeeded: n)) + } + } + mutating func decodeSingularInt64Field(value: inout Int64) throws { + try scanner.skipRequiredColon() + value = try scanner.nextSInt() + } + mutating func decodeSingularInt64Field(value: inout Int64?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextSInt() + } + mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextSInt() + value.append(n) + } + } else { + let n = try scanner.nextSInt() + value.append(n) + } + } + mutating func decodeSingularUInt32Field(value: inout UInt32) throws { + try scanner.skipRequiredColon() + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw TextFormatDecodingError.malformedNumber + } + value = UInt32(truncatingIfNeeded: n) + } + mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { + try scanner.skipRequiredColon() + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw TextFormatDecodingError.malformedNumber + } + value = UInt32(truncatingIfNeeded: n) + } + mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw TextFormatDecodingError.malformedNumber + } + value.append(UInt32(truncatingIfNeeded: n)) + } + } else { + let n = try scanner.nextUInt() + if n > UInt64(UInt32.max) { + throw TextFormatDecodingError.malformedNumber + } + value.append(UInt32(truncatingIfNeeded: n)) + } + } + mutating func decodeSingularUInt64Field(value: inout UInt64) throws { + try scanner.skipRequiredColon() + value = try scanner.nextUInt() + } + mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextUInt() + } + mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextUInt() + value.append(n) + } + } else { + let n = try scanner.nextUInt() + value.append(n) + } + } + mutating func decodeSingularSInt32Field(value: inout Int32) throws { + try decodeSingularInt32Field(value: &value) + } + mutating func decodeSingularSInt32Field(value: inout Int32?) throws { + try decodeSingularInt32Field(value: &value) + } + mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { + try decodeRepeatedInt32Field(value: &value) + } + mutating func decodeSingularSInt64Field(value: inout Int64) throws { + try decodeSingularInt64Field(value: &value) + } + mutating func decodeSingularSInt64Field(value: inout Int64?) throws { + try decodeSingularInt64Field(value: &value) + } + mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { + try decodeRepeatedInt64Field(value: &value) + } + mutating func decodeSingularFixed32Field(value: inout UInt32) throws { + try decodeSingularUInt32Field(value: &value) + } + mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { + try decodeSingularUInt32Field(value: &value) + } + mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { + try decodeRepeatedUInt32Field(value: &value) + } + mutating func decodeSingularFixed64Field(value: inout UInt64) throws { + try decodeSingularUInt64Field(value: &value) + } + mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { + try decodeSingularUInt64Field(value: &value) + } + mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { + try decodeRepeatedUInt64Field(value: &value) + } + mutating func decodeSingularSFixed32Field(value: inout Int32) throws { + try decodeSingularInt32Field(value: &value) + } + mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { + try decodeSingularInt32Field(value: &value) + } + mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { + try decodeRepeatedInt32Field(value: &value) + } + mutating func decodeSingularSFixed64Field(value: inout Int64) throws { + try decodeSingularInt64Field(value: &value) + } + mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { + try decodeSingularInt64Field(value: &value) + } + mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { + try decodeRepeatedInt64Field(value: &value) + } + mutating func decodeSingularBoolField(value: inout Bool) throws { + try scanner.skipRequiredColon() + value = try scanner.nextBool() + } + mutating func decodeSingularBoolField(value: inout Bool?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextBool() + } + mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextBool() + value.append(n) + } + } else { + let n = try scanner.nextBool() + value.append(n) + } + } + mutating func decodeSingularStringField(value: inout String) throws { + try scanner.skipRequiredColon() + value = try scanner.nextStringValue() + } + mutating func decodeSingularStringField(value: inout String?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextStringValue() + } + mutating func decodeRepeatedStringField(value: inout [String]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextStringValue() + value.append(n) + } + } else { + let n = try scanner.nextStringValue() + value.append(n) + } + } + mutating func decodeSingularBytesField(value: inout Data) throws { + try scanner.skipRequiredColon() + value = try scanner.nextBytesValue() + } + mutating func decodeSingularBytesField(value: inout Data?) throws { + try scanner.skipRequiredColon() + value = try scanner.nextBytesValue() + } + mutating func decodeRepeatedBytesField(value: inout [Data]) throws { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let n = try scanner.nextBytesValue() + value.append(n) + } + } else { + let n = try scanner.nextBytesValue() + value.append(n) + } + } + + private mutating func decodeEnum() throws -> E where E.RawValue == Int { + if let name = try scanner.nextOptionalEnumName() { + if let b = E(rawUTF8: name) { + return b + } else { + throw TextFormatDecodingError.unrecognizedEnumValue + } + } + let number = try scanner.nextSInt() + if number >= Int64(Int32.min) && number <= Int64(Int32.max) { + let n = Int32(truncatingIfNeeded: number) + if let e = E(rawValue: Int(n)) { + return e + } else { + throw TextFormatDecodingError.unrecognizedEnumValue + } + } + throw TextFormatDecodingError.malformedText + + } + + mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int { + try scanner.skipRequiredColon() + let e: E = try decodeEnum() + value = e + } + + mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int { + try scanner.skipRequiredColon() + let e: E = try decodeEnum() + value = e + } + + mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int { + try scanner.skipRequiredColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let e: E = try decodeEnum() + value.append(e) + } + } else { + let e: E = try decodeEnum() + value.append(e) + } + } + + mutating func decodeSingularMessageField(value: inout M?) throws { + _ = scanner.skipOptionalColon() + if value == nil { + value = M() + } + let terminator = try scanner.skipObjectStart() + var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) + if M.self == Google_Protobuf_Any.self { + var any = value as! Google_Protobuf_Any? + try any!.decodeTextFormat(decoder: &subDecoder) + value = any as! M? + } else { + try value!.decodeMessage(decoder: &subDecoder) + } + scanner = subDecoder.scanner + } + + mutating func decodeRepeatedMessageField(value: inout [M]) throws { + _ = scanner.skipOptionalColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + let terminator = try scanner.skipObjectStart() + var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) + if M.self == Google_Protobuf_Any.self { + var message = Google_Protobuf_Any() + try message.decodeTextFormat(decoder: &subDecoder) + value.append(message as! M) + } else { + var message = M() + try message.decodeMessage(decoder: &subDecoder) + value.append(message) + } + scanner = subDecoder.scanner + } + } else { + let terminator = try scanner.skipObjectStart() + var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) + if M.self == Google_Protobuf_Any.self { + var message = Google_Protobuf_Any() + try message.decodeTextFormat(decoder: &subDecoder) + value.append(message as! M) + } else { + var message = M() + try message.decodeMessage(decoder: &subDecoder) + value.append(message) + } + scanner = subDecoder.scanner + } + } + + mutating func decodeSingularGroupField(value: inout G?) throws { + try decodeSingularMessageField(value: &value) + } + + mutating func decodeRepeatedGroupField(value: inout [G]) throws { + try decodeRepeatedMessageField(value: &value) + } + + private mutating func decodeMapEntry(mapType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { + var keyField: KeyType.BaseType? + var valueField: ValueType.BaseType? + let terminator = try scanner.skipObjectStart() + while true { + if scanner.skipOptionalObjectEnd(terminator) { + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + return + } else { + throw TextFormatDecodingError.malformedText + } + } + if let key = try scanner.nextKey() { + switch key { + case "key", "1": + try KeyType.decodeSingular(value: &keyField, from: &self) + case "value", "2": + try ValueType.decodeSingular(value: &valueField, from: &self) + default: + throw TextFormatDecodingError.unknownField + } + scanner.skipOptionalSeparator() + } + } + } + + mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { + _ = scanner.skipOptionalColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + try decodeMapEntry(mapType: fieldType, value: &value) + } + } else { + try decodeMapEntry(mapType: fieldType, value: &value) + } + } + + private mutating func decodeMapEntry(mapType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { + var keyField: KeyType.BaseType? + var valueField: ValueType? + let terminator = try scanner.skipObjectStart() + while true { + if scanner.skipOptionalObjectEnd(terminator) { + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + return + } else { + throw TextFormatDecodingError.malformedText + } + } + if let key = try scanner.nextKey() { + switch key { + case "key", "1": + try KeyType.decodeSingular(value: &keyField, from: &self) + case "value", "2": + try decodeSingularEnumField(value: &valueField) + default: + throw TextFormatDecodingError.unknownField + } + scanner.skipOptionalSeparator() + } + } + } + + mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { + _ = scanner.skipOptionalColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + try decodeMapEntry(mapType: fieldType, value: &value) + } + } else { + try decodeMapEntry(mapType: fieldType, value: &value) + } + } + + private mutating func decodeMapEntry(mapType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { + var keyField: KeyType.BaseType? + var valueField: ValueType? + let terminator = try scanner.skipObjectStart() + while true { + if scanner.skipOptionalObjectEnd(terminator) { + if let keyField = keyField, let valueField = valueField { + value[keyField] = valueField + return + } else { + throw TextFormatDecodingError.malformedText + } + } + if let key = try scanner.nextKey() { + switch key { + case "key", "1": + try KeyType.decodeSingular(value: &keyField, from: &self) + case "value", "2": + try decodeSingularMessageField(value: &valueField) + default: + throw TextFormatDecodingError.unknownField + } + scanner.skipOptionalSeparator() + } + } + } + + mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { + _ = scanner.skipOptionalColon() + if scanner.skipOptionalBeginArray() { + var firstItem = true + while true { + if scanner.skipOptionalEndArray() { + return + } + if firstItem { + firstItem = false + } else { + try scanner.skipRequiredComma() + } + try decodeMapEntry(mapType: fieldType, value: &value) + } + } else { + try decodeMapEntry(mapType: fieldType, value: &value) + } + } + + mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws { + if let ext = scanner.extensions?[messageType, fieldNumber] { + var fieldValue = values[fieldNumber] + if fieldValue != nil { + try fieldValue!.decodeExtensionField(decoder: &self) + } else { + fieldValue = try ext._protobuf_newField(decoder: &self) + } + if fieldValue != nil { + values[fieldNumber] = fieldValue + } else { + // Really things should never get here, for TextFormat, decoding + // the value should always work or throw an error. This specific + // error result is to allow this to be more detectable. + throw TextFormatDecodingError.internalExtensionError + } + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift new file mode 100644 index 0000000..49047b2 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift @@ -0,0 +1,40 @@ +// Sources/SwiftProtobuf/TextFormatDecodingError.swift - Protobuf text format decoding errors +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Protobuf text format decoding errors +/// +// ----------------------------------------------------------------------------- + +public enum TextFormatDecodingError: Error { + /// Text data could not be parsed + case malformedText + /// A number could not be parsed + case malformedNumber + /// Extraneous data remained after decoding should have been complete + case trailingGarbage + /// The data stopped before we expected + case truncated + /// A string was not valid UTF8 + case invalidUTF8 + /// The data being parsed does not match the type specified in the proto file + case schemaMismatch + /// Field names were not compiled into the binary + case missingFieldNames + /// A field identifier (name or number) was not found on the message + case unknownField + /// The enum value was not recognized + case unrecognizedEnumValue + /// Text format rejects conflicting values for the same oneof field + case conflictingOneOf + /// An internal error happened while decoding. If this is ever encountered, + /// please file an issue with SwiftProtobuf with as much details as possible + /// for what happened (proto definitions, bytes being decoded (if possible)). + case internalExtensionError +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift new file mode 100644 index 0000000..8a7f9ce --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift @@ -0,0 +1,292 @@ +// Sources/SwiftProtobuf/TextFormatEncoder.swift - Text format encoding support +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Text format serialization engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let asciiSpace = UInt8(ascii: " ") +private let asciiColon = UInt8(ascii: ":") +private let asciiComma = UInt8(ascii: ",") +private let asciiMinus = UInt8(ascii: "-") +private let asciiBackslash = UInt8(ascii: "\\") +private let asciiDoubleQuote = UInt8(ascii: "\"") +private let asciiZero = UInt8(ascii: "0") +private let asciiOpenCurlyBracket = UInt8(ascii: "{") +private let asciiCloseCurlyBracket = UInt8(ascii: "}") +private let asciiOpenSquareBracket = UInt8(ascii: "[") +private let asciiCloseSquareBracket = UInt8(ascii: "]") +private let asciiNewline = UInt8(ascii: "\n") +private let asciiUpperA = UInt8(ascii: "A") + +private let tabSize = 2 + +/// TextFormatEncoder has no public members. +internal struct TextFormatEncoder { + private var data = [UInt8]() + private var indentString: [UInt8] = [] + var stringResult: String { + get { + return String(bytes: data, encoding: String.Encoding.utf8)! + } + } + + internal mutating func append(staticText: StaticString) { + let buff = UnsafeBufferPointer(start: staticText.utf8Start, count: staticText.utf8CodeUnitCount) + data.append(contentsOf: buff) + } + + internal mutating func append(name: _NameMap.Name) { + data.append(contentsOf: name.utf8Buffer) + } + + private mutating func append(text: String) { + data.append(contentsOf: text.utf8) + } + + init() {} + + internal mutating func indent() { + data.append(contentsOf: indentString) + } + + mutating func emitFieldName(name: UnsafeBufferPointer) { + indent() + data.append(contentsOf: name) + } + + mutating func emitFieldName(name: StaticString) { + let buff = UnsafeBufferPointer(start: name.utf8Start, count: name.utf8CodeUnitCount) + emitFieldName(name: buff) + } + + mutating func emitExtensionFieldName(name: String) { + indent() + data.append(asciiOpenSquareBracket) + append(text: name) + data.append(asciiCloseSquareBracket) + } + + mutating func emitFieldNumber(number: Int) { + indent() + appendUInt(value: UInt64(number)) + } + + mutating func startRegularField() { + append(staticText: ": ") + } + mutating func endRegularField() { + data.append(asciiNewline) + } + + // In Text format, a message-valued field writes the name + // without a trailing colon: + // name_of_field {key: value key2: value2} + mutating func startMessageField() { + append(staticText: " {\n") + for _ in 1...tabSize { + indentString.append(asciiSpace) + } + } + + mutating func endMessageField() { + for _ in 1...tabSize { + indentString.remove(at: indentString.count - 1) + } + indent() + append(staticText: "}\n") + } + + mutating func startArray() { + data.append(asciiOpenSquareBracket) + } + + mutating func arraySeparator() { + append(staticText: ", ") + } + + mutating func endArray() { + data.append(asciiCloseSquareBracket) + } + + mutating func putEnumValue(value: E) { + if let name = value.name { + data.append(contentsOf: name.utf8Buffer) + } else { + appendInt(value: Int64(value.rawValue)) + } + } + + mutating func putFloatValue(value: Float) { + if value.isNaN { + append(staticText: "nan") + } else if !value.isFinite { + if value < 0 { + append(staticText: "-inf") + } else { + append(staticText: "inf") + } + } else { + data.append(contentsOf: value.debugDescription.utf8) + } + } + + mutating func putDoubleValue(value: Double) { + if value.isNaN { + append(staticText: "nan") + } else if !value.isFinite { + if value < 0 { + append(staticText: "-inf") + } else { + append(staticText: "inf") + } + } else { + data.append(contentsOf: value.debugDescription.utf8) + } + } + + private mutating func appendUInt(value: UInt64) { + if value >= 1000 { + appendUInt(value: value / 1000) + } + if value >= 100 { + data.append(asciiZero + UInt8((value / 100) % 10)) + } + if value >= 10 { + data.append(asciiZero + UInt8((value / 10) % 10)) + } + data.append(asciiZero + UInt8(value % 10)) + } + private mutating func appendInt(value: Int64) { + if value < 0 { + data.append(asciiMinus) + // This is the twos-complement negation of value, + // computed in a way that won't overflow a 64-bit + // signed integer. + appendUInt(value: 1 + ~UInt64(bitPattern: value)) + } else { + appendUInt(value: UInt64(bitPattern: value)) + } + } + + mutating func putInt64(value: Int64) { + appendInt(value: value) + } + + mutating func putUInt64(value: UInt64) { + appendUInt(value: value) + } + + mutating func appendUIntHex(value: UInt64, digits: Int) { + if digits == 0 { + append(staticText: "0x") + } else { + appendUIntHex(value: value >> 4, digits: digits - 1) + let d = UInt8(truncatingIfNeeded: value % 16) + data.append(d < 10 ? asciiZero + d : asciiUpperA + d - 10) + } + } + + mutating func putUInt64Hex(value: UInt64, digits: Int) { + appendUIntHex(value: value, digits: digits) + } + + mutating func putBoolValue(value: Bool) { + append(staticText: value ? "true" : "false") + } + + mutating func putStringValue(value: String) { + data.append(asciiDoubleQuote) + for c in value.unicodeScalars { + switch c.value { + // Special two-byte escapes + case 8: + append(staticText: "\\b") + case 9: + append(staticText: "\\t") + case 10: + append(staticText: "\\n") + case 11: + append(staticText: "\\v") + case 12: + append(staticText: "\\f") + case 13: + append(staticText: "\\r") + case 34: + append(staticText: "\\\"") + case 92: + append(staticText: "\\\\") + case 0...31, 127: // Octal form for C0 control chars + data.append(asciiBackslash) + data.append(asciiZero + UInt8(c.value / 64)) + data.append(asciiZero + UInt8(c.value / 8 % 8)) + data.append(asciiZero + UInt8(c.value % 8)) + case 0...127: // ASCII + data.append(UInt8(truncatingIfNeeded: c.value)) + case 0x80...0x7ff: + data.append(0xc0 + UInt8(c.value / 64)) + data.append(0x80 + UInt8(c.value % 64)) + case 0x800...0xffff: + data.append(0xe0 + UInt8(truncatingIfNeeded: c.value >> 12)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) + default: + data.append(0xf0 + UInt8(truncatingIfNeeded: c.value >> 18)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 12) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) + data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) + } + } + data.append(asciiDoubleQuote) + } + + mutating func putBytesValue(value: Data) { + data.append(asciiDoubleQuote) + value.withUnsafeBytes { (body: UnsafeRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + let p = baseAddress.assumingMemoryBound(to: UInt8.self) + + for i in 0.. () in + if let baseAddress = body.baseAddress, body.count > 0 { + let p = baseAddress.assumingMemoryBound(to: UInt8.self) + var decoder = BinaryDecoder(forReadingFrom: p, + count: body.count, + options: BinaryDecodingOptions()) + try visitUnknown(decoder: &decoder, groupFieldNumber: nil) + } + } + } + } + + private mutating func visitUnknown(decoder: inout BinaryDecoder, groupFieldNumber: Int?) throws { + while let tag = try decoder.getTag() { + switch tag.wireFormat { + case .varint: + encoder.emitFieldNumber(number: tag.fieldNumber) + var value: UInt64 = 0 + encoder.startRegularField() + try decoder.decodeSingularUInt64Field(value: &value) + encoder.putUInt64(value: value) + encoder.endRegularField() + case .fixed64: + encoder.emitFieldNumber(number: tag.fieldNumber) + var value: UInt64 = 0 + encoder.startRegularField() + try decoder.decodeSingularFixed64Field(value: &value) + encoder.putUInt64Hex(value: value, digits: 16) + encoder.endRegularField() + case .lengthDelimited: + encoder.emitFieldNumber(number: tag.fieldNumber) + var bytes = Internal.emptyData + try decoder.decodeSingularBytesField(value: &bytes) + bytes.withUnsafeBytes { (body: UnsafeRawBufferPointer) -> () in + if let baseAddress = body.baseAddress, body.count > 0 { + let p = baseAddress.assumingMemoryBound(to: UInt8.self) + + var testDecoder = BinaryDecoder(forReadingFrom: p, + count: body.count, + parent: decoder) + do { + // Skip all the fields to test if it looks like a message + while let _ = try testDecoder.nextFieldNumber() { + } + // No error? Output the message body. + var subDecoder = BinaryDecoder(forReadingFrom: p, + count: bytes.count, + parent: decoder) + encoder.startMessageField() + try visitUnknown(decoder: &subDecoder, groupFieldNumber: nil) + encoder.endMessageField() + } catch { + // Field scan threw an error, so just dump it as a string. + encoder.startRegularField() + encoder.putBytesValue(value: bytes) + encoder.endRegularField() + } + } + } + case .startGroup: + encoder.emitFieldNumber(number: tag.fieldNumber) + encoder.startMessageField() + try visitUnknown(decoder: &decoder, groupFieldNumber: tag.fieldNumber) + encoder.endMessageField() + case .endGroup: + // Unknown data is scanned and verified by the + // binary parser, so this can never fail. + assert(tag.fieldNumber == groupFieldNumber) + return + case .fixed32: + encoder.emitFieldNumber(number: tag.fieldNumber) + var value: UInt32 = 0 + encoder.startRegularField() + try decoder.decodeSingularFixed32Field(value: &value) + encoder.putUInt64Hex(value: UInt64(value), digits: 8) + encoder.endRegularField() + } + } + } + + // Visitor.swift defines default versions for other singular field types + // that simply widen and dispatch to one of the following. Since Text format + // does not distinguish e.g., Fixed64 vs. UInt64, this is sufficient. + + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putFloatValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putDoubleValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putInt64(value: value) + encoder.endRegularField() + } + + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putUInt64(value: value) + encoder.endRegularField() + } + + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putBoolValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putStringValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putBytesValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putEnumValue(value: value) + encoder.endRegularField() + } + + mutating func visitSingularMessageField(value: M, + fieldNumber: Int) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startMessageField() + var visitor = TextFormatEncodingVisitor(message: value, encoder: encoder, options: options) + if let any = value as? Google_Protobuf_Any { + any.textTraverse(visitor: &visitor) + } else { + try! value.traverse(visitor: &visitor) + } + encoder = visitor.encoder + encoder.endMessageField() + } + + // Emit the full "verbose" form of an Any. This writes the typeURL + // as a field name in `[...]` followed by the fields of the + // contained message. + internal mutating func visitAnyVerbose(value: Message, typeURL: String) { + encoder.emitExtensionFieldName(name: typeURL) + encoder.startMessageField() + var visitor = TextFormatEncodingVisitor(message: value, encoder: encoder, options: options) + if let any = value as? Google_Protobuf_Any { + any.textTraverse(visitor: &visitor) + } else { + try! value.traverse(visitor: &visitor) + } + encoder = visitor.encoder + encoder.endMessageField() + } + + // Write a single special field called "#json". This + // is used for Any objects with undecoded JSON contents. + internal mutating func visitAnyJSONDataField(value: Data) { + encoder.indent() + encoder.append(staticText: "#json: ") + encoder.putBytesValue(value: value) + encoder.append(staticText: "\n") + } + + // The default implementations in Visitor.swift provide the correct + // results, but we get significantly better performance by only doing + // the name lookup once for the array, rather than once for each element: + + mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putFloatValue(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putDoubleValue(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putInt64(value: Int64(v)) + encoder.endRegularField() + } + } + + mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putInt64(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putUInt64(value: UInt64(v)) + encoder.endRegularField() + } + } + + mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putUInt64(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { + try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { + try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) + } + mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) + } + mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putBoolValue(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putStringValue(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putBytesValue(value: v) + encoder.endRegularField() + } + } + + mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + encoder.putEnumValue(value: v) + encoder.endRegularField() + } + } + + // Messages and groups + mutating func visitRepeatedMessageField(value: [M], + fieldNumber: Int) throws { + for v in value { + emitFieldName(lookingUp: fieldNumber) + encoder.startMessageField() + var visitor = TextFormatEncodingVisitor(message: v, encoder: encoder, options: options) + if let any = v as? Google_Protobuf_Any { + any.textTraverse(visitor: &visitor) + } else { + try! v.traverse(visitor: &visitor) + } + encoder = visitor.encoder + encoder.endMessageField() + } + } + + // Google's C++ implementation of Text format supports two formats + // for repeated numeric fields: "short" format writes the list as a + // single field with values enclosed in `[...]`, "long" format + // writes a separate field name/value for each item. They provide + // an option for callers to select which output version they prefer. + + // Since this distinction mirrors the difference in Protobuf Binary + // between "packed" and "non-packed", I've chosen to use the short + // format for packed fields and the long version for repeated + // fields. This provides a clear visual distinction between these + // fields (including proto3's default use of packed) without + // introducing the baggage of a separate option. + + private mutating func _visitPacked( + value: [T], fieldNumber: Int, + encode: (T, inout TextFormatEncoder) -> () + ) throws { + emitFieldName(lookingUp: fieldNumber) + encoder.startRegularField() + var firstItem = true + encoder.startArray() + for v in value { + if !firstItem { + encoder.arraySeparator() + } + encode(v, &encoder) + firstItem = false + } + encoder.endArray() + encoder.endRegularField() + } + + mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: Float, encoder: inout TextFormatEncoder) in + encoder.putFloatValue(value: v) + } + } + + mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: Double, encoder: inout TextFormatEncoder) in + encoder.putDoubleValue(value: v) + } + } + + mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: Int32, encoder: inout TextFormatEncoder) in + encoder.putInt64(value: Int64(v)) + } + } + + mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: Int64, encoder: inout TextFormatEncoder) in + encoder.putInt64(value: v) + } + } + + mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: UInt32, encoder: inout TextFormatEncoder) in + encoder.putUInt64(value: UInt64(v)) + } + } + + mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: UInt64, encoder: inout TextFormatEncoder) in + encoder.putUInt64(value: v) + } + } + + mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { + try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { + try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + try visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + try visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) + } + + mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: Bool, encoder: inout TextFormatEncoder) in + encoder.putBoolValue(value: v) + } + } + + mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { + try _visitPacked(value: value, fieldNumber: fieldNumber) { + (v: E, encoder: inout TextFormatEncoder) in + encoder.putEnumValue(value: v) + } + } + + /// Helper to encapsulate the common structure of iterating over a map + /// and encoding the keys and values. + private mutating func _visitMap( + map: Dictionary, + fieldNumber: Int, + coder: (inout TextFormatEncodingVisitor, K, V) throws -> () + ) throws { + for (k,v) in map { + emitFieldName(lookingUp: fieldNumber) + encoder.startMessageField() + var visitor = TextFormatEncodingVisitor(nameMap: nil, nameResolver: mapNameResolver, extensions: nil, encoder: encoder, options: options) + try coder(&visitor, k, v) + encoder = visitor.encoder + encoder.endMessageField() + } + } + + mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int + ) throws { + try _visitMap(map: value, fieldNumber: fieldNumber) { + (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in + try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) + try ValueType.visitSingular(value: value, fieldNumber: 2, with: &visitor) + } + } + + mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int + ) throws where ValueType.RawValue == Int { + try _visitMap(map: value, fieldNumber: fieldNumber) { + (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in + try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) + try visitor.visitSingularEnumField(value: value, fieldNumber: 2) + } + } + + mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int + ) throws { + try _visitMap(map: value, fieldNumber: fieldNumber) { + (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in + try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) + try visitor.visitSingularMessageField(value: value, fieldNumber: 2) + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift new file mode 100644 index 0000000..6e12ff8 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift @@ -0,0 +1,1078 @@ +// Sources/SwiftProtobuf/TextFormatScanner.swift - Text format decoding +// +// Copyright (c) 2014 - 2019 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Test format decoding engine. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +private let asciiBell = UInt8(7) +private let asciiBackspace = UInt8(8) +private let asciiTab = UInt8(9) +private let asciiNewLine = UInt8(10) +private let asciiVerticalTab = UInt8(11) +private let asciiFormFeed = UInt8(12) +private let asciiCarriageReturn = UInt8(13) +private let asciiZero = UInt8(ascii: "0") +private let asciiOne = UInt8(ascii: "1") +private let asciiThree = UInt8(ascii: "3") +private let asciiSeven = UInt8(ascii: "7") +private let asciiNine = UInt8(ascii: "9") +private let asciiColon = UInt8(ascii: ":") +private let asciiPeriod = UInt8(ascii: ".") +private let asciiPlus = UInt8(ascii: "+") +private let asciiComma = UInt8(ascii: ",") +private let asciiSemicolon = UInt8(ascii: ";") +private let asciiDoubleQuote = UInt8(ascii: "\"") +private let asciiSingleQuote = UInt8(ascii: "\'") +private let asciiBackslash = UInt8(ascii: "\\") +private let asciiForwardSlash = UInt8(ascii: "/") +private let asciiHash = UInt8(ascii: "#") +private let asciiUnderscore = UInt8(ascii: "_") +private let asciiQuestionMark = UInt8(ascii: "?") +private let asciiSpace = UInt8(ascii: " ") +private let asciiOpenSquareBracket = UInt8(ascii: "[") +private let asciiCloseSquareBracket = UInt8(ascii: "]") +private let asciiOpenCurlyBracket = UInt8(ascii: "{") +private let asciiCloseCurlyBracket = UInt8(ascii: "}") +private let asciiOpenAngleBracket = UInt8(ascii: "<") +private let asciiCloseAngleBracket = UInt8(ascii: ">") +private let asciiMinus = UInt8(ascii: "-") +private let asciiLowerA = UInt8(ascii: "a") +private let asciiUpperA = UInt8(ascii: "A") +private let asciiLowerB = UInt8(ascii: "b") +private let asciiLowerE = UInt8(ascii: "e") +private let asciiUpperE = UInt8(ascii: "E") +private let asciiLowerF = UInt8(ascii: "f") +private let asciiUpperF = UInt8(ascii: "F") +private let asciiLowerI = UInt8(ascii: "i") +private let asciiLowerL = UInt8(ascii: "l") +private let asciiLowerN = UInt8(ascii: "n") +private let asciiLowerR = UInt8(ascii: "r") +private let asciiLowerS = UInt8(ascii: "s") +private let asciiLowerT = UInt8(ascii: "t") +private let asciiUpperT = UInt8(ascii: "T") +private let asciiLowerU = UInt8(ascii: "u") +private let asciiLowerV = UInt8(ascii: "v") +private let asciiLowerX = UInt8(ascii: "x") +private let asciiLowerY = UInt8(ascii: "y") +private let asciiLowerZ = UInt8(ascii: "z") +private let asciiUpperZ = UInt8(ascii: "Z") + +private func fromHexDigit(_ c: UInt8) -> UInt8? { + if c >= asciiZero && c <= asciiNine { + return c - asciiZero + } + if c >= asciiUpperA && c <= asciiUpperF { + return c - asciiUpperA + UInt8(10) + } + if c >= asciiLowerA && c <= asciiLowerF { + return c - asciiLowerA + UInt8(10) + } + return nil +} + +// Protobuf Text encoding assumes that you're working directly +// in UTF-8. So this implementation converts the string to UTF8, +// then decodes it into a sequence of bytes, then converts +// it back into a string. +private func decodeString(_ s: String) -> String? { + var out = [UInt8]() + var bytes = s.utf8.makeIterator() + while let byte = bytes.next() { + switch byte { + case asciiBackslash: // backslash + if let escaped = bytes.next() { + switch escaped { + case asciiZero...asciiSeven: // 0...7 + // C standard allows 1, 2, or 3 octal digits. + let savedPosition = bytes + let digit1 = escaped + let digit1Value = digit1 - asciiZero + if let digit2 = bytes.next(), + digit2 >= asciiZero && digit2 <= asciiSeven { + let digit2Value = digit2 - asciiZero + let innerSavedPosition = bytes + if let digit3 = bytes.next(), + digit3 >= asciiZero && digit3 <= asciiSeven { + let digit3Value = digit3 - asciiZero + let n = digit1Value * 64 + digit2Value * 8 + digit3Value + out.append(n) + } else { + let n = digit1Value * 8 + digit2Value + out.append(n) + bytes = innerSavedPosition + } + } else { + let n = digit1Value + out.append(n) + bytes = savedPosition + } + case asciiLowerX: // "x" + // Unlike C/C++, protobuf only allows 1 or 2 digits here: + if let byte = bytes.next(), let digit = fromHexDigit(byte) { + var n = digit + let savedPosition = bytes + if let byte = bytes.next(), let digit = fromHexDigit(byte) { + n = n &* 16 + digit + } else { + // No second digit; reset the iterator + bytes = savedPosition + } + out.append(n) + } else { + return nil // Hex escape must have at least 1 digit + } + case asciiLowerA: // \a + out.append(asciiBell) + case asciiLowerB: // \b + out.append(asciiBackspace) + case asciiLowerF: // \f + out.append(asciiFormFeed) + case asciiLowerN: // \n + out.append(asciiNewLine) + case asciiLowerR: // \r + out.append(asciiCarriageReturn) + case asciiLowerT: // \t + out.append(asciiTab) + case asciiLowerV: // \v + out.append(asciiVerticalTab) + case asciiDoubleQuote, + asciiSingleQuote, + asciiQuestionMark, + asciiBackslash: // " ' ? \ + out.append(escaped) + default: + return nil // Unrecognized escape + } + } else { + return nil // Input ends with backslash + } + default: + out.append(byte) + } + } + // There has got to be an easier way to convert a [UInt8] into a String. + return out.withUnsafeBufferPointer { ptr in + if let addr = ptr.baseAddress { + return utf8ToString(bytes: addr, count: ptr.count) + } else { + return String() + } + } +} + +/// +/// TextFormatScanner has no public members. +/// +internal struct TextFormatScanner { + internal var extensions: ExtensionMap? + private var p: UnsafePointer + private var end: UnsafePointer + private var doubleParser = DoubleParser() + + internal var complete: Bool { + mutating get { + return p == end + } + } + + internal init(utf8Pointer: UnsafePointer, count: Int, extensions: ExtensionMap? = nil) { + p = utf8Pointer + end = p + count + self.extensions = extensions + skipWhitespace() + } + + /// Skip whitespace + private mutating func skipWhitespace() { + while p != end { + let u = p[0] + switch u { + case asciiSpace, + asciiTab, + asciiNewLine, + asciiCarriageReturn: // space, tab, NL, CR + p += 1 + case asciiHash: // # comment + p += 1 + while p != end { + // Skip until end of line + let c = p[0] + p += 1 + if c == asciiNewLine || c == asciiCarriageReturn { + break + } + } + default: + return + } + } + } + + /// Return a buffer containing the raw UTF8 for an identifier. + /// Assumes that you already know the current byte is a valid + /// start of identifier. + private mutating func parseUTF8Identifier() -> UnsafeBufferPointer { + let start = p + loop: while p != end { + let c = p[0] + switch c { + case asciiLowerA...asciiLowerZ, + asciiUpperA...asciiUpperZ, + asciiZero...asciiNine, + asciiUnderscore: + p += 1 + default: + break loop + } + } + let s = UnsafeBufferPointer(start: start, count: p - start) + skipWhitespace() + return s + } + + /// Return a String containing the next identifier. + private mutating func parseIdentifier() -> String { + let buff = parseUTF8Identifier() + let s = utf8ToString(bytes: buff.baseAddress!, count: buff.count) + // Force-unwrap is OK: we never have invalid UTF8 at this point. + return s! + } + + /// Parse the rest of an [extension_field_name] in the input, assuming the + /// initial "[" character has already been read (and is in the prefix) + /// This is also used for AnyURL, so we include "/", "." + private mutating func parseExtensionKey() -> String? { + let start = p + if p == end { + return nil + } + let c = p[0] + switch c { + case asciiLowerA...asciiLowerZ, asciiUpperA...asciiUpperZ: + p += 1 + default: + return nil + } + while p != end { + let c = p[0] + switch c { + case asciiLowerA...asciiLowerZ, + asciiUpperA...asciiUpperZ, + asciiZero...asciiNine, + asciiUnderscore, + asciiPeriod, + asciiForwardSlash: + p += 1 + case asciiCloseSquareBracket: // ] + return utf8ToString(bytes: start, count: p - start) + default: + return nil + } + } + return nil + } + + /// Scan a string that encodes a byte field, return a count of + /// the number of bytes that should be decoded from it + private mutating func validateAndCountBytesFromString(terminator: UInt8, sawBackslash: inout Bool) throws -> Int { + var count = 0 + let start = p + sawBackslash = false + while p != end { + let byte = p[0] + p += 1 + if byte == terminator { + p = start + return count + } + switch byte { + case asciiBackslash: // "\\" + sawBackslash = true + if p != end { + let escaped = p[0] + p += 1 + switch escaped { + case asciiZero...asciiSeven: // '0'...'7' + // C standard allows 1, 2, or 3 octal digits. + if p != end, p[0] >= asciiZero, p[0] <= asciiSeven { + p += 1 + if p != end, p[0] >= asciiZero, p[0] <= asciiSeven { + if escaped > asciiThree { + // Out of range octal: three digits and first digit is greater than 3 + throw TextFormatDecodingError.malformedText + } + p += 1 + } + } + count += 1 + case asciiLowerX: // 'x' hexadecimal escape + if p != end && fromHexDigit(p[0]) != nil { + p += 1 + if p != end && fromHexDigit(p[0]) != nil { + p += 1 + } + } else { + throw TextFormatDecodingError.malformedText // Hex escape must have at least 1 digit + } + count += 1 + case asciiLowerA, // \a ("alert") + asciiLowerB, // \b + asciiLowerF, // \f + asciiLowerN, // \n + asciiLowerR, // \r + asciiLowerT, // \t + asciiLowerV, // \v + asciiSingleQuote, // \' + asciiDoubleQuote, // \" + asciiQuestionMark, // \? + asciiBackslash: // \\ + count += 1 + default: + throw TextFormatDecodingError.malformedText // Unrecognized escape + } + } + default: + count += 1 + } + } + throw TextFormatDecodingError.malformedText + } + + /// Protobuf Text format uses C ASCII conventions for + /// encoding byte sequences, including the use of octal + /// and hexadecimal escapes. + /// + /// Assumes that validateAndCountBytesFromString() has already + /// verified the correctness. So we get to avoid error checks here. + private mutating func parseBytesFromString(terminator: UInt8, into data: inout Data) { + data.withUnsafeMutableBytes { + (body: UnsafeMutableRawBufferPointer) in + if let baseAddress = body.baseAddress, body.count > 0 { + var out = baseAddress.assumingMemoryBound(to: UInt8.self) + while p[0] != terminator { + let byte = p[0] + p += 1 + switch byte { + case asciiBackslash: // "\\" + let escaped = p[0] + p += 1 + switch escaped { + case asciiZero...asciiSeven: // '0'...'7' + // C standard allows 1, 2, or 3 octal digits. + let digit1Value = escaped - asciiZero + let digit2 = p[0] + if digit2 >= asciiZero, digit2 <= asciiSeven { + p += 1 + let digit2Value = digit2 - asciiZero + let digit3 = p[0] + if digit3 >= asciiZero, digit3 <= asciiSeven { + p += 1 + let digit3Value = digit3 - asciiZero + out[0] = digit1Value &* 64 + digit2Value * 8 + digit3Value + out += 1 + } else { + out[0] = digit1Value * 8 + digit2Value + out += 1 + } + } else { + out[0] = digit1Value + out += 1 + } + case asciiLowerX: // 'x' hexadecimal escape + // We already validated, so we know there's at least one digit: + var n = fromHexDigit(p[0])! + p += 1 + if let digit = fromHexDigit(p[0]) { + n = n &* 16 &+ digit + p += 1 + } + out[0] = n + out += 1 + case asciiLowerA: // \a ("alert") + out[0] = asciiBell + out += 1 + case asciiLowerB: // \b + out[0] = asciiBackspace + out += 1 + case asciiLowerF: // \f + out[0] = asciiFormFeed + out += 1 + case asciiLowerN: // \n + out[0] = asciiNewLine + out += 1 + case asciiLowerR: // \r + out[0] = asciiCarriageReturn + out += 1 + case asciiLowerT: // \t + out[0] = asciiTab + out += 1 + case asciiLowerV: // \v + out[0] = asciiVerticalTab + out += 1 + default: + out[0] = escaped + out += 1 + } + default: + out[0] = byte + out += 1 + } + } + p += 1 // Consume terminator + } + } + } + + /// Assumes the leading quote has already been consumed + private mutating func parseStringSegment(terminator: UInt8) -> String? { + let start = p + var sawBackslash = false + while p != end { + let c = p[0] + if c == terminator { + let s = utf8ToString(bytes: start, count: p - start) + p += 1 + skipWhitespace() + if let s = s, sawBackslash { + return decodeString(s) + } else { + return s + } + } + p += 1 + if c == asciiBackslash { // \ + if p == end { + return nil + } + sawBackslash = true + p += 1 + } + } + return nil // Unterminated quoted string + } + + internal mutating func nextUInt() throws -> UInt64 { + if p == end { + throw TextFormatDecodingError.malformedNumber + } + let c = p[0] + p += 1 + if c == asciiZero { // leading '0' precedes octal or hex + if p[0] == asciiLowerX { // 'x' => hex + p += 1 + var n: UInt64 = 0 + while p != end { + let digit = p[0] + let val: UInt64 + switch digit { + case asciiZero...asciiNine: // 0...9 + val = UInt64(digit - asciiZero) + case asciiLowerA...asciiLowerF: // a...f + val = UInt64(digit - asciiLowerA + 10) + case asciiUpperA...asciiUpperF: + val = UInt64(digit - asciiUpperA + 10) + case asciiLowerU: // trailing 'u' + p += 1 + skipWhitespace() + return n + default: + skipWhitespace() + return n + } + if n > UInt64.max / 16 { + throw TextFormatDecodingError.malformedNumber + } + p += 1 + n = n * 16 + val + } + skipWhitespace() + return n + } else { // octal + var n: UInt64 = 0 + while p != end { + let digit = p[0] + if digit == asciiLowerU { // trailing 'u' + p += 1 + skipWhitespace() + return n + } + if digit < asciiZero || digit > asciiSeven { + skipWhitespace() + return n // not octal digit + } + let val = UInt64(digit - asciiZero) + if n > UInt64.max / 8 { + throw TextFormatDecodingError.malformedNumber + } + p += 1 + n = n * 8 + val + } + skipWhitespace() + return n + } + } else if c > asciiZero && c <= asciiNine { // 1...9 + var n = UInt64(c - asciiZero) + while p != end { + let digit = p[0] + if digit == asciiLowerU { // trailing 'u' + p += 1 + skipWhitespace() + return n + } + if digit < asciiZero || digit > asciiNine { + skipWhitespace() + return n // not a digit + } + let val = UInt64(digit - asciiZero) + if n > UInt64.max / 10 || n * 10 > UInt64.max - val { + throw TextFormatDecodingError.malformedNumber + } + p += 1 + n = n * 10 + val + } + skipWhitespace() + return n + } + throw TextFormatDecodingError.malformedNumber + } + + internal mutating func nextSInt() throws -> Int64 { + if p == end { + throw TextFormatDecodingError.malformedNumber + } + let c = p[0] + if c == asciiMinus { // - + p += 1 + // character after '-' must be digit + let digit = p[0] + if digit < asciiZero || digit > asciiNine { + throw TextFormatDecodingError.malformedNumber + } + let n = try nextUInt() + let limit: UInt64 = 0x8000000000000000 // -Int64.min + if n >= limit { + if n > limit { + // Too large negative number + throw TextFormatDecodingError.malformedNumber + } else { + return Int64.min // Special case for Int64.min + } + } + return -Int64(bitPattern: n) + } else { + let n = try nextUInt() + if n > UInt64(bitPattern: Int64.max) { + throw TextFormatDecodingError.malformedNumber + } + return Int64(bitPattern: n) + } + } + + internal mutating func nextStringValue() throws -> String { + var result: String + skipWhitespace() + if p == end { + throw TextFormatDecodingError.malformedText + } + let c = p[0] + if c != asciiSingleQuote && c != asciiDoubleQuote { + throw TextFormatDecodingError.malformedText + } + p += 1 + if let s = parseStringSegment(terminator: c) { + result = s + } else { + throw TextFormatDecodingError.malformedText + } + + while true { + if p == end { + return result + } + let c = p[0] + if c != asciiSingleQuote && c != asciiDoubleQuote { + return result + } + p += 1 + if let s = parseStringSegment(terminator: c) { + result.append(s) + } else { + throw TextFormatDecodingError.malformedText + } + } + } + + /// Protobuf Text Format allows a single bytes field to + /// contain multiple quoted strings. The values + /// are separately decoded and then concatenated: + /// field1: "bytes" 'more bytes' + /// "and even more bytes" + internal mutating func nextBytesValue() throws -> Data { + // Get the first string's contents + var result: Data + skipWhitespace() + if p == end { + throw TextFormatDecodingError.malformedText + } + let c = p[0] + if c != asciiSingleQuote && c != asciiDoubleQuote { + throw TextFormatDecodingError.malformedText + } + p += 1 + var sawBackslash = false + let n = try validateAndCountBytesFromString(terminator: c, sawBackslash: &sawBackslash) + if sawBackslash { + result = Data(count: n) + parseBytesFromString(terminator: c, into: &result) + } else { + result = Data(bytes: p, count: n) + p += n + 1 // Skip string body + close quote + } + + // If there are more strings, decode them + // and append to the result: + while true { + skipWhitespace() + if p == end { + return result + } + let c = p[0] + if c != asciiSingleQuote && c != asciiDoubleQuote { + return result + } + p += 1 + var sawBackslash = false + let n = try validateAndCountBytesFromString(terminator: c, sawBackslash: &sawBackslash) + if sawBackslash { + var b = Data(count: n) + parseBytesFromString(terminator: c, into: &b) + result.append(b) + } else { + result.append(p, count: n) + p += n + 1 // Skip string body + close quote + } + } + } + + // Tries to identify a sequence of UTF8 characters + // that represent a numeric floating-point value. + private mutating func tryParseFloatString() -> Double? { + guard p != end else {return nil} + let start = p + var c = p[0] + if c == asciiMinus { + p += 1 + guard p != end else {p = start; return nil} + c = p[0] + } + switch c { + case asciiZero: // '0' as first character is not allowed followed by digit + p += 1 + guard p != end else {break} + c = p[0] + if c >= asciiZero && c <= asciiNine { + p = start + return nil + } + case asciiPeriod: // '.' as first char only if followed by digit + p += 1 + guard p != end else {p = start; return nil} + c = p[0] + if c < asciiZero || c > asciiNine { + p = start + return nil + } + case asciiOne...asciiNine: + break + default: + p = start + return nil + } + loop: while p != end { + let c = p[0] + switch c { + case asciiZero...asciiNine, + asciiPeriod, + asciiPlus, + asciiMinus, + asciiLowerE, + asciiUpperE: // 0...9, ., +, -, e, E + p += 1 + case asciiLowerF: // f + // proto1 allowed floats to be suffixed with 'f' + let d = doubleParser.utf8ToDouble(bytes: start, count: p - start) + // Just skip the 'f' + p += 1 + skipWhitespace() + return d + default: + break loop + } + } + let d = doubleParser.utf8ToDouble(bytes: start, count: p - start) + skipWhitespace() + return d + } + + // Skip specified characters if they all match + private mutating func skipOptionalCharacters(bytes: [UInt8]) { + let start = p + for b in bytes { + if p == end || p[0] != b { + p = start + return + } + p += 1 + } + } + + // Skip following keyword if it matches (case-insensitively) + // the given keyword (specified as a series of bytes). + private mutating func skipOptionalKeyword(bytes: [UInt8]) -> Bool { + let start = p + for b in bytes { + if p == end { + p = start + return false + } + var c = p[0] + if c >= asciiUpperA && c <= asciiUpperZ { + // Convert to lower case + // (Protobuf text keywords are case insensitive) + c += asciiLowerA - asciiUpperA + } + if c != b { + p = start + return false + } + p += 1 + } + if p == end { + return true + } + let c = p[0] + if ((c >= asciiUpperA && c <= asciiUpperZ) + || (c >= asciiLowerA && c <= asciiLowerZ)) { + p = start + return false + } + skipWhitespace() + return true + } + + // If the next token is the identifier "nan", return true. + private mutating func skipOptionalNaN() -> Bool { + return skipOptionalKeyword(bytes: + [asciiLowerN, asciiLowerA, asciiLowerN]) + } + + // If the next token is a recognized spelling of "infinity", + // return Float.infinity or -Float.infinity + private mutating func skipOptionalInfinity() -> Float? { + if p == end { + return nil + } + let c = p[0] + let negated: Bool + if c == asciiMinus { + negated = true + p += 1 + } else { + negated = false + } + let inf = [asciiLowerI, asciiLowerN, asciiLowerF] + let infinity = [asciiLowerI, asciiLowerN, asciiLowerF, asciiLowerI, + asciiLowerN, asciiLowerI, asciiLowerT, asciiLowerY] + if (skipOptionalKeyword(bytes: inf) + || skipOptionalKeyword(bytes: infinity)) { + return negated ? -Float.infinity : Float.infinity + } + return nil + } + + internal mutating func nextFloat() throws -> Float { + if let d = tryParseFloatString() { + return Float(d) + } + if skipOptionalNaN() { + return Float.nan + } + if let inf = skipOptionalInfinity() { + return inf + } + throw TextFormatDecodingError.malformedNumber + } + + internal mutating func nextDouble() throws -> Double { + if let d = tryParseFloatString() { + return d + } + if skipOptionalNaN() { + return Double.nan + } + if let inf = skipOptionalInfinity() { + return Double(inf) + } + throw TextFormatDecodingError.malformedNumber + } + + internal mutating func nextBool() throws -> Bool { + skipWhitespace() + if p == end { + throw TextFormatDecodingError.malformedText + } + let c = p[0] + p += 1 + let result: Bool + switch c { + case asciiZero: + result = false + case asciiOne: + result = true + case asciiLowerF, asciiUpperF: + if p != end { + let alse = [asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE] + skipOptionalCharacters(bytes: alse) + } + result = false + case asciiLowerT, asciiUpperT: + if p != end { + let rue = [asciiLowerR, asciiLowerU, asciiLowerE] + skipOptionalCharacters(bytes: rue) + } + result = true + default: + throw TextFormatDecodingError.malformedText + } + if p == end { + return result + } + switch p[0] { + case asciiSpace, + asciiTab, + asciiNewLine, + asciiCarriageReturn, + asciiHash, + asciiComma, + asciiSemicolon, + asciiCloseSquareBracket, + asciiCloseCurlyBracket, + asciiCloseAngleBracket: + skipWhitespace() + return result + default: + throw TextFormatDecodingError.malformedText + } + } + + internal mutating func nextOptionalEnumName() throws -> UnsafeBufferPointer? { + skipWhitespace() + if p == end { + throw TextFormatDecodingError.malformedText + } + switch p[0] { + case asciiLowerA...asciiLowerZ, asciiUpperA...asciiUpperZ: + return parseUTF8Identifier() + default: + return nil + } + } + + /// Any URLs are syntactically (almost) identical to extension + /// keys, so we share the code for those. + internal mutating func nextOptionalAnyURL() throws -> String? { + return try nextOptionalExtensionKey() + } + + /// Returns next extension key or nil if end-of-input or + /// if next token is not an extension key. + /// + /// Throws an error if the next token starts with '[' but + /// cannot be parsed as an extension key. + /// + /// Note: This accepts / characters to support Any URL parsing. + /// Technically, Any URLs can contain / characters and extension + /// key names cannot. But in practice, accepting / chracters for + /// extension keys works fine, since the result just gets rejected + /// when the key is looked up. + internal mutating func nextOptionalExtensionKey() throws -> String? { + skipWhitespace() + if p == end { + return nil + } + if p[0] == asciiOpenSquareBracket { // [ + p += 1 + if let s = parseExtensionKey() { + if p == end || p[0] != asciiCloseSquareBracket { + throw TextFormatDecodingError.malformedText + } + // Skip ] + p += 1 + skipWhitespace() + return s + } else { + throw TextFormatDecodingError.malformedText + } + } + return nil + } + + /// Returns text of next regular key or nil if end-of-input. + /// This considers an extension key [keyname] to be an + /// error, so call nextOptionalExtensionKey first if you + /// want to handle extension keys. + /// + /// This is only used by map parsing; we should be able to + /// rework that to use nextFieldNumber instead. + internal mutating func nextKey() throws -> String? { + skipWhitespace() + if p == end { + return nil + } + let c = p[0] + switch c { + case asciiOpenSquareBracket: // [ + throw TextFormatDecodingError.malformedText + case asciiLowerA...asciiLowerZ, + asciiUpperA...asciiUpperZ, + asciiOne...asciiNine: // a...z, A...Z, 1...9 + return parseIdentifier() + default: + throw TextFormatDecodingError.malformedText + } + } + + /// Parse a field name, look it up, and return the corresponding + /// field number. + /// + /// returns nil at end-of-input + /// + /// Throws if field name cannot be parsed or if field name is + /// unknown. + /// + /// This function accounts for as much as 2/3 of the total run + /// time of the entire parse. + internal mutating func nextFieldNumber(names: _NameMap) throws -> Int? { + if p == end { + return nil + } + let c = p[0] + switch c { + case asciiLowerA...asciiLowerZ, + asciiUpperA...asciiUpperZ: // a...z, A...Z + let key = parseUTF8Identifier() + if let fieldNumber = names.number(forProtoName: key) { + return fieldNumber + } else { + throw TextFormatDecodingError.unknownField + } + case asciiOne...asciiNine: // 1-9 (field numbers are 123, not 0123) + var fieldNum = Int(c) - Int(asciiZero) + p += 1 + while p != end { + let c = p[0] + if c >= asciiZero && c <= asciiNine { + fieldNum = fieldNum &* 10 &+ (Int(c) - Int(asciiZero)) + } else { + break + } + p += 1 + } + skipWhitespace() + if names.names(for: fieldNum) != nil { + return fieldNum + } else { + // It was a number that isn't a known field. + // The C++ version (TextFormat::Parser::ParserImpl::ConsumeField()), + // supports an option to file or skip the field's value (this is true + // of unknown names or numbers). + throw TextFormatDecodingError.unknownField + } + default: + break + } + throw TextFormatDecodingError.malformedText + } + + private mutating func skipRequiredCharacter(_ c: UInt8) throws { + skipWhitespace() + if p != end && p[0] == c { + p += 1 + skipWhitespace() + } else { + throw TextFormatDecodingError.malformedText + } + } + + internal mutating func skipRequiredComma() throws { + try skipRequiredCharacter(asciiComma) + } + + internal mutating func skipRequiredColon() throws { + try skipRequiredCharacter(asciiColon) + } + + private mutating func skipOptionalCharacter(_ c: UInt8) -> Bool { + if p != end && p[0] == c { + p += 1 + skipWhitespace() + return true + } + return false + } + + internal mutating func skipOptionalColon() -> Bool { + return skipOptionalCharacter(asciiColon) + } + + internal mutating func skipOptionalEndArray() -> Bool { + return skipOptionalCharacter(asciiCloseSquareBracket) + } + + internal mutating func skipOptionalBeginArray() -> Bool { + return skipOptionalCharacter(asciiOpenSquareBracket) + } + + internal mutating func skipOptionalObjectEnd(_ c: UInt8) -> Bool { + return skipOptionalCharacter(c) + } + + internal mutating func skipOptionalSeparator() { + if p != end { + let c = p[0] + if c == asciiComma || c == asciiSemicolon { // comma or semicolon + p += 1 + skipWhitespace() + } + } + } + + /// Returns the character that should end this field. + /// E.g., if object starts with "{", returns "}" + internal mutating func skipObjectStart() throws -> UInt8 { + if p != end { + let c = p[0] + p += 1 + skipWhitespace() + switch c { + case asciiOpenCurlyBracket: // { + return asciiCloseCurlyBracket // } + case asciiOpenAngleBracket: // < + return asciiCloseAngleBracket // > + default: + break + } + } + throw TextFormatDecodingError.malformedText + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift new file mode 100644 index 0000000..8ae3790 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift @@ -0,0 +1,53 @@ +// Sources/SwiftProtobuf/TimeUtils.swift - Generally useful time/calendar functions +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Generally useful time/calendar functions and constants +/// +// ----------------------------------------------------------------------------- + +let minutesPerDay: Int32 = 1440 +let minutesPerHour: Int32 = 60 +let secondsPerDay: Int32 = 86400 +let secondsPerHour: Int32 = 3600 +let secondsPerMinute: Int32 = 60 +let nanosPerSecond: Int32 = 1000000000 + +internal func timeOfDayFromSecondsSince1970(seconds: Int64) -> (hh: Int32, mm: Int32, ss: Int32) { + let secondsSinceMidnight = Int32(mod(seconds, Int64(secondsPerDay))) + let ss = mod(secondsSinceMidnight, secondsPerMinute) + let mm = mod(div(secondsSinceMidnight, secondsPerMinute), minutesPerHour) + let hh = Int32(div(secondsSinceMidnight, secondsPerHour)) + + return (hh: hh, mm: mm, ss: ss) +} + +internal func julianDayNumberFromSecondsSince1970(seconds: Int64) -> Int64 { + // January 1, 1970 is Julian Day Number 2440588. + // See http://aa.usno.navy.mil/faq/docs/JD_Formula.php + return div(seconds + 2440588 * Int64(secondsPerDay), Int64(secondsPerDay)) +} + +internal func gregorianDateFromSecondsSince1970(seconds: Int64) -> (YY: Int32, MM: Int32, DD: Int32) { + // The following implements Richards' algorithm (see the Wikipedia article + // for "Julian day"). + // If you touch this code, please test it exhaustively by playing with + // Test_Timestamp.testJSON_range. + + let JJ = julianDayNumberFromSecondsSince1970(seconds: seconds) + let f = JJ + 1401 + div(div(4 * JJ + 274277, 146097) * 3, 4) - 38 + let e = 4 * f + 3 + let g = Int64(div(mod(e, 1461), 4)) + let h = 5 * g + 2 + let DD = div(mod(h, 153), 5) + 1 + let MM = mod(div(h, 153) + 2, 12) + 1 + let YY = div(e, 1461) - 4716 + div(12 + 2 - MM, 12) + + return (YY: Int32(YY), MM: Int32(MM), DD: Int32(DD)) +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift new file mode 100644 index 0000000..9501bc6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift @@ -0,0 +1,46 @@ +// Sources/SwiftProtobuf/UnknownStorage.swift - Handling unknown fields +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Proto2 binary coding requires storing and recoding of unknown fields. +/// This simple support class handles that requirement. A property of this type +/// is compiled into every proto2 message. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// Contains any unknown fields in a decoded message; that is, fields that were +/// sent on the wire but were not recognized by the generated message +/// implementation or were valid field numbers but with mismatching wire +/// formats (for example, a field encoded as a varint when a fixed32 integer +/// was expected). +public struct UnknownStorage: Equatable { + /// The raw protocol buffer binary-encoded bytes that represent the unknown + /// fields of a decoded message. + public private(set) var data = Internal.emptyData + +#if !swift(>=4.1) + public static func ==(lhs: UnknownStorage, rhs: UnknownStorage) -> Bool { + return lhs.data == rhs.data + } +#endif + + public init() {} + + internal mutating func append(protobufData: Data) { + data.append(protobufData) + } + + public func traverse(visitor: inout V) throws { + if !data.isEmpty { + try visitor.visitUnknown(bytes: data) + } + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift new file mode 100644 index 0000000..613a2d1 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift @@ -0,0 +1,108 @@ +// Sources/SwiftProtobuf/Varint.swift - Varint encoding/decoding helpers +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Helper functions to varint-encode and decode integers. +/// +// ----------------------------------------------------------------------------- + + +/// Contains helper methods to varint-encode and decode integers. +internal enum Varint { + + /// Computes the number of bytes that would be needed to store a 32-bit varint. + /// + /// - Parameter value: The number whose varint size should be calculated. + /// - Returns: The size, in bytes, of the 32-bit varint. + static func encodedSize(of value: UInt32) -> Int { + if (value & (~0 << 7)) == 0 { + return 1 + } + if (value & (~0 << 14)) == 0 { + return 2 + } + if (value & (~0 << 21)) == 0 { + return 3 + } + if (value & (~0 << 28)) == 0 { + return 4 + } + return 5 + } + + /// Computes the number of bytes that would be needed to store a signed 32-bit varint, if it were + /// treated as an unsigned integer with the same bit pattern. + /// + /// - Parameter value: The number whose varint size should be calculated. + /// - Returns: The size, in bytes, of the 32-bit varint. + static func encodedSize(of value: Int32) -> Int { + if value >= 0 { + return encodedSize(of: UInt32(bitPattern: value)) + } else { + // Must sign-extend. + return encodedSize(of: Int64(value)) + } + } + + /// Computes the number of bytes that would be needed to store a 64-bit varint. + /// + /// - Parameter value: The number whose varint size should be calculated. + /// - Returns: The size, in bytes, of the 64-bit varint. + static func encodedSize(of value: Int64) -> Int { + // Handle two common special cases up front. + if (value & (~0 << 7)) == 0 { + return 1 + } + if value < 0 { + return 10 + } + + // Divide and conquer the remaining eight cases. + var value = value + var n = 2 + + if (value & (~0 << 35)) != 0 { + n += 4 + value >>= 28 + } + if (value & (~0 << 21)) != 0 { + n += 2 + value >>= 14 + } + if (value & (~0 << 14)) != 0 { + n += 1 + } + return n + } + + /// Computes the number of bytes that would be needed to store an unsigned 64-bit varint, if it + /// were treated as a signed integer witht he same bit pattern. + /// + /// - Parameter value: The number whose varint size should be calculated. + /// - Returns: The size, in bytes, of the 64-bit varint. + static func encodedSize(of value: UInt64) -> Int { + return encodedSize(of: Int64(bitPattern: value)) + } + + /// Counts the number of distinct varints in a packed byte buffer. + static func countVarintsInBuffer(start: UnsafePointer, count: Int) -> Int { + // We don't need to decode all the varints to count how many there + // are. Just observe that every varint has exactly one byte with + // value < 128. So we just count those... + var n = 0 + var ints = 0 + while n < count { + if start[n] < 128 { + ints += 1 + } + n += 1 + } + return ints + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift new file mode 100644 index 0000000..848e2e4 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift @@ -0,0 +1,28 @@ +// Sources/SwiftProtobuf/Version.swift - Runtime Version info +// +// Copyright (c) 2014 - 2017 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// A interface for exposing the version of the runtime. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +// Expose version information about the library. +public struct Version { + /// Major version. + public static let major = 1 + /// Minor version. + public static let minor = 6 + /// Revision number. + public static let revision = 0 + + /// String form of the version number. + public static let versionString = "\(major).\(minor).\(revision)" +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift new file mode 100644 index 0000000..0f28085 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift @@ -0,0 +1,693 @@ +// Sources/SwiftProtobuf/Visitor.swift - Basic serialization machinery +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Protocol for traversing the object tree. +/// +/// This is used by: +/// = Protobuf serialization +/// = JSON serialization (with some twists to account for specialty JSON +/// encodings) +/// = Protobuf text serialization +/// = Hashable computation +/// +/// Conceptually, serializers create visitor objects that are +/// then passed recursively to every message and field via generated +/// 'traverse' methods. The details get a little involved due to +/// the need to allow particular messages to override particular +/// behaviors for specific encodings, but the general idea is quite simple. +/// +// ----------------------------------------------------------------------------- + +import Foundation + +/// This is the key interface used by the generated `traverse()` methods +/// used for serialization. It is implemented by each serialization protocol: +/// Protobuf Binary, Protobuf Text, JSON, and the Hash encoder. +public protocol Visitor { + + /// Called for each non-repeated float field + /// + /// A default implementation is provided that just widens the value + /// and calls `visitSingularDoubleField` + mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws + + /// Called for each non-repeated double field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws + + /// Called for each non-repeated int32 field + /// + /// A default implementation is provided that just widens the value + /// and calls `visitSingularInt64Field` + mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws + + /// Called for each non-repeated int64 field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws + + /// Called for each non-repeated uint32 field + /// + /// A default implementation is provided that just widens the value + /// and calls `visitSingularUInt64Field` + mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws + + /// Called for each non-repeated uint64 field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws + + /// Called for each non-repeated sint32 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularInt32Field` + mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws + + /// Called for each non-repeated sint64 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularInt64Field` + mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws + + /// Called for each non-repeated fixed32 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularUInt32Field` + mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws + + /// Called for each non-repeated fixed64 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularUInt64Field` + mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws + + /// Called for each non-repeated sfixed32 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularInt32Field` + mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws + + /// Called for each non-repeated sfixed64 field + /// + /// A default implementation is provided that just forwards to + /// `visitSingularInt64Field` + mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws + + /// Called for each non-repeated bool field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws + + /// Called for each non-repeated string field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularStringField(value: String, fieldNumber: Int) throws + + /// Called for each non-repeated bytes field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws + + /// Called for each non-repeated enum field + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws + + /// Called for each non-repeated nested message field. + /// + /// There is no default implementation. This must be implemented. + mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws + + /// Called for each non-repeated proto2 group field. + /// + /// A default implementation is provided that simply forwards to + /// `visitSingularMessageField`. Implementors who need to handle groups + /// differently than nested messages can override this and provide distinct + /// implementations. + mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws + + // Called for each non-packed repeated float field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularFloatField` once for each item in the array. + mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws + + // Called for each non-packed repeated double field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularDoubleField` once for each item in the array. + mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws + + // Called for each non-packed repeated int32 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularInt32Field` once for each item in the array. + mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each non-packed repeated int64 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularInt64Field` once for each item in the array. + mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each non-packed repeated uint32 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularUInt32Field` once for each item in the array. + mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws + + // Called for each non-packed repeated uint64 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularUInt64Field` once for each item in the array. + mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws + + // Called for each non-packed repeated sint32 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularSInt32Field` once for each item in the array. + mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each non-packed repeated sint64 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularSInt64Field` once for each item in the array. + mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each non-packed repeated fixed32 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularFixed32Field` once for each item in the array. + mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws + + // Called for each non-packed repeated fixed64 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularFixed64Field` once for each item in the array. + mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws + + // Called for each non-packed repeated sfixed32 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularSFixed32Field` once for each item in the array. + mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each non-packed repeated sfixed64 field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularSFixed64Field` once for each item in the array. + mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each non-packed repeated bool field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularBoolField` once for each item in the array. + mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws + + // Called for each non-packed repeated string field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularStringField` once for each item in the array. + mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws + + // Called for each non-packed repeated bytes field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularBytesField` once for each item in the array. + mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws + + /// Called for each repeated, unpacked enum field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularEnumField` once for each item in the array. + mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws + + /// Called for each repeated nested message field. The method is called once + /// with the complete array of values for the field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularMessageField` once for each item in the array. + mutating func visitRepeatedMessageField(value: [M], + fieldNumber: Int) throws + + /// Called for each repeated proto2 group field. + /// + /// A default implementation is provided that simply calls + /// `visitSingularGroupField` once for each item in the array. + mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws + + // Called for each packed, repeated float field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws + + // Called for each packed, repeated double field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws + + // Called for each packed, repeated int32 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each packed, repeated int64 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each packed, repeated uint32 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws + + // Called for each packed, repeated uint64 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws + + // Called for each packed, repeated sint32 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each packed, repeated sint64 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each packed, repeated fixed32 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws + + // Called for each packed, repeated fixed64 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws + + // Called for each packed, repeated sfixed32 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws + + // Called for each packed, repeated sfixed64 field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws + + // Called for each packed, repeated bool field. + /// + /// This is called once with the complete array of values for + /// the field. + /// + /// There is a default implementation that forwards to the non-packed + /// function. + mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws + + /// Called for each repeated, packed enum field. + /// The method is called once with the complete array of values for + /// the field. + /// + /// A default implementation is provided that simply forwards to + /// `visitRepeatedEnumField`. Implementors who need to handle packed fields + /// differently than unpacked fields can override this and provide distinct + /// implementations. + mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws + + /// Called for each map field with primitive values. The method is + /// called once with the complete dictionary of keys/values for the + /// field. + /// + /// There is no default implementation. This must be implemented. + mutating func visitMapField( + fieldType: _ProtobufMap.Type, + value: _ProtobufMap.BaseType, + fieldNumber: Int) throws + + /// Called for each map field with enum values. The method is called + /// once with the complete dictionary of keys/values for the field. + /// + /// There is no default implementation. This must be implemented. + mutating func visitMapField( + fieldType: _ProtobufEnumMap.Type, + value: _ProtobufEnumMap.BaseType, + fieldNumber: Int) throws where ValueType.RawValue == Int + + /// Called for each map field with message values. The method is + /// called once with the complete dictionary of keys/values for the + /// field. + /// + /// There is no default implementation. This must be implemented. + mutating func visitMapField( + fieldType: _ProtobufMessageMap.Type, + value: _ProtobufMessageMap.BaseType, + fieldNumber: Int) throws + + /// Called for each extension range. + mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws + + /// Called for each extension range. + mutating func visitExtensionFieldsAsMessageSet( + fields: ExtensionFieldValueSet, + start: Int, + end: Int) throws + + /// Called with the raw bytes that represent any unknown fields. + mutating func visitUnknown(bytes: Data) throws +} + +/// Forwarding default implementations of some visitor methods, for convenience. +extension Visitor { + + // Default definitions of numeric serializations. + // + // The 32-bit versions widen and delegate to 64-bit versions. + // The specialized integer codings delegate to standard Int/UInt. + // + // These "just work" for Hash and Text formats. Most of these work + // for JSON (32-bit integers are overridden to suppress quoting), + // and a few even work for Protobuf Binary (thanks to varint coding + // which erases the size difference between 32-bit and 64-bit ints). + + public mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { + try visitSingularDoubleField(value: Double(value), fieldNumber: fieldNumber) + } + public mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt64Field(value: Int64(value), fieldNumber: fieldNumber) + } + public mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: UInt64(value), fieldNumber: fieldNumber) + } + public mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) + } + public mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) + } + public mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { + try visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) + } + public mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { + try visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) + } + public mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { + try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) + } + public mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { + try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) + } + + // Default definitions of repeated serializations that just iterate and + // invoke the singular encoding. These "just work" for Protobuf Binary (encoder + // and size visitor), Protobuf Text, and Hash visitors. JSON format stores + // repeated values differently from singular, so overrides these. + + public mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { + for v in value { + try visitSingularFloatField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { + for v in value { + try visitSingularDoubleField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { + for v in value { + try visitSingularInt32Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { + for v in value { + try visitSingularInt64Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + for v in value { + try visitSingularUInt32Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + for v in value { + try visitSingularUInt64Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { + for v in value { + try visitSingularSInt32Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { + for v in value { + try visitSingularSInt64Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + for v in value { + try visitSingularFixed32Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + for v in value { + try visitSingularFixed64Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + for v in value { + try visitSingularSFixed32Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + for v in value { + try visitSingularSFixed64Field(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { + for v in value { + try visitSingularBoolField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { + for v in value { + try visitSingularStringField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { + for v in value { + try visitSingularBytesField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { + for v in value { + try visitSingularEnumField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { + for v in value { + try visitSingularMessageField(value: v, fieldNumber: fieldNumber) + } + } + + public mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { + for v in value { + try visitSingularGroupField(value: v, fieldNumber: fieldNumber) + } + } + + // Default definitions of packed serialization just defer to the + // repeated implementation. This works for Hash and JSON visitors + // (which do not distinguish packed vs. non-packed) but are + // overridden by Protobuf Binary and Text. + + public mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { + try visitRepeatedFloatField(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { + try visitRepeatedDoubleField(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { + try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { + try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { + try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { + try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { + try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { + try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { + try visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { + try visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { + try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { + try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { + try visitRepeatedBoolField(value: value, fieldNumber: fieldNumber) + } + + public mutating func visitPackedEnumField(value: [E], + fieldNumber: Int) throws { + try visitRepeatedEnumField(value: value, fieldNumber: fieldNumber) + } + + // Default handling for Groups is to treat them just like messages. + // This works for Text and Hash, but is overridden by Protobuf Binary + // format (which has a different encoding for groups) and JSON + // (which explicitly ignores all groups). + + public mutating func visitSingularGroupField(value: G, + fieldNumber: Int) throws { + try visitSingularMessageField(value: value, fieldNumber: fieldNumber) + } + + // Default handling of Extensions as a MessageSet to handing them just + // as plain extensions. Formats that what custom behavior can override + // it. + + public mutating func visitExtensionFieldsAsMessageSet( + fields: ExtensionFieldValueSet, + start: Int, + end: Int) throws { + try visitExtensionFields(fields: fields, start: start, end: end) + } + + // Default handling for Extensions is to forward the traverse to + // the ExtensionFieldValueSet. Formats that don't care about extensions + // can override to avoid it. + + /// Called for each extension range. + public mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { + try fields.traverse(visitor: &self, start: start, end: end) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift new file mode 100644 index 0000000..ea28c40 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift @@ -0,0 +1,70 @@ +// Sources/SwiftProtobuf/WireFormat.swift - Describes proto wire formats +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Types related to binary wire formats of encoded values. +/// +// ----------------------------------------------------------------------------- + +/// Denotes the wire format by which a value is encoded in binary form. +internal enum WireFormat: UInt8 { + case varint = 0 + case fixed64 = 1 + case lengthDelimited = 2 + case startGroup = 3 + case endGroup = 4 + case fixed32 = 5 +} + +extension WireFormat { + /// Information about the "MessageSet" format. Used when a Message has + /// the message_set_wire_format option enabled. + /// + /// Writing in MessageSet form means instead of writing the Extesions + /// normally as a simple fields, each gets written wrapped in a group: + /// repeated group Item = 1 { + /// required int32 type_id = 2; + /// required bytes message = 3; + /// } + /// Where the field number is the type_id, and the message is serilaized + /// into the bytes. + /// + /// The handling of unknown fields is ill defined. In proto1, they were + /// dropped. In the C++ for proto2, since it stores them in the unknowns + /// storage, if preserves any that are length delimited data (since that's + /// how the message also goes out). While the C++ is parsing, where the + /// unknowns fall in the flow of the group, sorta decides what happens. + /// Since it is ill defined, currently SwiftProtobuf will reflect out + /// anything set in the unknownStorage. During parsing, unknowns on the + /// message are preserved, but unknowns within the group are dropped (like + /// map items). Any extension in the MessageSet that isn't in the Regisry + /// being used at parse time will remain in a group and go into the + /// Messages's unknown fields (this way it reflects back out correctly). + internal enum MessageSet { + + enum FieldNumbers { + static let item = 1; + static let typeId = 2; + static let message = 3; + } + + enum Tags { + static let itemStart = FieldTag(fieldNumber: FieldNumbers.item, wireFormat: .startGroup) + static let itemEnd = FieldTag(fieldNumber: FieldNumbers.item, wireFormat: .endGroup) + static let typeId = FieldTag(fieldNumber: FieldNumbers.typeId, wireFormat: .varint) + static let message = FieldTag(fieldNumber: FieldNumbers.message, wireFormat: .lengthDelimited) + } + + // The size of all the tags needed to write out an Extension in MessageSet format. + static let itemTagsEncodedSize = + Tags.itemStart.encodedSize + Tags.itemEnd.encodedSize + + Tags.typeId.encodedSize + + Tags.message.encodedSize + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift new file mode 100644 index 0000000..f838ac6 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift @@ -0,0 +1,66 @@ +// Sources/SwiftProtobuf/ZigZag.swift - ZigZag encoding/decoding helpers +// +// Copyright (c) 2014 - 2016 Apple Inc. and the project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See LICENSE.txt for license information: +// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt +// +// ----------------------------------------------------------------------------- +/// +/// Helper functions to ZigZag encode and decode signed integers. +/// +// ----------------------------------------------------------------------------- + + +/// Contains helper methods to ZigZag encode and decode signed integers. +internal enum ZigZag { + + /// Return a 32-bit ZigZag-encoded value. + /// + /// ZigZag encodes signed integers into values that can be efficiently encoded with varint. + /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always + /// taking 10 bytes on the wire.) + /// + /// - Parameter value: A signed 32-bit integer. + /// - Returns: An unsigned 32-bit integer representing the ZigZag-encoded value. + static func encoded(_ value: Int32) -> UInt32 { + return UInt32(bitPattern: (value << 1) ^ (value >> 31)) + } + + /// Return a 64-bit ZigZag-encoded value. + /// + /// ZigZag encodes signed integers into values that can be efficiently encoded with varint. + /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always + /// taking 10 bytes on the wire.) + /// + /// - Parameter value: A signed 64-bit integer. + /// - Returns: An unsigned 64-bit integer representing the ZigZag-encoded value. + static func encoded(_ value: Int64) -> UInt64 { + return UInt64(bitPattern: (value << 1) ^ (value >> 63)) + } + + /// Return a 32-bit ZigZag-decoded value. + /// + /// ZigZag enocdes signed integers into values that can be efficiently encoded with varint. + /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always + /// taking 10 bytes on the wire.) + /// + /// - Parameter value: An unsigned 32-bit ZagZag-encoded integer. + /// - Returns: The signed 32-bit decoded value. + static func decoded(_ value: UInt32) -> Int32 { + return Int32(value >> 1) ^ -Int32(value & 1) + } + + /// Return a 64-bit ZigZag-decoded value. + /// + /// ZigZag enocdes signed integers into values that can be efficiently encoded with varint. + /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always + /// taking 10 bytes on the wire.) + /// + /// - Parameter value: An unsigned 64-bit ZigZag-encoded integer. + /// - Returns: The signed 64-bit decoded value. + static func decoded(_ value: UInt64) -> Int64 { + return Int64(value >> 1) ^ -Int64(value & 1) + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift new file mode 100644 index 0000000..3f56e2f --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift @@ -0,0 +1,234 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/any.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// `Any` contains an arbitrary serialized protocol buffer message along with a +/// URL that describes the type of the serialized message. +/// +/// Protobuf library provides support to pack/unpack Any values in the form +/// of utility functions or additional generated methods of the Any type. +/// +/// Example 1: Pack and unpack a message in C++. +/// +/// Foo foo = ...; +/// Any any; +/// any.PackFrom(foo); +/// ... +/// if (any.UnpackTo(&foo)) { +/// ... +/// } +/// +/// Example 2: Pack and unpack a message in Java. +/// +/// Foo foo = ...; +/// Any any = Any.pack(foo); +/// ... +/// if (any.is(Foo.class)) { +/// foo = any.unpack(Foo.class); +/// } +/// +/// Example 3: Pack and unpack a message in Python. +/// +/// foo = Foo(...) +/// any = Any() +/// any.Pack(foo) +/// ... +/// if any.Is(Foo.DESCRIPTOR): +/// any.Unpack(foo) +/// ... +/// +/// Example 4: Pack and unpack a message in Go +/// +/// foo := &pb.Foo{...} +/// any, err := ptypes.MarshalAny(foo) +/// ... +/// foo := &pb.Foo{} +/// if err := ptypes.UnmarshalAny(any, foo); err != nil { +/// ... +/// } +/// +/// The pack methods provided by protobuf library will by default use +/// 'type.googleapis.com/full.type.name' as the type URL and the unpack +/// methods only use the fully qualified type name after the last '/' +/// in the type URL, for example "foo.bar.com/x/y.z" will yield type +/// name "y.z". +/// +/// +/// JSON +/// ==== +/// The JSON representation of an `Any` value uses the regular +/// representation of the deserialized, embedded message, with an +/// additional field `@type` which contains the type URL. Example: +/// +/// package google.profile; +/// message Person { +/// string first_name = 1; +/// string last_name = 2; +/// } +/// +/// { +/// "@type": "type.googleapis.com/google.profile.Person", +/// "firstName": , +/// "lastName": +/// } +/// +/// If the embedded message type is well-known and has a custom JSON +/// representation, that representation will be embedded adding a field +/// `value` which holds the custom JSON in addition to the `@type` +/// field. Example (for message [google.protobuf.Duration][]): +/// +/// { +/// "@type": "type.googleapis.com/google.protobuf.Duration", +/// "value": "1.212s" +/// } +public struct Google_Protobuf_Any { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// A URL/resource name that uniquely identifies the type of the serialized + /// protocol buffer message. This string must contain at least + /// one "/" character. The last segment of the URL's path must represent + /// the fully qualified name of the type (as in + /// `path/google.protobuf.Duration`). The name should be in a canonical form + /// (e.g., leading "." is not accepted). + /// + /// In practice, teams usually precompile into the binary all types that they + /// expect it to use in the context of Any. However, for URLs which use the + /// scheme `http`, `https`, or no scheme, one can optionally set up a type + /// server that maps type URLs to message definitions as follows: + /// + /// * If no scheme is provided, `https` is assumed. + /// * An HTTP GET on the URL must yield a [google.protobuf.Type][] + /// value in binary format, or produce an error. + /// * Applications are allowed to cache lookup results based on the + /// URL, or have them precompiled into a binary to avoid any + /// lookup. Therefore, binary compatibility needs to be preserved + /// on changes to types. (Use versioned type names to manage + /// breaking changes.) + /// + /// Note: this functionality is not currently available in the official + /// protobuf release, and it is not used for type URLs beginning with + /// type.googleapis.com. + /// + /// Schemes other than `http`, `https` (or the empty scheme) might be + /// used with implementation specific semantics. + public var typeURL: String { + get {return _storage._typeURL} + set {_uniqueStorage()._typeURL = newValue} + } + + /// Must be a valid serialized protocol buffer of the above specified type. + public var value: Data { + get {return _storage._value} + set {_uniqueStorage()._value = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + internal var _storage = _StorageClass.defaultInstance +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Any: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Any" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "type_url"), + 2: .same(proto: "value"), + ] + + typealias _StorageClass = AnyMessageStorage + + internal mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._typeURL) + case 2: try decoder.decodeSingularBytesField(value: &_storage._value) + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + try _storage.preTraverse() + if !_storage._typeURL.isEmpty { + try visitor.visitSingularStringField(value: _storage._typeURL, fieldNumber: 1) + } + if !_storage._value.isEmpty { + try visitor.visitSingularBytesField(value: _storage._value, fieldNumber: 2) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Any, rhs: Google_Protobuf_Any) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = lhs._storage.isEqualTo(other: rhs._storage) + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift new file mode 100644 index 0000000..268c436 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift @@ -0,0 +1,476 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/api.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Api is a light-weight descriptor for an API Interface. +/// +/// Interfaces are also described as "protocol buffer services" in some contexts, +/// such as by the "service" keyword in a .proto file, but they are different +/// from API Services, which represent a concrete implementation of an interface +/// as opposed to simply a description of methods and bindings. They are also +/// sometimes simply referred to as "APIs" in other contexts, such as the name of +/// this message itself. See https://cloud.google.com/apis/design/glossary for +/// detailed terminology. +public struct Google_Protobuf_Api { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The fully qualified name of this interface, including package name + /// followed by the interface's simple name. + public var name: String { + get {return _storage._name} + set {_uniqueStorage()._name = newValue} + } + + /// The methods of this interface, in unspecified order. + public var methods: [Google_Protobuf_Method] { + get {return _storage._methods} + set {_uniqueStorage()._methods = newValue} + } + + /// Any metadata attached to the interface. + public var options: [Google_Protobuf_Option] { + get {return _storage._options} + set {_uniqueStorage()._options = newValue} + } + + /// A version string for this interface. If specified, must have the form + /// `major-version.minor-version`, as in `1.10`. If the minor version is + /// omitted, it defaults to zero. If the entire version field is empty, the + /// major version is derived from the package name, as outlined below. If the + /// field is not empty, the version in the package name will be verified to be + /// consistent with what is provided here. + /// + /// The versioning schema uses [semantic + /// versioning](http://semver.org) where the major version number + /// indicates a breaking change and the minor version an additive, + /// non-breaking change. Both version numbers are signals to users + /// what to expect from different versions, and should be carefully + /// chosen based on the product plan. + /// + /// The major version is also reflected in the package name of the + /// interface, which must end in `v`, as in + /// `google.feature.v1`. For major versions 0 and 1, the suffix can + /// be omitted. Zero major versions must only be used for + /// experimental, non-GA interfaces. + public var version: String { + get {return _storage._version} + set {_uniqueStorage()._version = newValue} + } + + /// Source context for the protocol buffer service represented by this + /// message. + public var sourceContext: Google_Protobuf_SourceContext { + get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} + set {_uniqueStorage()._sourceContext = newValue} + } + /// Returns true if `sourceContext` has been explicitly set. + public var hasSourceContext: Bool {return _storage._sourceContext != nil} + /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. + public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} + + /// Included interfaces. See [Mixin][]. + public var mixins: [Google_Protobuf_Mixin] { + get {return _storage._mixins} + set {_uniqueStorage()._mixins = newValue} + } + + /// The source syntax of the service. + public var syntax: Google_Protobuf_Syntax { + get {return _storage._syntax} + set {_uniqueStorage()._syntax = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +/// Method represents a method of an API interface. +public struct Google_Protobuf_Method { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The simple name of this method. + public var name: String = String() + + /// A URL of the input message type. + public var requestTypeURL: String = String() + + /// If true, the request is streamed. + public var requestStreaming: Bool = false + + /// The URL of the output message type. + public var responseTypeURL: String = String() + + /// If true, the response is streamed. + public var responseStreaming: Bool = false + + /// Any metadata attached to the method. + public var options: [Google_Protobuf_Option] = [] + + /// The source syntax of this method. + public var syntax: Google_Protobuf_Syntax = .proto2 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Declares an API Interface to be included in this interface. The including +/// interface must redeclare all the methods from the included interface, but +/// documentation and options are inherited as follows: +/// +/// - If after comment and whitespace stripping, the documentation +/// string of the redeclared method is empty, it will be inherited +/// from the original method. +/// +/// - Each annotation belonging to the service config (http, +/// visibility) which is not set in the redeclared method will be +/// inherited. +/// +/// - If an http annotation is inherited, the path pattern will be +/// modified as follows. Any version prefix will be replaced by the +/// version of the including interface plus the [root][] path if +/// specified. +/// +/// Example of a simple mixin: +/// +/// package google.acl.v1; +/// service AccessControl { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v1/{resource=**}:getAcl"; +/// } +/// } +/// +/// package google.storage.v2; +/// service Storage { +/// rpc GetAcl(GetAclRequest) returns (Acl); +/// +/// // Get a data record. +/// rpc GetData(GetDataRequest) returns (Data) { +/// option (google.api.http).get = "/v2/{resource=**}"; +/// } +/// } +/// +/// Example of a mixin configuration: +/// +/// apis: +/// - name: google.storage.v2.Storage +/// mixins: +/// - name: google.acl.v1.AccessControl +/// +/// The mixin construct implies that all methods in `AccessControl` are +/// also declared with same name and request/response types in +/// `Storage`. A documentation generator or annotation processor will +/// see the effective `Storage.GetAcl` method after inherting +/// documentation and annotations as follows: +/// +/// service Storage { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v2/{resource=**}:getAcl"; +/// } +/// ... +/// } +/// +/// Note how the version in the path pattern changed from `v1` to `v2`. +/// +/// If the `root` field in the mixin is specified, it should be a +/// relative path under which inherited HTTP paths are placed. Example: +/// +/// apis: +/// - name: google.storage.v2.Storage +/// mixins: +/// - name: google.acl.v1.AccessControl +/// root: acls +/// +/// This implies the following inherited HTTP annotation: +/// +/// service Storage { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; +/// } +/// ... +/// } +public struct Google_Protobuf_Mixin { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The fully qualified name of the interface which is included. + public var name: String = String() + + /// If non-empty specifies a path under which inherited HTTP paths + /// are rooted. + public var root: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Api: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Api" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "methods"), + 3: .same(proto: "options"), + 4: .same(proto: "version"), + 5: .standard(proto: "source_context"), + 6: .same(proto: "mixins"), + 7: .same(proto: "syntax"), + ] + + fileprivate class _StorageClass { + var _name: String = String() + var _methods: [Google_Protobuf_Method] = [] + var _options: [Google_Protobuf_Option] = [] + var _version: String = String() + var _sourceContext: Google_Protobuf_SourceContext? = nil + var _mixins: [Google_Protobuf_Mixin] = [] + var _syntax: Google_Protobuf_Syntax = .proto2 + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _name = source._name + _methods = source._methods + _options = source._options + _version = source._version + _sourceContext = source._sourceContext + _mixins = source._mixins + _syntax = source._syntax + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._name) + case 2: try decoder.decodeRepeatedMessageField(value: &_storage._methods) + case 3: try decoder.decodeRepeatedMessageField(value: &_storage._options) + case 4: try decoder.decodeSingularStringField(value: &_storage._version) + case 5: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) + case 6: try decoder.decodeRepeatedMessageField(value: &_storage._mixins) + case 7: try decoder.decodeSingularEnumField(value: &_storage._syntax) + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if !_storage._name.isEmpty { + try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) + } + if !_storage._methods.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._methods, fieldNumber: 2) + } + if !_storage._options.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 3) + } + if !_storage._version.isEmpty { + try visitor.visitSingularStringField(value: _storage._version, fieldNumber: 4) + } + if let v = _storage._sourceContext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + } + if !_storage._mixins.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._mixins, fieldNumber: 6) + } + if _storage._syntax != .proto2 { + try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 7) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Api, rhs: Google_Protobuf_Api) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._name != rhs_storage._name {return false} + if _storage._methods != rhs_storage._methods {return false} + if _storage._options != rhs_storage._options {return false} + if _storage._version != rhs_storage._version {return false} + if _storage._sourceContext != rhs_storage._sourceContext {return false} + if _storage._mixins != rhs_storage._mixins {return false} + if _storage._syntax != rhs_storage._syntax {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Method: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Method" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .standard(proto: "request_type_url"), + 3: .standard(proto: "request_streaming"), + 4: .standard(proto: "response_type_url"), + 5: .standard(proto: "response_streaming"), + 6: .same(proto: "options"), + 7: .same(proto: "syntax"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &self.name) + case 2: try decoder.decodeSingularStringField(value: &self.requestTypeURL) + case 3: try decoder.decodeSingularBoolField(value: &self.requestStreaming) + case 4: try decoder.decodeSingularStringField(value: &self.responseTypeURL) + case 5: try decoder.decodeSingularBoolField(value: &self.responseStreaming) + case 6: try decoder.decodeRepeatedMessageField(value: &self.options) + case 7: try decoder.decodeSingularEnumField(value: &self.syntax) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if !self.requestTypeURL.isEmpty { + try visitor.visitSingularStringField(value: self.requestTypeURL, fieldNumber: 2) + } + if self.requestStreaming != false { + try visitor.visitSingularBoolField(value: self.requestStreaming, fieldNumber: 3) + } + if !self.responseTypeURL.isEmpty { + try visitor.visitSingularStringField(value: self.responseTypeURL, fieldNumber: 4) + } + if self.responseStreaming != false { + try visitor.visitSingularBoolField(value: self.responseStreaming, fieldNumber: 5) + } + if !self.options.isEmpty { + try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 6) + } + if self.syntax != .proto2 { + try visitor.visitSingularEnumField(value: self.syntax, fieldNumber: 7) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Method, rhs: Google_Protobuf_Method) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.requestTypeURL != rhs.requestTypeURL {return false} + if lhs.requestStreaming != rhs.requestStreaming {return false} + if lhs.responseTypeURL != rhs.responseTypeURL {return false} + if lhs.responseStreaming != rhs.responseStreaming {return false} + if lhs.options != rhs.options {return false} + if lhs.syntax != rhs.syntax {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Mixin: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Mixin" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "root"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &self.name) + case 2: try decoder.decodeSingularStringField(value: &self.root) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if !self.root.isEmpty { + try visitor.visitSingularStringField(value: self.root, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Mixin, rhs: Google_Protobuf_Mixin) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.root != rhs.root {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift new file mode 100644 index 0000000..86db1a0 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift @@ -0,0 +1,169 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/duration.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// A Duration represents a signed, fixed-length span of time represented +/// as a count of seconds and fractions of seconds at nanosecond +/// resolution. It is independent of any calendar and concepts like "day" +/// or "month". It is related to Timestamp in that the difference between +/// two Timestamp values is a Duration and it can be added or subtracted +/// from a Timestamp. Range is approximately +-10,000 years. +/// +/// # Examples +/// +/// Example 1: Compute Duration from two Timestamps in pseudo code. +/// +/// Timestamp start = ...; +/// Timestamp end = ...; +/// Duration duration = ...; +/// +/// duration.seconds = end.seconds - start.seconds; +/// duration.nanos = end.nanos - start.nanos; +/// +/// if (duration.seconds < 0 && duration.nanos > 0) { +/// duration.seconds += 1; +/// duration.nanos -= 1000000000; +/// } else if (durations.seconds > 0 && duration.nanos < 0) { +/// duration.seconds -= 1; +/// duration.nanos += 1000000000; +/// } +/// +/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +/// +/// Timestamp start = ...; +/// Duration duration = ...; +/// Timestamp end = ...; +/// +/// end.seconds = start.seconds + duration.seconds; +/// end.nanos = start.nanos + duration.nanos; +/// +/// if (end.nanos < 0) { +/// end.seconds -= 1; +/// end.nanos += 1000000000; +/// } else if (end.nanos >= 1000000000) { +/// end.seconds += 1; +/// end.nanos -= 1000000000; +/// } +/// +/// Example 3: Compute Duration from datetime.timedelta in Python. +/// +/// td = datetime.timedelta(days=3, minutes=10) +/// duration = Duration() +/// duration.FromTimedelta(td) +/// +/// # JSON Mapping +/// +/// In JSON format, the Duration type is encoded as a string rather than an +/// object, where the string ends in the suffix "s" (indicating seconds) and +/// is preceded by the number of seconds, with nanoseconds expressed as +/// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +/// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +/// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +/// microsecond should be expressed in JSON format as "3.000001s". +public struct Google_Protobuf_Duration { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Signed seconds of the span of time. Must be from -315,576,000,000 + /// to +315,576,000,000 inclusive. Note: these bounds are computed from: + /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + public var seconds: Int64 = 0 + + /// Signed fractions of a second at nanosecond resolution of the span + /// of time. Durations less than one second are represented with a 0 + /// `seconds` field and a positive or negative `nanos` field. For durations + /// of one second or more, a non-zero value for the `nanos` field must be + /// of the same sign as the `seconds` field. Must be from -999,999,999 + /// to +999,999,999 inclusive. + public var nanos: Int32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Duration: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Duration" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "seconds"), + 2: .same(proto: "nanos"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularInt64Field(value: &self.seconds) + case 2: try decoder.decodeSingularInt32Field(value: &self.nanos) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.seconds != 0 { + try visitor.visitSingularInt64Field(value: self.seconds, fieldNumber: 1) + } + if self.nanos != 0 { + try visitor.visitSingularInt32Field(value: self.nanos, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Duration, rhs: Google_Protobuf_Duration) -> Bool { + if lhs.seconds != rhs.seconds {return false} + if lhs.nanos != rhs.nanos {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift new file mode 100644 index 0000000..a951fc5 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift @@ -0,0 +1,91 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/empty.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// A generic empty message that you can re-use to avoid defining duplicated +/// empty messages in your APIs. A typical example is to use it as the request +/// or the response type of an API method. For instance: +/// +/// service Foo { +/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +/// } +/// +/// The JSON representation for `Empty` is empty JSON object `{}`. +public struct Google_Protobuf_Empty { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Empty: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Empty" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Empty, rhs: Google_Protobuf_Empty) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift new file mode 100644 index 0000000..bea1b11 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift @@ -0,0 +1,294 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/field_mask.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// `FieldMask` represents a set of symbolic field paths, for example: +/// +/// paths: "f.a" +/// paths: "f.b.d" +/// +/// Here `f` represents a field in some root message, `a` and `b` +/// fields in the message found in `f`, and `d` a field found in the +/// message in `f.b`. +/// +/// Field masks are used to specify a subset of fields that should be +/// returned by a get operation or modified by an update operation. +/// Field masks also have a custom JSON encoding (see below). +/// +/// # Field Masks in Projections +/// +/// When used in the context of a projection, a response message or +/// sub-message is filtered by the API to only contain those fields as +/// specified in the mask. For example, if the mask in the previous +/// example is applied to a response message as follows: +/// +/// f { +/// a : 22 +/// b { +/// d : 1 +/// x : 2 +/// } +/// y : 13 +/// } +/// z: 8 +/// +/// The result will not contain specific values for fields x,y and z +/// (their value will be set to the default, and omitted in proto text +/// output): +/// +/// +/// f { +/// a : 22 +/// b { +/// d : 1 +/// } +/// } +/// +/// A repeated field is not allowed except at the last position of a +/// paths string. +/// +/// If a FieldMask object is not present in a get operation, the +/// operation applies to all fields (as if a FieldMask of all fields +/// had been specified). +/// +/// Note that a field mask does not necessarily apply to the +/// top-level response message. In case of a REST get operation, the +/// field mask applies directly to the response, but in case of a REST +/// list operation, the mask instead applies to each individual message +/// in the returned resource list. In case of a REST custom method, +/// other definitions may be used. Where the mask applies will be +/// clearly documented together with its declaration in the API. In +/// any case, the effect on the returned resource/resources is required +/// behavior for APIs. +/// +/// # Field Masks in Update Operations +/// +/// A field mask in update operations specifies which fields of the +/// targeted resource are going to be updated. The API is required +/// to only change the values of the fields as specified in the mask +/// and leave the others untouched. If a resource is passed in to +/// describe the updated values, the API ignores the values of all +/// fields not covered by the mask. +/// +/// If a repeated field is specified for an update operation, new values will +/// be appended to the existing repeated field in the target resource. Note that +/// a repeated field is only allowed in the last position of a `paths` string. +/// +/// If a sub-message is specified in the last position of the field mask for an +/// update operation, then new value will be merged into the existing sub-message +/// in the target resource. +/// +/// For example, given the target message: +/// +/// f { +/// b { +/// d: 1 +/// x: 2 +/// } +/// c: [1] +/// } +/// +/// And an update message: +/// +/// f { +/// b { +/// d: 10 +/// } +/// c: [2] +/// } +/// +/// then if the field mask is: +/// +/// paths: ["f.b", "f.c"] +/// +/// then the result will be: +/// +/// f { +/// b { +/// d: 10 +/// x: 2 +/// } +/// c: [1, 2] +/// } +/// +/// An implementation may provide options to override this default behavior for +/// repeated and message fields. +/// +/// In order to reset a field's value to the default, the field must +/// be in the mask and set to the default value in the provided resource. +/// Hence, in order to reset all fields of a resource, provide a default +/// instance of the resource and set all fields in the mask, or do +/// not provide a mask as described below. +/// +/// If a field mask is not present on update, the operation applies to +/// all fields (as if a field mask of all fields has been specified). +/// Note that in the presence of schema evolution, this may mean that +/// fields the client does not know and has therefore not filled into +/// the request will be reset to their default. If this is unwanted +/// behavior, a specific service may require a client to always specify +/// a field mask, producing an error if not. +/// +/// As with get operations, the location of the resource which +/// describes the updated values in the request message depends on the +/// operation kind. In any case, the effect of the field mask is +/// required to be honored by the API. +/// +/// ## Considerations for HTTP REST +/// +/// The HTTP kind of an update operation which uses a field mask must +/// be set to PATCH instead of PUT in order to satisfy HTTP semantics +/// (PUT must only be used for full updates). +/// +/// # JSON Encoding of Field Masks +/// +/// In JSON, a field mask is encoded as a single string where paths are +/// separated by a comma. Fields name in each path are converted +/// to/from lower-camel naming conventions. +/// +/// As an example, consider the following message declarations: +/// +/// message Profile { +/// User user = 1; +/// Photo photo = 2; +/// } +/// message User { +/// string display_name = 1; +/// string address = 2; +/// } +/// +/// In proto a field mask for `Profile` may look as such: +/// +/// mask { +/// paths: "user.display_name" +/// paths: "photo" +/// } +/// +/// In JSON, the same mask is represented as below: +/// +/// { +/// mask: "user.displayName,photo" +/// } +/// +/// # Field Masks and Oneof Fields +/// +/// Field masks treat fields in oneofs just as regular fields. Consider the +/// following message: +/// +/// message SampleMessage { +/// oneof test_oneof { +/// string name = 4; +/// SubMessage sub_message = 9; +/// } +/// } +/// +/// The field mask can be: +/// +/// mask { +/// paths: "name" +/// } +/// +/// Or: +/// +/// mask { +/// paths: "sub_message" +/// } +/// +/// Note that oneof type names ("test_oneof" in this case) cannot be used in +/// paths. +/// +/// ## Field Mask Verification +/// +/// The implementation of any API method which has a FieldMask type field in the +/// request should verify the included field paths, and return an +/// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. +public struct Google_Protobuf_FieldMask { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The set of field mask paths. + public var paths: [String] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_FieldMask: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".FieldMask" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "paths"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeRepeatedStringField(value: &self.paths) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.paths.isEmpty { + try visitor.visitRepeatedStringField(value: self.paths, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_FieldMask, rhs: Google_Protobuf_FieldMask) -> Bool { + if lhs.paths != rhs.paths {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift new file mode 100644 index 0000000..b9c7627 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift @@ -0,0 +1,98 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/source_context.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// `SourceContext` represents information about the source of a +/// protobuf element, like the file in which it is defined. +public struct Google_Protobuf_SourceContext { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The path-qualified name of the .proto file that contained the associated + /// protobuf element. For example: `"google/protobuf/source_context.proto"`. + public var fileName: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_SourceContext: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SourceContext" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "file_name"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &self.fileName) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.fileName.isEmpty { + try visitor.visitSingularStringField(value: self.fileName, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_SourceContext, rhs: Google_Protobuf_SourceContext) -> Bool { + if lhs.fileName != rhs.fileName {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift new file mode 100644 index 0000000..eceb43c --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift @@ -0,0 +1,417 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/struct.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// `NullValue` is a singleton enumeration to represent the null value for the +/// `Value` type union. +/// +/// The JSON representation for `NullValue` is JSON `null`. +public enum Google_Protobuf_NullValue: SwiftProtobuf.Enum { + public typealias RawValue = Int + + /// Null value. + case nullValue // = 0 + case UNRECOGNIZED(Int) + + public init() { + self = .nullValue + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .nullValue + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .nullValue: return 0 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Google_Protobuf_NullValue: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Google_Protobuf_NullValue] = [ + .nullValue, + ] +} + +#endif // swift(>=4.2) + +/// `Struct` represents a structured data value, consisting of fields +/// which map to dynamically typed values. In some languages, `Struct` +/// might be supported by a native representation. For example, in +/// scripting languages like JS a struct is represented as an +/// object. The details of that representation are described together +/// with the proto support for the language. +/// +/// The JSON representation for `Struct` is JSON object. +public struct Google_Protobuf_Struct { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Unordered map of dynamically typed values. + public var fields: Dictionary = [:] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// `Value` represents a dynamically typed value which can be either +/// null, a number, a string, a boolean, a recursive struct value, or a +/// list of values. A producer of value is expected to set one of that +/// variants, absence of any variant indicates an error. +/// +/// The JSON representation for `Value` is JSON value. +public struct Google_Protobuf_Value { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The kind of value. + public var kind: OneOf_Kind? { + get {return _storage._kind} + set {_uniqueStorage()._kind = newValue} + } + + /// Represents a null value. + public var nullValue: Google_Protobuf_NullValue { + get { + if case .nullValue(let v)? = _storage._kind {return v} + return .nullValue + } + set {_uniqueStorage()._kind = .nullValue(newValue)} + } + + /// Represents a double value. + public var numberValue: Double { + get { + if case .numberValue(let v)? = _storage._kind {return v} + return 0 + } + set {_uniqueStorage()._kind = .numberValue(newValue)} + } + + /// Represents a string value. + public var stringValue: String { + get { + if case .stringValue(let v)? = _storage._kind {return v} + return String() + } + set {_uniqueStorage()._kind = .stringValue(newValue)} + } + + /// Represents a boolean value. + public var boolValue: Bool { + get { + if case .boolValue(let v)? = _storage._kind {return v} + return false + } + set {_uniqueStorage()._kind = .boolValue(newValue)} + } + + /// Represents a structured value. + public var structValue: Google_Protobuf_Struct { + get { + if case .structValue(let v)? = _storage._kind {return v} + return Google_Protobuf_Struct() + } + set {_uniqueStorage()._kind = .structValue(newValue)} + } + + /// Represents a repeated `Value`. + public var listValue: Google_Protobuf_ListValue { + get { + if case .listValue(let v)? = _storage._kind {return v} + return Google_Protobuf_ListValue() + } + set {_uniqueStorage()._kind = .listValue(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// The kind of value. + public enum OneOf_Kind: Equatable { + /// Represents a null value. + case nullValue(Google_Protobuf_NullValue) + /// Represents a double value. + case numberValue(Double) + /// Represents a string value. + case stringValue(String) + /// Represents a boolean value. + case boolValue(Bool) + /// Represents a structured value. + case structValue(Google_Protobuf_Struct) + /// Represents a repeated `Value`. + case listValue(Google_Protobuf_ListValue) + + #if !swift(>=4.1) + public static func ==(lhs: Google_Protobuf_Value.OneOf_Kind, rhs: Google_Protobuf_Value.OneOf_Kind) -> Bool { + switch (lhs, rhs) { + case (.nullValue(let l), .nullValue(let r)): return l == r + case (.numberValue(let l), .numberValue(let r)): return l == r + case (.stringValue(let l), .stringValue(let r)): return l == r + case (.boolValue(let l), .boolValue(let r)): return l == r + case (.structValue(let l), .structValue(let r)): return l == r + case (.listValue(let l), .listValue(let r)): return l == r + default: return false + } + } + #endif + } + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +/// `ListValue` is a wrapper around a repeated field of values. +/// +/// The JSON representation for `ListValue` is JSON array. +public struct Google_Protobuf_ListValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Repeated field of dynamically typed values. + public var values: [Google_Protobuf_Value] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_NullValue: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "NULL_VALUE"), + ] +} + +extension Google_Protobuf_Struct: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Struct" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "fields"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: &self.fields) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.fields.isEmpty { + try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: self.fields, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Struct, rhs: Google_Protobuf_Struct) -> Bool { + if lhs.fields != rhs.fields {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Value" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "null_value"), + 2: .standard(proto: "number_value"), + 3: .standard(proto: "string_value"), + 4: .standard(proto: "bool_value"), + 5: .standard(proto: "struct_value"), + 6: .standard(proto: "list_value"), + ] + + fileprivate class _StorageClass { + var _kind: Google_Protobuf_Value.OneOf_Kind? + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _kind = source._kind + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: + if _storage._kind != nil {try decoder.handleConflictingOneOf()} + var v: Google_Protobuf_NullValue? + try decoder.decodeSingularEnumField(value: &v) + if let v = v {_storage._kind = .nullValue(v)} + case 2: + if _storage._kind != nil {try decoder.handleConflictingOneOf()} + var v: Double? + try decoder.decodeSingularDoubleField(value: &v) + if let v = v {_storage._kind = .numberValue(v)} + case 3: + if _storage._kind != nil {try decoder.handleConflictingOneOf()} + var v: String? + try decoder.decodeSingularStringField(value: &v) + if let v = v {_storage._kind = .stringValue(v)} + case 4: + if _storage._kind != nil {try decoder.handleConflictingOneOf()} + var v: Bool? + try decoder.decodeSingularBoolField(value: &v) + if let v = v {_storage._kind = .boolValue(v)} + case 5: + var v: Google_Protobuf_Struct? + if let current = _storage._kind { + try decoder.handleConflictingOneOf() + if case .structValue(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v {_storage._kind = .structValue(v)} + case 6: + var v: Google_Protobuf_ListValue? + if let current = _storage._kind { + try decoder.handleConflictingOneOf() + if case .listValue(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v {_storage._kind = .listValue(v)} + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + switch _storage._kind { + case .nullValue(let v)?: + try visitor.visitSingularEnumField(value: v, fieldNumber: 1) + case .numberValue(let v)?: + try visitor.visitSingularDoubleField(value: v, fieldNumber: 2) + case .stringValue(let v)?: + try visitor.visitSingularStringField(value: v, fieldNumber: 3) + case .boolValue(let v)?: + try visitor.visitSingularBoolField(value: v, fieldNumber: 4) + case .structValue(let v)?: + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + case .listValue(let v)?: + try visitor.visitSingularMessageField(value: v, fieldNumber: 6) + case nil: break + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Value, rhs: Google_Protobuf_Value) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._kind != rhs_storage._kind {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_ListValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ListValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "values"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeRepeatedMessageField(value: &self.values) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.values.isEmpty { + try visitor.visitRepeatedMessageField(value: self.values, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_ListValue, rhs: Google_Protobuf_ListValue) -> Bool { + if lhs.values != rhs.values {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift new file mode 100644 index 0000000..a9d40de --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift @@ -0,0 +1,189 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/timestamp.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// A Timestamp represents a point in time independent of any time zone or local +/// calendar, encoded as a count of seconds and fractions of seconds at +/// nanosecond resolution. The count is relative to an epoch at UTC midnight on +/// January 1, 1970, in the proleptic Gregorian calendar which extends the +/// Gregorian calendar backwards to year one. +/// +/// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap +/// second table is needed for interpretation, using a [24-hour linear +/// smear](https://developers.google.com/time/smear). +/// +/// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By +/// restricting to that range, we ensure that we can convert to and from [RFC +/// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. +/// +/// # Examples +/// +/// Example 1: Compute Timestamp from POSIX `time()`. +/// +/// Timestamp timestamp; +/// timestamp.set_seconds(time(NULL)); +/// timestamp.set_nanos(0); +/// +/// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +/// +/// struct timeval tv; +/// gettimeofday(&tv, NULL); +/// +/// Timestamp timestamp; +/// timestamp.set_seconds(tv.tv_sec); +/// timestamp.set_nanos(tv.tv_usec * 1000); +/// +/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +/// +/// FILETIME ft; +/// GetSystemTimeAsFileTime(&ft); +/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +/// +/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +/// Timestamp timestamp; +/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +/// +/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +/// +/// long millis = System.currentTimeMillis(); +/// +/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +/// .setNanos((int) ((millis % 1000) * 1000000)).build(); +/// +/// +/// Example 5: Compute Timestamp from current time in Python. +/// +/// timestamp = Timestamp() +/// timestamp.GetCurrentTime() +/// +/// # JSON Mapping +/// +/// In JSON format, the Timestamp type is encoded as a string in the +/// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +/// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +/// where {year} is always expressed using four digits while {month}, {day}, +/// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +/// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +/// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +/// is required. A proto3 JSON serializer should always use UTC (as indicated by +/// "Z") when printing the Timestamp type and a proto3 JSON parser should be +/// able to accept both UTC and other timezones (as indicated by an offset). +/// +/// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +/// 01:30 UTC on January 15, 2017. +/// +/// In JavaScript, one can convert a Date object to this format using the +/// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) +/// method. In Python, a standard `datetime.datetime` object can be converted +/// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) +/// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one +/// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( +/// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D +/// ) to obtain a formatter capable of generating timestamps in this format. +public struct Google_Protobuf_Timestamp { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Represents seconds of UTC time since Unix epoch + /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + /// 9999-12-31T23:59:59Z inclusive. + public var seconds: Int64 = 0 + + /// Non-negative fractions of a second at nanosecond resolution. Negative + /// second values with fractions must still have non-negative nanos values + /// that count forward in time. Must be from 0 to 999,999,999 + /// inclusive. + public var nanos: Int32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Timestamp: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Timestamp" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "seconds"), + 2: .same(proto: "nanos"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularInt64Field(value: &self.seconds) + case 2: try decoder.decodeSingularInt32Field(value: &self.nanos) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.seconds != 0 { + try visitor.visitSingularInt64Field(value: self.seconds, fieldNumber: 1) + } + if self.nanos != 0 { + try visitor.visitSingularInt32Field(value: self.nanos, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Timestamp, rhs: Google_Protobuf_Timestamp) -> Bool { + if lhs.seconds != rhs.seconds {return false} + if lhs.nanos != rhs.nanos {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift new file mode 100644 index 0000000..aedf640 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift @@ -0,0 +1,924 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/type.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// The syntax in which a protocol buffer element is defined. +public enum Google_Protobuf_Syntax: SwiftProtobuf.Enum { + public typealias RawValue = Int + + /// Syntax `proto2`. + case proto2 // = 0 + + /// Syntax `proto3`. + case proto3 // = 1 + case UNRECOGNIZED(Int) + + public init() { + self = .proto2 + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .proto2 + case 1: self = .proto3 + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .proto2: return 0 + case .proto3: return 1 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Google_Protobuf_Syntax: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Google_Protobuf_Syntax] = [ + .proto2, + .proto3, + ] +} + +#endif // swift(>=4.2) + +/// A protocol buffer message type. +public struct Google_Protobuf_Type { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The fully qualified message name. + public var name: String { + get {return _storage._name} + set {_uniqueStorage()._name = newValue} + } + + /// The list of fields. + public var fields: [Google_Protobuf_Field] { + get {return _storage._fields} + set {_uniqueStorage()._fields = newValue} + } + + /// The list of types appearing in `oneof` definitions in this type. + public var oneofs: [String] { + get {return _storage._oneofs} + set {_uniqueStorage()._oneofs = newValue} + } + + /// The protocol buffer options. + public var options: [Google_Protobuf_Option] { + get {return _storage._options} + set {_uniqueStorage()._options = newValue} + } + + /// The source context. + public var sourceContext: Google_Protobuf_SourceContext { + get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} + set {_uniqueStorage()._sourceContext = newValue} + } + /// Returns true if `sourceContext` has been explicitly set. + public var hasSourceContext: Bool {return _storage._sourceContext != nil} + /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. + public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} + + /// The source syntax. + public var syntax: Google_Protobuf_Syntax { + get {return _storage._syntax} + set {_uniqueStorage()._syntax = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +/// A single field of a message type. +public struct Google_Protobuf_Field { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The field type. + public var kind: Google_Protobuf_Field.Kind = .typeUnknown + + /// The field cardinality. + public var cardinality: Google_Protobuf_Field.Cardinality = .unknown + + /// The field number. + public var number: Int32 = 0 + + /// The field name. + public var name: String = String() + + /// The field type URL, without the scheme, for message or enumeration + /// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + public var typeURL: String = String() + + /// The index of the field type in `Type.oneofs`, for message or enumeration + /// types. The first type has index 1; zero means the type is not in the list. + public var oneofIndex: Int32 = 0 + + /// Whether to use alternative packed wire representation. + public var packed: Bool = false + + /// The protocol buffer options. + public var options: [Google_Protobuf_Option] = [] + + /// The field JSON name. + public var jsonName: String = String() + + /// The string value of the default value of this field. Proto2 syntax only. + public var defaultValue: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// Basic field types. + public enum Kind: SwiftProtobuf.Enum { + public typealias RawValue = Int + + /// Field type unknown. + case typeUnknown // = 0 + + /// Field type double. + case typeDouble // = 1 + + /// Field type float. + case typeFloat // = 2 + + /// Field type int64. + case typeInt64 // = 3 + + /// Field type uint64. + case typeUint64 // = 4 + + /// Field type int32. + case typeInt32 // = 5 + + /// Field type fixed64. + case typeFixed64 // = 6 + + /// Field type fixed32. + case typeFixed32 // = 7 + + /// Field type bool. + case typeBool // = 8 + + /// Field type string. + case typeString // = 9 + + /// Field type group. Proto2 syntax only, and deprecated. + case typeGroup // = 10 + + /// Field type message. + case typeMessage // = 11 + + /// Field type bytes. + case typeBytes // = 12 + + /// Field type uint32. + case typeUint32 // = 13 + + /// Field type enum. + case typeEnum // = 14 + + /// Field type sfixed32. + case typeSfixed32 // = 15 + + /// Field type sfixed64. + case typeSfixed64 // = 16 + + /// Field type sint32. + case typeSint32 // = 17 + + /// Field type sint64. + case typeSint64 // = 18 + case UNRECOGNIZED(Int) + + public init() { + self = .typeUnknown + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .typeUnknown + case 1: self = .typeDouble + case 2: self = .typeFloat + case 3: self = .typeInt64 + case 4: self = .typeUint64 + case 5: self = .typeInt32 + case 6: self = .typeFixed64 + case 7: self = .typeFixed32 + case 8: self = .typeBool + case 9: self = .typeString + case 10: self = .typeGroup + case 11: self = .typeMessage + case 12: self = .typeBytes + case 13: self = .typeUint32 + case 14: self = .typeEnum + case 15: self = .typeSfixed32 + case 16: self = .typeSfixed64 + case 17: self = .typeSint32 + case 18: self = .typeSint64 + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .typeUnknown: return 0 + case .typeDouble: return 1 + case .typeFloat: return 2 + case .typeInt64: return 3 + case .typeUint64: return 4 + case .typeInt32: return 5 + case .typeFixed64: return 6 + case .typeFixed32: return 7 + case .typeBool: return 8 + case .typeString: return 9 + case .typeGroup: return 10 + case .typeMessage: return 11 + case .typeBytes: return 12 + case .typeUint32: return 13 + case .typeEnum: return 14 + case .typeSfixed32: return 15 + case .typeSfixed64: return 16 + case .typeSint32: return 17 + case .typeSint64: return 18 + case .UNRECOGNIZED(let i): return i + } + } + + } + + /// Whether a field is optional, required, or repeated. + public enum Cardinality: SwiftProtobuf.Enum { + public typealias RawValue = Int + + /// For fields with unknown cardinality. + case unknown // = 0 + + /// For optional fields. + case `optional` // = 1 + + /// For required fields. Proto2 syntax only. + case `required` // = 2 + + /// For repeated fields. + case repeated // = 3 + case UNRECOGNIZED(Int) + + public init() { + self = .unknown + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .unknown + case 1: self = .optional + case 2: self = .required + case 3: self = .repeated + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .unknown: return 0 + case .optional: return 1 + case .required: return 2 + case .repeated: return 3 + case .UNRECOGNIZED(let i): return i + } + } + + } + + public init() {} +} + +#if swift(>=4.2) + +extension Google_Protobuf_Field.Kind: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Google_Protobuf_Field.Kind] = [ + .typeUnknown, + .typeDouble, + .typeFloat, + .typeInt64, + .typeUint64, + .typeInt32, + .typeFixed64, + .typeFixed32, + .typeBool, + .typeString, + .typeGroup, + .typeMessage, + .typeBytes, + .typeUint32, + .typeEnum, + .typeSfixed32, + .typeSfixed64, + .typeSint32, + .typeSint64, + ] +} + +extension Google_Protobuf_Field.Cardinality: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Google_Protobuf_Field.Cardinality] = [ + .unknown, + .optional, + .required, + .repeated, + ] +} + +#endif // swift(>=4.2) + +/// Enum type definition. +public struct Google_Protobuf_Enum { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Enum type name. + public var name: String { + get {return _storage._name} + set {_uniqueStorage()._name = newValue} + } + + /// Enum value definitions. + public var enumvalue: [Google_Protobuf_EnumValue] { + get {return _storage._enumvalue} + set {_uniqueStorage()._enumvalue = newValue} + } + + /// Protocol buffer options. + public var options: [Google_Protobuf_Option] { + get {return _storage._options} + set {_uniqueStorage()._options = newValue} + } + + /// The source context. + public var sourceContext: Google_Protobuf_SourceContext { + get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} + set {_uniqueStorage()._sourceContext = newValue} + } + /// Returns true if `sourceContext` has been explicitly set. + public var hasSourceContext: Bool {return _storage._sourceContext != nil} + /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. + public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} + + /// The source syntax. + public var syntax: Google_Protobuf_Syntax { + get {return _storage._syntax} + set {_uniqueStorage()._syntax = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +/// Enum value definition. +public struct Google_Protobuf_EnumValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Enum value name. + public var name: String = String() + + /// Enum value number. + public var number: Int32 = 0 + + /// Protocol buffer options. + public var options: [Google_Protobuf_Option] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// A protocol buffer option, which can be attached to a message, field, +/// enumeration, etc. +public struct Google_Protobuf_Option { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The option's name. For protobuf built-in options (options defined in + /// descriptor.proto), this is the short name. For example, `"map_entry"`. + /// For custom options, it should be the fully-qualified name. For example, + /// `"google.api.http"`. + public var name: String { + get {return _storage._name} + set {_uniqueStorage()._name = newValue} + } + + /// The option's value packed in an Any message. If the value is a primitive, + /// the corresponding wrapper type defined in google/protobuf/wrappers.proto + /// should be used. If the value is an enum, it should be stored as an int32 + /// value using the google.protobuf.Int32Value type. + public var value: Google_Protobuf_Any { + get {return _storage._value ?? Google_Protobuf_Any()} + set {_uniqueStorage()._value = newValue} + } + /// Returns true if `value` has been explicitly set. + public var hasValue: Bool {return _storage._value != nil} + /// Clears the value of `value`. Subsequent reads from it will return its default value. + public mutating func clearValue() {_uniqueStorage()._value = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_Syntax: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "SYNTAX_PROTO2"), + 1: .same(proto: "SYNTAX_PROTO3"), + ] +} + +extension Google_Protobuf_Type: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Type" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "fields"), + 3: .same(proto: "oneofs"), + 4: .same(proto: "options"), + 5: .standard(proto: "source_context"), + 6: .same(proto: "syntax"), + ] + + fileprivate class _StorageClass { + var _name: String = String() + var _fields: [Google_Protobuf_Field] = [] + var _oneofs: [String] = [] + var _options: [Google_Protobuf_Option] = [] + var _sourceContext: Google_Protobuf_SourceContext? = nil + var _syntax: Google_Protobuf_Syntax = .proto2 + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _name = source._name + _fields = source._fields + _oneofs = source._oneofs + _options = source._options + _sourceContext = source._sourceContext + _syntax = source._syntax + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._name) + case 2: try decoder.decodeRepeatedMessageField(value: &_storage._fields) + case 3: try decoder.decodeRepeatedStringField(value: &_storage._oneofs) + case 4: try decoder.decodeRepeatedMessageField(value: &_storage._options) + case 5: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) + case 6: try decoder.decodeSingularEnumField(value: &_storage._syntax) + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if !_storage._name.isEmpty { + try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) + } + if !_storage._fields.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._fields, fieldNumber: 2) + } + if !_storage._oneofs.isEmpty { + try visitor.visitRepeatedStringField(value: _storage._oneofs, fieldNumber: 3) + } + if !_storage._options.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 4) + } + if let v = _storage._sourceContext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 5) + } + if _storage._syntax != .proto2 { + try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 6) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Type, rhs: Google_Protobuf_Type) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._name != rhs_storage._name {return false} + if _storage._fields != rhs_storage._fields {return false} + if _storage._oneofs != rhs_storage._oneofs {return false} + if _storage._options != rhs_storage._options {return false} + if _storage._sourceContext != rhs_storage._sourceContext {return false} + if _storage._syntax != rhs_storage._syntax {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Field: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Field" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "kind"), + 2: .same(proto: "cardinality"), + 3: .same(proto: "number"), + 4: .same(proto: "name"), + 6: .standard(proto: "type_url"), + 7: .standard(proto: "oneof_index"), + 8: .same(proto: "packed"), + 9: .same(proto: "options"), + 10: .standard(proto: "json_name"), + 11: .standard(proto: "default_value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularEnumField(value: &self.kind) + case 2: try decoder.decodeSingularEnumField(value: &self.cardinality) + case 3: try decoder.decodeSingularInt32Field(value: &self.number) + case 4: try decoder.decodeSingularStringField(value: &self.name) + case 6: try decoder.decodeSingularStringField(value: &self.typeURL) + case 7: try decoder.decodeSingularInt32Field(value: &self.oneofIndex) + case 8: try decoder.decodeSingularBoolField(value: &self.packed) + case 9: try decoder.decodeRepeatedMessageField(value: &self.options) + case 10: try decoder.decodeSingularStringField(value: &self.jsonName) + case 11: try decoder.decodeSingularStringField(value: &self.defaultValue) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.kind != .typeUnknown { + try visitor.visitSingularEnumField(value: self.kind, fieldNumber: 1) + } + if self.cardinality != .unknown { + try visitor.visitSingularEnumField(value: self.cardinality, fieldNumber: 2) + } + if self.number != 0 { + try visitor.visitSingularInt32Field(value: self.number, fieldNumber: 3) + } + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 4) + } + if !self.typeURL.isEmpty { + try visitor.visitSingularStringField(value: self.typeURL, fieldNumber: 6) + } + if self.oneofIndex != 0 { + try visitor.visitSingularInt32Field(value: self.oneofIndex, fieldNumber: 7) + } + if self.packed != false { + try visitor.visitSingularBoolField(value: self.packed, fieldNumber: 8) + } + if !self.options.isEmpty { + try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 9) + } + if !self.jsonName.isEmpty { + try visitor.visitSingularStringField(value: self.jsonName, fieldNumber: 10) + } + if !self.defaultValue.isEmpty { + try visitor.visitSingularStringField(value: self.defaultValue, fieldNumber: 11) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Field, rhs: Google_Protobuf_Field) -> Bool { + if lhs.kind != rhs.kind {return false} + if lhs.cardinality != rhs.cardinality {return false} + if lhs.number != rhs.number {return false} + if lhs.name != rhs.name {return false} + if lhs.typeURL != rhs.typeURL {return false} + if lhs.oneofIndex != rhs.oneofIndex {return false} + if lhs.packed != rhs.packed {return false} + if lhs.options != rhs.options {return false} + if lhs.jsonName != rhs.jsonName {return false} + if lhs.defaultValue != rhs.defaultValue {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Field.Kind: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "TYPE_UNKNOWN"), + 1: .same(proto: "TYPE_DOUBLE"), + 2: .same(proto: "TYPE_FLOAT"), + 3: .same(proto: "TYPE_INT64"), + 4: .same(proto: "TYPE_UINT64"), + 5: .same(proto: "TYPE_INT32"), + 6: .same(proto: "TYPE_FIXED64"), + 7: .same(proto: "TYPE_FIXED32"), + 8: .same(proto: "TYPE_BOOL"), + 9: .same(proto: "TYPE_STRING"), + 10: .same(proto: "TYPE_GROUP"), + 11: .same(proto: "TYPE_MESSAGE"), + 12: .same(proto: "TYPE_BYTES"), + 13: .same(proto: "TYPE_UINT32"), + 14: .same(proto: "TYPE_ENUM"), + 15: .same(proto: "TYPE_SFIXED32"), + 16: .same(proto: "TYPE_SFIXED64"), + 17: .same(proto: "TYPE_SINT32"), + 18: .same(proto: "TYPE_SINT64"), + ] +} + +extension Google_Protobuf_Field.Cardinality: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "CARDINALITY_UNKNOWN"), + 1: .same(proto: "CARDINALITY_OPTIONAL"), + 2: .same(proto: "CARDINALITY_REQUIRED"), + 3: .same(proto: "CARDINALITY_REPEATED"), + ] +} + +extension Google_Protobuf_Enum: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Enum" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "enumvalue"), + 3: .same(proto: "options"), + 4: .standard(proto: "source_context"), + 5: .same(proto: "syntax"), + ] + + fileprivate class _StorageClass { + var _name: String = String() + var _enumvalue: [Google_Protobuf_EnumValue] = [] + var _options: [Google_Protobuf_Option] = [] + var _sourceContext: Google_Protobuf_SourceContext? = nil + var _syntax: Google_Protobuf_Syntax = .proto2 + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _name = source._name + _enumvalue = source._enumvalue + _options = source._options + _sourceContext = source._sourceContext + _syntax = source._syntax + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._name) + case 2: try decoder.decodeRepeatedMessageField(value: &_storage._enumvalue) + case 3: try decoder.decodeRepeatedMessageField(value: &_storage._options) + case 4: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) + case 5: try decoder.decodeSingularEnumField(value: &_storage._syntax) + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if !_storage._name.isEmpty { + try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) + } + if !_storage._enumvalue.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._enumvalue, fieldNumber: 2) + } + if !_storage._options.isEmpty { + try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 3) + } + if let v = _storage._sourceContext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + } + if _storage._syntax != .proto2 { + try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 5) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Enum, rhs: Google_Protobuf_Enum) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._name != rhs_storage._name {return false} + if _storage._enumvalue != rhs_storage._enumvalue {return false} + if _storage._options != rhs_storage._options {return false} + if _storage._sourceContext != rhs_storage._sourceContext {return false} + if _storage._syntax != rhs_storage._syntax {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_EnumValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EnumValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "number"), + 3: .same(proto: "options"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &self.name) + case 2: try decoder.decodeSingularInt32Field(value: &self.number) + case 3: try decoder.decodeRepeatedMessageField(value: &self.options) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.name.isEmpty { + try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) + } + if self.number != 0 { + try visitor.visitSingularInt32Field(value: self.number, fieldNumber: 2) + } + if !self.options.isEmpty { + try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_EnumValue, rhs: Google_Protobuf_EnumValue) -> Bool { + if lhs.name != rhs.name {return false} + if lhs.number != rhs.number {return false} + if lhs.options != rhs.options {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Option: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Option" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "name"), + 2: .same(proto: "value"), + ] + + fileprivate class _StorageClass { + var _name: String = String() + var _value: Google_Protobuf_Any? = nil + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _name = source._name + _value = source._value + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &_storage._name) + case 2: try decoder.decodeSingularMessageField(value: &_storage._value) + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + if !_storage._name.isEmpty { + try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) + } + if let v = _storage._value { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Option, rhs: Google_Protobuf_Option) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._name != rhs_storage._name {return false} + if _storage._value != rhs_storage._value {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift new file mode 100644 index 0000000..58f4bf9 --- /dev/null +++ b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift @@ -0,0 +1,468 @@ +// DO NOT EDIT. +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: google/protobuf/wrappers.proto +// +// For information on using the generated types, please see the documenation: +// https://github.com/apple/swift-protobuf/ + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. +// +// These wrappers have no meaningful use within repeated fields as they lack +// the ability to detect presence on individual elements. +// These wrappers have no meaningful use within a map or a oneof since +// individual entries of a map or fields of a oneof can already detect presence. + +import Foundation + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that your are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Wrapper message for `double`. +/// +/// The JSON representation for `DoubleValue` is JSON number. +public struct Google_Protobuf_DoubleValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The double value. + public var value: Double = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `float`. +/// +/// The JSON representation for `FloatValue` is JSON number. +public struct Google_Protobuf_FloatValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The float value. + public var value: Float = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `int64`. +/// +/// The JSON representation for `Int64Value` is JSON string. +public struct Google_Protobuf_Int64Value { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The int64 value. + public var value: Int64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `uint64`. +/// +/// The JSON representation for `UInt64Value` is JSON string. +public struct Google_Protobuf_UInt64Value { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The uint64 value. + public var value: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `int32`. +/// +/// The JSON representation for `Int32Value` is JSON number. +public struct Google_Protobuf_Int32Value { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The int32 value. + public var value: Int32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `uint32`. +/// +/// The JSON representation for `UInt32Value` is JSON number. +public struct Google_Protobuf_UInt32Value { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The uint32 value. + public var value: UInt32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `bool`. +/// +/// The JSON representation for `BoolValue` is JSON `true` and `false`. +public struct Google_Protobuf_BoolValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The bool value. + public var value: Bool = false + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `string`. +/// +/// The JSON representation for `StringValue` is JSON string. +public struct Google_Protobuf_StringValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The string value. + public var value: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper message for `bytes`. +/// +/// The JSON representation for `BytesValue` is JSON string. +public struct Google_Protobuf_BytesValue { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The bytes value. + public var value: Data = SwiftProtobuf.Internal.emptyData + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "google.protobuf" + +extension Google_Protobuf_DoubleValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DoubleValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularDoubleField(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularDoubleField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_DoubleValue, rhs: Google_Protobuf_DoubleValue) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_FloatValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".FloatValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularFloatField(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularFloatField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_FloatValue, rhs: Google_Protobuf_FloatValue) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Int64Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Int64Value" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularInt64Field(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularInt64Field(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Int64Value, rhs: Google_Protobuf_Int64Value) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_UInt64Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UInt64Value" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularUInt64Field(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularUInt64Field(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_UInt64Value, rhs: Google_Protobuf_UInt64Value) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_Int32Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Int32Value" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularInt32Field(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularInt32Field(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_Int32Value, rhs: Google_Protobuf_Int32Value) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_UInt32Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UInt32Value" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularUInt32Field(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != 0 { + try visitor.visitSingularUInt32Field(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_UInt32Value, rhs: Google_Protobuf_UInt32Value) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_BoolValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BoolValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularBoolField(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.value != false { + try visitor.visitSingularBoolField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_BoolValue, rhs: Google_Protobuf_BoolValue) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_StringValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".StringValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularStringField(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.value.isEmpty { + try visitor.visitSingularStringField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_StringValue, rhs: Google_Protobuf_StringValue) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Google_Protobuf_BytesValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BytesValue" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "value"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + switch fieldNumber { + case 1: try decoder.decodeSingularBytesField(value: &self.value) + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.value.isEmpty { + try visitor.visitSingularBytesField(value: self.value, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Google_Protobuf_BytesValue, rhs: Google_Protobuf_BytesValue) -> Bool { + if lhs.value != rhs.value {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist b/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist new file mode 100644 index 0000000..2243fe6 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + ${PRODUCT_BUNDLE_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown new file mode 100644 index 0000000..c14e6c3 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown @@ -0,0 +1,218 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## SwiftProtobuf + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +## Runtime Library Exception to the Apache 2.0 License: ## + + + As an exception, if you use this Software to compile your source code and + portions of this Software are embedded into the binary product as a result, + you may redistribute such product without providing attribution as would + otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. + +Generated by CocoaPods - https://cocoapods.org diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist new file mode 100644 index 0000000..7b9559f --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist @@ -0,0 +1,250 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +## Runtime Library Exception to the Apache 2.0 License: ## + + + As an exception, if you use this Software to compile your source code and + portions of this Software are embedded into the binary product as a result, + you may redistribute such product without providing attribution as would + otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. + + License + Apache 2.0 + Title + SwiftProtobuf + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - https://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m b/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m new file mode 100644 index 0000000..9775501 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods_UB : NSObject +@end +@implementation PodsDummy_Pods_UB +@end diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h b/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h new file mode 100644 index 0000000..5672be2 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h @@ -0,0 +1,16 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + + +FOUNDATION_EXPORT double Pods_UBVersionNumber; +FOUNDATION_EXPORT const unsigned char Pods_UBVersionString[]; + diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig b/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig new file mode 100644 index 0000000..cafce36 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig @@ -0,0 +1,10 @@ +FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' +OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" +OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS +PODS_BUILD_DIR = ${BUILD_DIR} +PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_PODFILE_DIR_PATH = ${SRCROOT}/. +PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap b/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap new file mode 100644 index 0000000..9447309 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap @@ -0,0 +1,6 @@ +framework module Pods_UB { + umbrella header "Pods-UB-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig b/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig new file mode 100644 index 0000000..cafce36 --- /dev/null +++ b/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig @@ -0,0 +1,10 @@ +FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' +OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" +OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS +PODS_BUILD_DIR = ${BUILD_DIR} +PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_PODFILE_DIR_PATH = ${SRCROOT}/. +PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist new file mode 100644 index 0000000..2243fe6 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + ${PRODUCT_BUNDLE_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown new file mode 100644 index 0000000..c14e6c3 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown @@ -0,0 +1,218 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## SwiftProtobuf + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +## Runtime Library Exception to the Apache 2.0 License: ## + + + As an exception, if you use this Software to compile your source code and + portions of this Software are embedded into the binary product as a result, + you may redistribute such product without providing attribution as would + otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. + +Generated by CocoaPods - https://cocoapods.org diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist new file mode 100644 index 0000000..7b9559f --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist @@ -0,0 +1,250 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + +## Runtime Library Exception to the Apache 2.0 License: ## + + + As an exception, if you use this Software to compile your source code and + portions of this Software are embedded into the binary product as a result, + you may redistribute such product without providing attribution as would + otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. + + License + Apache 2.0 + Title + SwiftProtobuf + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - https://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m new file mode 100644 index 0000000..f7d2f4a --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods_UBTests : NSObject +@end +@implementation PodsDummy_Pods_UBTests +@end diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh new file mode 100755 index 0000000..b035e1c --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh @@ -0,0 +1,171 @@ +#!/bin/sh +set -e +set -u +set -o pipefail + +function on_error { + echo "$(realpath -mq "${0}"):$1: error: Unexpected failure" +} +trap 'on_error $LINENO' ERR + +if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then + # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy + # frameworks to, so exit 0 (signalling the script phase was successful). + exit 0 +fi + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}" +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +# Used as a return value for each invocation of `strip_invalid_archs` function. +STRIP_BINARY_RETVAL=0 + +# This protects against multiple targets copying the same framework dependency at the same time. The solution +# was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html +RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") + +# Copies and strips a vendored framework +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + elif [ -r "$1" ]; then + local source="$1" + fi + + local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # Use filter instead of exclude so missing patterns don't throw errors. + echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + local basename + basename="$(basename -s .framework "$1")" + binary="${destination}/${basename}.framework/${basename}" + + if ! [ -r "$binary" ]; then + binary="${destination}/${basename}" + elif [ -L "${binary}" ]; then + echo "Destination binary is symlinked..." + dirname="$(dirname "${binary}")" + binary="${dirname}/$(readlink "${binary}")" + fi + + # Strip invalid architectures so "fat" simulator / device frameworks work on device + if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then + strip_invalid_archs "$binary" + fi + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. + if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done + fi +} + +# Copies and strips a vendored dSYM +install_dsym() { + local source="$1" + if [ -r "$source" ]; then + # Copy the dSYM into a the targets temp dir. + echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" + rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" + + local basename + basename="$(basename -s .framework.dSYM "$source")" + binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}" + + # Strip invalid architectures so "fat" simulator / device frameworks work on device + if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then + strip_invalid_archs "$binary" + fi + + if [[ $STRIP_BINARY_RETVAL == 1 ]]; then + # Move the stripped file into its final destination. + echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" + rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}" + else + # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. + touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM" + fi + fi +} + +# Copies the bcsymbolmap files of a vendored framework +install_bcsymbolmap() { + local bcsymbolmap_path="$1" + local destination="${BUILT_PRODUCTS_DIR}" + echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"" + rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}" +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identity + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'" + + if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then + code_sign_cmd="$code_sign_cmd &" + fi + echo "$code_sign_cmd" + eval "$code_sign_cmd" + fi +} + +# Strip invalid architectures +strip_invalid_archs() { + binary="$1" + # Get architectures for current target binary + binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" + # Intersect them with the architectures we are building for + intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" + # If there are no archs supported by this binary then warn the user + if [[ -z "$intersected_archs" ]]; then + echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." + STRIP_BINARY_RETVAL=0 + return + fi + stripped="" + for arch in $binary_archs; do + if ! [[ "${ARCHS}" == *"$arch"* ]]; then + # Strip non-valid architectures in-place + lipo -remove "$arch" -output "$binary" "$binary" + stripped="$stripped $arch" + fi + done + if [[ "$stripped" ]]; then + echo "Stripped $binary of architectures:$stripped" + fi + STRIP_BINARY_RETVAL=1 +} + + +if [[ "$CONFIGURATION" == "Debug" ]]; then + install_framework "${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework" +fi +if [[ "$CONFIGURATION" == "Release" ]]; then + install_framework "${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework" +fi +if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then + wait +fi diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h new file mode 100644 index 0000000..99ffa46 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h @@ -0,0 +1,16 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + + +FOUNDATION_EXPORT double Pods_UBTestsVersionNumber; +FOUNDATION_EXPORT const unsigned char Pods_UBTestsVersionString[]; + diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig new file mode 100644 index 0000000..e945731 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig @@ -0,0 +1,11 @@ +ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES +FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks' +OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" +OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS +PODS_BUILD_DIR = ${BUILD_DIR} +PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_PODFILE_DIR_PATH = ${SRCROOT}/. +PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap new file mode 100644 index 0000000..bcd72b7 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap @@ -0,0 +1,6 @@ +framework module Pods_UBTests { + umbrella header "Pods-UBTests-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig new file mode 100644 index 0000000..e945731 --- /dev/null +++ b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig @@ -0,0 +1,11 @@ +ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES +FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks' +OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" +OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS +PODS_BUILD_DIR = ${BUILD_DIR} +PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_PODFILE_DIR_PATH = ${SRCROOT}/. +PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist new file mode 100644 index 0000000..2f66809 --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + ${PRODUCT_BUNDLE_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.6.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m new file mode 100644 index 0000000..95f025a --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_SwiftProtobuf : NSObject +@end +@implementation PodsDummy_SwiftProtobuf +@end diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch new file mode 100644 index 0000000..082f8af --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch @@ -0,0 +1,12 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h new file mode 100644 index 0000000..d03d03b --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h @@ -0,0 +1,16 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + + +FOUNDATION_EXPORT double SwiftProtobufVersionNumber; +FOUNDATION_EXPORT const unsigned char SwiftProtobufVersionString[]; + diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap new file mode 100644 index 0000000..a88eceb --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap @@ -0,0 +1,6 @@ +framework module SwiftProtobuf { + umbrella header "SwiftProtobuf-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig new file mode 100644 index 0000000..271c7f5 --- /dev/null +++ b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig @@ -0,0 +1,10 @@ +CODE_SIGN_IDENTITY = +CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS +PODS_BUILD_DIR = ${BUILD_DIR} +PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) +PODS_ROOT = ${SRCROOT} +PODS_TARGET_SRCROOT = ${PODS_ROOT}/SwiftProtobuf +PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} +SKIP_INSTALL = YES diff --git a/Sources/UB/Extensions/UUID+Bytes.swift b/Sources/UB/Extensions/UUID+Bytes.swift new file mode 100644 index 0000000..3347478 --- /dev/null +++ b/Sources/UB/Extensions/UUID+Bytes.swift @@ -0,0 +1,13 @@ +import Foundation + +extension UUID { + + public var bytes: Data { + get { + return withUnsafePointer(to: self) { + Data(bytes: $0, count: MemoryLayout.size(ofValue: self)) + } + } + } + +} \ No newline at end of file diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index d202f0b..fc317e7 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -3,28 +3,21 @@ import Foundation /// CoreBluetoothTransport is used to send and receieve message over Bluetooth public class CoreBluetoothTransport: NSObject { + private let centralManager: CBCentralManager private let peripheralManager: CBPeripheralManager - private var testServiceID = CBUUID(string: "0xAAAA") - private var testServiceID2 = CBUUID(string: "0xBBBB") - + static let ubServiceUUID = CBUUID(string: "0xAAAA") + static let receiveCharacteristicUUID = CBUUID(string: "0002") + let receiveCharacteristic = CBMutableCharacteristic( - type: CBUUID(string: "0002"), + type: receiveCharacteristicUUID, properties: CBCharacteristicProperties.writeWithoutResponse, value: nil, permissions: CBAttributePermissions.writeable ) - var test: CBCharacteristic? - - private var perp: CBPeripheral? // make this an array for multiple devices - // private var peripherals = [Addr:CBPeripheral?]() // make this an array for multiple devices - - - - private var outQueue = [(Message,Addr)]() - + private var peripherals = [Addr: CBPeripheral]() public convenience override init() { self.init( @@ -54,24 +47,32 @@ extension CoreBluetoothTransport: Transport { public func send(message: Message, to: Addr) { // check bluetooth is running - guard let uuid = String(bytes: to, encoding: .utf8) else { - print("Error: not a valid Byte sequence") - return - } - guard let toUUID = UUID(uuidString: uuid) else { - print("Error: not a valid UUID sequence") - return - } - let peripherals = centralManager.retrievePeripherals(withIdentifiers: [toUUID]) - if peripherals.count == 0 { +// guard let uuid = String(bytes: to, encoding: .utf8) else { +// print("Error: not a valid Byte sequence") +// return +// } +// guard let toUUID = UUID(uuidString: uuid) else { +// print("Error: not a valid UUID sequence") +// return +// } +// +// +// let peripherals = centralManager.retrievePeripherals(withIdentifiers: [toUUID]) +// if peripherals.count == 0 { +// print("Error: peripheral with uuid \(to) not found") +// return +// } +// +// let peripheral = peripherals[0] +// print("NAME : \(peripheral)") + + if let peripheral = peripherals[to] { + peripheral.writeValue(message.message, for: receiveCharacteristic, type: CBCharacteristicWriteType.withoutResponse) + } else { print("Error: peripheral with uuid \(to) not found") - return + // @todo error } - let peripheral = peripherals[0] - print("NAME : \(peripheral)") - - peripheral.writeValue(message.message, for: test!, type: CBCharacteristicWriteType.withoutResponse) } /// Listen implements a function to receive messages being sent to a node. @@ -91,7 +92,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { let WR_PROPERTIES: CBCharacteristicProperties = .write let WR_PERMISSIONS: CBAttributePermissions = .writeable - let serialService = CBMutableService(type: testServiceID, primary: true) + let serialService = CBMutableService(type: CoreBluetoothTransport.ubServiceUUID, primary: true) let writeCharacteristics = CBMutableCharacteristic(type: WR_UUID, properties: WR_PROPERTIES, value: nil, @@ -99,7 +100,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { serialService.characteristics = [writeCharacteristics] peripheral.add(serialService) - peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [testServiceID, testServiceID2], + peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], CBAdvertisementDataLocalNameKey: nil]) } } @@ -137,29 +138,30 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { print("Bluetooth status is POWERED OFF") case .poweredOn: print("Bluetooth status is POWERED ON") - centralManager.scanForPeripherals(withServices: [testServiceID, testServiceID2]) + centralManager.scanForPeripherals(withServices: [CoreBluetoothTransport.ubServiceUUID]) } } // Try to connect to discovered devices - public func centralManager(_: CBCentralManager, - didDiscover peripheral: CBPeripheral, - advertisementData _: [String: Any], - rssi _: NSNumber) { - perp = peripheral - perp?.delegate = self + public func centralManager( + _ central: CBCentralManager, + didDiscover peripheral: CBPeripheral, + advertisementData _: [String: Any], + rssi _: NSNumber + ) { + peripheral.delegate = self decodePeripheralState(peripheralState: peripheral.state, peripheral: peripheral) - centralManager.connect(perp!) + centralManager.connect(peripheral) } // When connected to a devices, ask for the Services - public func centralManager(_: CBCentralManager, didConnect _: CBPeripheral) { - // look for services of interest on peripheral - perp?.discoverServices([testServiceID, testServiceID2]) + public func centralManager(_: CBCentralManager, didConnect peripheral: CBPeripheral) { + peripheral.discoverServices([CoreBluetoothTransport.receiveCharacteristicUUID]) } - // Handle Disconnections - public func centralManager(_: CBCentralManager, didDisconnectPeripheral _: CBPeripheral, error _: Error?) {} + public func centralManager(_: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error _: Error?) { + peripherals.removeValue(forKey: Addr(peripheral.identifier.bytes)) + } func decodePeripheralState(peripheralState: CBPeripheralState, peripheral: CBPeripheral) { switch peripheralState { @@ -181,49 +183,21 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { } extension CoreBluetoothTransport: CBPeripheralDelegate { - // ask for Characteristics for each Service of interest public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices _: Error?) { - print("servicessssss ") - for service in peripheral.services! { - print("Service: \(service)") - peripheral.discoverCharacteristics(nil, for: service) + guard let service = peripheral.services?.first(where: { $0.uuid == CoreBluetoothTransport.ubServiceUUID }) else { + return } + + peripheral.discoverCharacteristics([CoreBluetoothTransport.receiveCharacteristicUUID], for: service) } - // called with characteristics public func peripheral( _ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error _: Error? ) { - - for characteristic in service.characteristics! { - if characteristic.uuid == CBUUID(string: "0002"){ - print("WE GOT THE RIGHT CHARACTERISTIC") - test = characteristic - } - - // peripheral.readValue(for: characteristic) -// if characteristic.uuid == testServiceID { - //let data = Data(bytes: [97, 98, 99, 100]) - print("Characteristic: \(characteristic)") - -// print("Sending some good shit") -// let data = outQueue[0].0.message; -// peripheral.writeValue(data, for: characteristic, type: CBCharacteristicWriteType.withoutResponse) -// outQueue.remove(at:0) - -// } + if service.characteristics?.contains(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) ?? false { + peripherals[Addr(peripheral.identifier.bytes)] = peripheral } } - -// // called when reading a value from peripheral characteristic data field. -// public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { -// let data = Data(bytes: characteristic.value!) -// print("Characteristic Value: \(data.hexEncodedString())") -// } -} - -extension CoreBluetoothTransport { - public func startScanning() {} } diff --git a/UB.xcworkspace/contents.xcworkspacedata b/UB.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..70e8acb --- /dev/null +++ b/UB.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + From 0006cb1d8c2bbabf9cbf1b2b6769c31b4df482ac Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 21:54:24 -0400 Subject: [PATCH 16/54] oops --- Pods/Manifest.lock | 17 - Pods/SwiftProtobuf/LICENSE.txt | 211 --- Pods/SwiftProtobuf/README.md | 300 ---- .../SwiftProtobuf/AnyMessageStorage.swift | 467 ----- .../SwiftProtobuf/AnyUnpackError.swift | 37 - .../Sources/SwiftProtobuf/BinaryDecoder.swift | 1503 ---------------- .../SwiftProtobuf/BinaryDecodingError.swift | 44 - .../SwiftProtobuf/BinaryDecodingOptions.swift | 39 - .../SwiftProtobuf/BinaryDelimited.swift | 227 --- .../Sources/SwiftProtobuf/BinaryEncoder.swift | 135 -- .../SwiftProtobuf/BinaryEncodingError.swift | 27 - .../BinaryEncodingSizeVisitor.swift | 369 ---- .../SwiftProtobuf/BinaryEncodingVisitor.swift | 360 ---- .../SwiftProtobuf/CustomJSONCodable.swift | 36 - .../SwiftProtobuf/Data+Extensions.swift | 33 - .../Sources/SwiftProtobuf/Decoder.swift | 150 -- .../Sources/SwiftProtobuf/DoubleParser.swift | 68 - .../Sources/SwiftProtobuf/Enum.swift | 93 - .../SwiftProtobuf/ExtensibleMessage.swift | 39 - .../ExtensionFieldValueSet.swift | 89 - .../SwiftProtobuf/ExtensionFields.swift | 708 -------- .../Sources/SwiftProtobuf/ExtensionMap.swift | 38 - .../Sources/SwiftProtobuf/FieldTag.swift | 69 - .../Sources/SwiftProtobuf/FieldTypes.swift | 412 ----- .../Google_Protobuf_Any+Extensions.swift | 145 -- .../Google_Protobuf_Any+Registry.swift | 135 -- .../Google_Protobuf_Duration+Extensions.swift | 234 --- ...Google_Protobuf_FieldMask+Extensions.swift | 163 -- ...Google_Protobuf_ListValue+Extensions.swift | 80 - .../Google_Protobuf_Struct+Extensions.swift | 85 - ...Google_Protobuf_Timestamp+Extensions.swift | 337 ---- .../Google_Protobuf_Value+Extensions.swift | 163 -- .../Google_Protobuf_Wrappers+Extensions.swift | 283 --- .../Sources/SwiftProtobuf/HashVisitor.swift | 408 ----- .../Sources/SwiftProtobuf/Internal.swift | 51 - .../Sources/SwiftProtobuf/JSONDecoder.swift | 702 -------- .../SwiftProtobuf/JSONDecodingError.swift | 62 - .../SwiftProtobuf/JSONDecodingOptions.swift | 29 - .../Sources/SwiftProtobuf/JSONEncoder.swift | 370 ---- .../SwiftProtobuf/JSONEncodingError.swift | 35 - .../SwiftProtobuf/JSONEncodingOptions.swift | 26 - .../SwiftProtobuf/JSONEncodingVisitor.swift | 352 ---- .../JSONMapEncodingVisitor.swift | 174 -- .../Sources/SwiftProtobuf/JSONScanner.swift | 1512 ----------------- .../Sources/SwiftProtobuf/MathUtils.swift | 40 - .../SwiftProtobuf/Message+AnyAdditions.swift | 45 - .../Message+BinaryAdditions.swift | 126 -- .../SwiftProtobuf/Message+JSONAdditions.swift | 117 -- .../Message+JSONArrayAdditions.swift | 111 -- .../Message+TextFormatAdditions.swift | 89 - .../Sources/SwiftProtobuf/Message.swift | 216 --- .../SwiftProtobuf/MessageExtension.swift | 41 - .../Sources/SwiftProtobuf/NameMap.swift | 286 ---- .../SwiftProtobuf/ProtoNameProviding.swift | 23 - .../ProtobufAPIVersionCheck.swift | 43 - .../Sources/SwiftProtobuf/ProtobufMap.swift | 39 - .../SwiftProtobuf/SelectiveVisitor.swift | 268 --- .../SwiftProtobuf/SimpleExtensionMap.swift | 112 -- .../Sources/SwiftProtobuf/StringUtils.swift | 73 - .../SwiftProtobuf/TextFormatDecoder.swift | 713 -------- .../TextFormatDecodingError.swift | 40 - .../SwiftProtobuf/TextFormatEncoder.swift | 292 ---- .../TextFormatEncodingOptions.swift | 22 - .../TextFormatEncodingVisitor.swift | 553 ------ .../SwiftProtobuf/TextFormatScanner.swift | 1078 ------------ .../Sources/SwiftProtobuf/TimeUtils.swift | 53 - .../SwiftProtobuf/UnknownStorage.swift | 46 - .../Sources/SwiftProtobuf/Varint.swift | 108 -- .../Sources/SwiftProtobuf/Version.swift | 28 - .../Sources/SwiftProtobuf/Visitor.swift | 693 -------- .../Sources/SwiftProtobuf/WireFormat.swift | 70 - .../Sources/SwiftProtobuf/ZigZag.swift | 66 - .../Sources/SwiftProtobuf/any.pb.swift | 234 --- .../Sources/SwiftProtobuf/api.pb.swift | 476 ------ .../Sources/SwiftProtobuf/duration.pb.swift | 169 -- .../Sources/SwiftProtobuf/empty.pb.swift | 91 - .../Sources/SwiftProtobuf/field_mask.pb.swift | 294 ---- .../SwiftProtobuf/source_context.pb.swift | 98 -- .../Sources/SwiftProtobuf/struct.pb.swift | 417 ----- .../Sources/SwiftProtobuf/timestamp.pb.swift | 189 --- .../Sources/SwiftProtobuf/type.pb.swift | 924 ---------- .../Sources/SwiftProtobuf/wrappers.pb.swift | 468 ----- .../Pods-UB/Pods-UB-Info.plist | 26 - .../Pods-UB/Pods-UB-acknowledgements.markdown | 218 --- .../Pods-UB/Pods-UB-acknowledgements.plist | 250 --- .../Pods-UB/Pods-UB-dummy.m | 5 - .../Pods-UB/Pods-UB-umbrella.h | 16 - .../Pods-UB/Pods-UB.debug.xcconfig | 10 - .../Pods-UB/Pods-UB.modulemap | 6 - .../Pods-UB/Pods-UB.release.xcconfig | 10 - .../Pods-UBTests/Pods-UBTests-Info.plist | 26 - .../Pods-UBTests-acknowledgements.markdown | 218 --- .../Pods-UBTests-acknowledgements.plist | 250 --- .../Pods-UBTests/Pods-UBTests-dummy.m | 5 - .../Pods-UBTests/Pods-UBTests-frameworks.sh | 171 -- .../Pods-UBTests/Pods-UBTests-umbrella.h | 16 - .../Pods-UBTests/Pods-UBTests.debug.xcconfig | 11 - .../Pods-UBTests/Pods-UBTests.modulemap | 6 - .../Pods-UBTests.release.xcconfig | 11 - .../SwiftProtobuf/SwiftProtobuf-Info.plist | 26 - .../SwiftProtobuf/SwiftProtobuf-dummy.m | 5 - .../SwiftProtobuf/SwiftProtobuf-prefix.pch | 12 - .../SwiftProtobuf/SwiftProtobuf-umbrella.h | 16 - .../SwiftProtobuf/SwiftProtobuf.modulemap | 6 - .../SwiftProtobuf/SwiftProtobuf.xcconfig | 10 - UB.xcworkspace/contents.xcworkspacedata | 10 - 106 files changed, 20908 deletions(-) delete mode 100644 Pods/Manifest.lock delete mode 100644 Pods/SwiftProtobuf/LICENSE.txt delete mode 100644 Pods/SwiftProtobuf/README.md delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncodingOptions.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift delete mode 100644 Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.modulemap delete mode 100644 Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m delete mode 100755 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap delete mode 100644 Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap delete mode 100644 Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig delete mode 100644 UB.xcworkspace/contents.xcworkspacedata diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock deleted file mode 100644 index b704343..0000000 --- a/Pods/Manifest.lock +++ /dev/null @@ -1,17 +0,0 @@ -PODS: - - SwiftProtobuf (1.6.0) - -DEPENDENCIES: - - SwiftProtobuf - - SwiftProtobuf (~> 1.0) - -SPEC REPOS: - https://github.com/cocoapods/specs.git: - - SwiftProtobuf - -SPEC CHECKSUMS: - SwiftProtobuf: e905ca1366405696411aaf174411c4b19c0ef73d - -PODFILE CHECKSUM: 8bab0dca2a6adb9d64e1fee38b77e3add1ceea2d - -COCOAPODS: 1.7.5 diff --git a/Pods/SwiftProtobuf/LICENSE.txt b/Pods/SwiftProtobuf/LICENSE.txt deleted file mode 100644 index 4b3ed03..0000000 --- a/Pods/SwiftProtobuf/LICENSE.txt +++ /dev/null @@ -1,211 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -## Runtime Library Exception to the Apache 2.0 License: ## - - - As an exception, if you use this Software to compile your source code and - portions of this Software are embedded into the binary product as a result, - you may redistribute such product without providing attribution as would - otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. diff --git a/Pods/SwiftProtobuf/README.md b/Pods/SwiftProtobuf/README.md deleted file mode 100644 index 6dc45b0..0000000 --- a/Pods/SwiftProtobuf/README.md +++ /dev/null @@ -1,300 +0,0 @@ -Swift logo - -# Swift Protobuf - -**Welcome to Swift Protobuf!** - -[Apple's Swift programming language](https://swift.org/) is a perfect -complement to [Google's Protocol -Buffer](https://developers.google.com/protocol-buffers/) ("protobuf") serialization -technology. -They both emphasize high performance and programmer safety. - -This project provides both the command-line program that adds Swift -code generation to Google's `protoc` and the runtime library that is -necessary for using the generated code. -After using the protoc plugin to generate Swift code from your .proto -files, you will need to add this library to your project. - - -# Features of SwiftProtobuf - -SwiftProtobuf offers many advantages over alternative serialization -systems: - -* Safety: The protobuf code-generation system avoids the - errors that are common with hand-built serialization code. -* Correctness: SwiftProtobuf passes both its own extensive - test suite and Google's full conformance test for protobuf - correctness. -* Schema-driven: Defining your data structures in a separate - `.proto` schema file clearly documents your communications - conventions. -* Idiomatic: SwiftProtobuf takes full advantage of the Swift language. - In particular, all generated types provide full Swift copy-on-write - value semantics. -* Efficient binary serialization: The `.serializedData()` - method returns a `Data` with a compact binary form of your data. - You can deserialize the data using the `init(serializedData:)` - initializer. -* Standard JSON serialization: The `.jsonUTF8Data()` method returns a JSON - form of your data that can be parsed with the `init(jsonUTF8Data:)` - initializer. -* Hashable, Equatable: The generated struct can be put into a - `Set<>` or `Dictionary<>`. -* Performant: The binary and JSON serializers have been - extensively optimized. -* Extensible: You can add your own Swift extensions to any - of the generated types. - -Best of all, you can take the same `.proto` file and generate -Java, C++, Python, or Objective-C for use on other platforms. The -generated code for those languages will use the exact same -serialization and deserialization conventions as SwiftProtobuf, making -it easy to exchange serialized data in binary or JSON forms, with no -additional effort on your part. - -# Documentation - -More information is available in the associated documentation: - - * [Google's protobuf documentation](https://developers.google.com/protocol-buffers/) - provides general information about protocol buffers, the protoc compiler, - and how to use protocol buffers with C++, Java, and other languages. - * [PLUGIN.md](Documentation/PLUGIN.md) documents the `protoc-gen-swift` - plugin that adds Swift support to the `protoc` program - * [API.md](Documentation/API.md) documents how to use the generated code. - This is recommended reading for anyone using SwiftProtobuf in their - project. - * [cocoadocs.org](http://cocoadocs.org/docsets/SwiftProtobuf/) has the generated - API documentation - * [INTERNALS.md](Documentation/INTERNALS.md) documents the internal structure - of the generated code and the library. This - should only be needed by folks interested in working on SwiftProtobuf - itself. - * [STYLE_GUIDELINES.md](Documentation/STYLE_GUIDELINES.md) documents the style - guidelines we have adopted in our codebase if you are interested in - contributing - -# Getting Started - -If you've worked with Protocol Buffers before, adding Swift support is very -simple: you just need to build the `protoc-gen-swift` program and copy it into -your PATH. -The `protoc` program will find and use it automatically, allowing you -to build Swift sources for your proto files. -You will also, of course, need to add the SwiftProtobuf runtime library to -your project as explained below. - -## System Requirements - -To use Swift with Protocol buffers, you'll need: - -* A Swift 4.0 or later compiler (Xcode 9.1 or later). Support is included -for the Swift Package Manager; or using the included Xcode project. The Swift -protobuf project is being developed and tested against the latest release -version of Swift available from [Swift.org](https://swift.org) - -* Google's protoc compiler. The Swift protoc plugin is being actively -developed and tested against the latest protobuf sources. -The SwiftProtobuf tests need a version of protoc which supports the -`swift_prefix` option (introduced in protoc 3.2.0). -It may work with earlier versions of protoc. -You can get recent versions from -[Google's github repository](https://github.com/protocolbuffers/protobuf). - -## Building and Installing the Code Generator Plugin - -To translate `.proto` files into Swift, you will need both Google's -protoc compiler and the SwiftProtobuf code generator plugin. - -Building the plugin should be simple on any supported Swift platform: - -``` -$ git clone https://github.com/apple/swift-protobuf.git -$ cd swift-protobuf -``` - -Pick what released version of SwiftProtobuf you are going to use. You can get -a list of tags with: - -``` -$ git tag -l -``` - -Once you pick the version you will use, set your local state to match, and -build the protoc plugin: - -``` -$ git checkout tags/[tag_name] -$ swift build -c release -``` - -This will create a binary called `protoc-gen-swift` in the `.build/release` -directory. - -To install, just copy this one executable into a directory that is -part of your `PATH` environment variable. - -NOTE: The Swift runtime support is now included with macOS. If you are -using old Xcode versions or are on older system versions, you might need -to use also use `--static-swift-stdlib` with `swift build`. - -### Alternatively install via Homebrew - -If you prefer using [Homebrew](https://brew.sh): - -``` -$ brew install swift-protobuf -``` - -This will install `protoc` compiler and Swift code generator plugin. - -## Converting .proto files into Swift - -To generate Swift output for your .proto files, you run the `protoc` command as -usual, using the `--swift_out=` option: - -``` -$ protoc --swift_out=. my.proto -``` - -The `protoc` program will automatically look for `protoc-gen-swift` in your -`PATH` and use it. - -Each `.proto` input file will get translated to a corresponding `.pb.swift` -file in the output directory. - -More information about building and using `protoc-gen-swift` can be found -in the [detailed Plugin documentation](Documentation/PLUGIN.md). - -## Adding the SwiftProtobuf library to your project... - -To use the generated code, you need to include the `SwiftProtobuf` library -module in your project. How you do this will vary depending on how -you're building your project. Note that in all cases, we strongly recommend -that you use the version of the SwiftProtobuf library that corresponds to -the version of `protoc-gen-swift` you used to generate the code. - -### ...using `swift build` - -After copying the `.pb.swift` files into your project, you will need to add the -[SwiftProtobuf library](https://github.com/apple/swift-protobuf) to your -project to support the generated code. -If you are using the Swift Package Manager, add a dependency to your -`Package.swift` file and import the `SwiftProtobuf` library into the desired -targets. Adjust the `"1.6.0"` here to match the `[tag_name]` you used to build -the plugin above: - -```swift -dependencies: [ - .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"), -], -targets: [ - .target(name: "MyTarget", dependencies: ["SwiftProtobuf"]), -] -``` - -### ...using Xcode - -If you are using Xcode, then you should: - -* Add the `.pb.swift` source files generated from your protos directly to your - project -* Add the appropriate `SwiftProtobuf_` target from the Xcode project - in this package to your project. - -### ...using CocoaPods - -If you're using CocoaPods, add this to your `Podfile` adjusting the `:tag` to -match the `[tag_name]` you used to build the plugin above: - -```ruby -pod 'SwiftProtobuf', '~> 1.0' -``` - -And run `pod install`. - -NOTE: CocoaPods 1.7 or newer is required. - -### ...using Carthage - -If you're using Carthage, add this to your `Cartfile` but adjust the tag to match the `[tag_name]` you used to build the plugin above: - -```ruby -github "apple/swift-protobuf" ~> 1.0 -``` - -Run `carthage update` and drag `SwiftProtobuf.framework` into your Xcode.project. - -# Quick Start - -Once you have installed the code generator, used it to -generate Swift code from your `.proto` file, and -added the SwiftProtobuf library to your project, you can -just use the generated types as you would any other Swift -struct. - -For example, you might start with the following very simple -proto file: -```protobuf -syntax = "proto3"; - -message BookInfo { - int64 id = 1; - string title = 2; - string author = 3; -} -``` - -Then generate Swift code using: -``` -$ protoc --swift_out=. DataModel.proto -``` - -The generated code will expose a Swift property for -each of the proto fields as well as a selection -of serialization and deserialization capabilities: -```swift -// Create a BookInfo object and populate it: -var info = BookInfo() -info.id = 1734 -info.title = "Really Interesting Book" -info.author = "Jane Smith" - -// As above, but generating a read-only value: -let info2 = BookInfo.with { - $0.id = 1735 - $0.title = "Even More Interesting" - $0.author = "Jane Q. Smith" - } - -// Serialize to binary protobuf format: -let binaryData: Data = try info.serializedData() - -// Deserialize a received Data object from `binaryData` -let decodedInfo = try BookInfo(serializedData: binaryData) - -// Serialize to JSON format as a Data object -let jsonData: Data = try info.jsonUTF8Data() - -// Deserialize from JSON format from `jsonData` -let receivedFromJSON = try BookInfo(jsonUTF8Data: jsonData) -``` - -You can find more information in the detailed -[API Documentation](Documentation/API.md). - -## Report any issues - -If you run into problems, please send us a detailed report. -At a minimum, please include: - -* The specific operating system and version (for example, "macOS 10.12.1" or - "Ubuntu 16.10") -* The version of Swift you have installed (from `swift --version`) -* The version of the protoc compiler you are working with from - `protoc --version` -* The specific version of this source code (you can use `git log -1` to get the - latest commit ID) -* Any local changes you may have diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift deleted file mode 100644 index 3eb842a..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyMessageStorage.swift +++ /dev/null @@ -1,467 +0,0 @@ -// Sources/SwiftProtobuf/AnyMessageStorage.swift - Custom stroage for Any WKT -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Hand written storage class for Google_Protobuf_Any to support on demand -/// transforms between the formats. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -#if !swift(>=4.2) -private let i_2166136261 = Int(bitPattern: 2166136261) -private let i_16777619 = Int(16777619) -#endif - -fileprivate func serializeAnyJSON( - for message: Message, - typeURL: String, - options: JSONEncodingOptions -) throws -> String { - var visitor = try JSONEncodingVisitor(message: message, options: options) - visitor.startObject() - visitor.encodeField(name: "@type", stringValue: typeURL) - if let m = message as? _CustomJSONCodable { - let value = try m.encodedJSONString(options: options) - visitor.encodeField(name: "value", jsonText: value) - } else { - try message.traverse(visitor: &visitor) - } - visitor.endObject() - return visitor.stringResult -} - -fileprivate func emitVerboseTextForm(visitor: inout TextFormatEncodingVisitor, message: Message, typeURL: String) { - let url: String - if typeURL.isEmpty { - url = buildTypeURL(forMessage: message, typePrefix: defaultAnyTypeURLPrefix) - } else { - url = typeURL - } - visitor.visitAnyVerbose(value: message, typeURL: url) -} - -fileprivate func asJSONObject(body: Data) -> Data { - let asciiOpenCurlyBracket = UInt8(ascii: "{") - let asciiCloseCurlyBracket = UInt8(ascii: "}") - var result = Data([asciiOpenCurlyBracket]) - result.append(body) - result.append(asciiCloseCurlyBracket) - return result -} - -fileprivate func unpack(contentJSON: Data, - options: JSONDecodingOptions, - as messageType: Message.Type) throws -> Message { - guard messageType is _CustomJSONCodable.Type else { - let contentJSONAsObject = asJSONObject(body: contentJSON) - return try messageType.init(jsonUTF8Data: contentJSONAsObject, options: options) - } - - var value = String() - try contentJSON.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var scanner = JSONScanner(source: buffer, - messageDepthLimit: options.messageDepthLimit, - ignoreUnknownFields: options.ignoreUnknownFields) - let key = try scanner.nextQuotedString() - if key != "value" { - // The only thing within a WKT should be "value". - throw AnyUnpackError.malformedWellKnownTypeJSON - } - try scanner.skipRequiredColon() // Can't fail - value = try scanner.skip() - if !scanner.complete { - // If that wasn't the end, then there was another key, - // and WKTs should only have the one. - throw AnyUnpackError.malformedWellKnownTypeJSON - } - } - } - return try messageType.init(jsonString: value, options: options) -} - -internal class AnyMessageStorage { - // The two properties generated Google_Protobuf_Any will reference. - var _typeURL = String() - var _value: Data { - // Remapped to the internal `state`. - get { - switch state { - case .binary(let value): - return value - case .message(let message): - do { - return try message.serializedData(partial: true) - } catch { - return Internal.emptyData - } - case .contentJSON(let contentJSON, let options): - guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) else { - return Internal.emptyData - } - do { - let m = try unpack(contentJSON: contentJSON, - options: options, - as: messageType) - return try m.serializedData(partial: true) - } catch { - return Internal.emptyData - } - } - } - set { - state = .binary(newValue) - } - } - - enum InternalState { - // a serialized binary - // Note: Unlike contentJSON below, binary does not bother to capture the - // decoding options. This is because the actual binary format is the binary - // blob, i.e. - when decoding from binary, the spec doesn't include decoding - // the binary blob, it is pass through. Instead there is a public api for - // unpacking that takes new options when a developer decides to decode it. - case binary(Data) - // a message - case message(Message) - // parsed JSON with the @type removed and the decoding options. - case contentJSON(Data, JSONDecodingOptions) - } - var state: InternalState = .binary(Internal.emptyData) - - static let defaultInstance = AnyMessageStorage() - - private init() {} - - init(copying source: AnyMessageStorage) { - _typeURL = source._typeURL - state = source.state - } - - func isA(_ type: M.Type) -> Bool { - if _typeURL.isEmpty { - return false - } - let encodedType = typeName(fromURL: _typeURL) - return encodedType == M.protoMessageName - } - - // This is only ever called with the expactation that target will be fully - // replaced during the unpacking and never as a merge. - func unpackTo( - target: inout M, - extensions: ExtensionMap?, - options: BinaryDecodingOptions - ) throws { - guard isA(M.self) else { - throw AnyUnpackError.typeMismatch - } - - switch state { - case .binary(let data): - target = try M(serializedData: data, extensions: extensions, partial: true, options: options) - - case .message(let msg): - if let message = msg as? M { - // Already right type, copy it over. - target = message - } else { - // Different type, serialize and parse. - let data = try msg.serializedData(partial: true) - target = try M(serializedData: data, extensions: extensions, partial: true) - } - - case .contentJSON(let contentJSON, let options): - target = try unpack(contentJSON: contentJSON, - options: options, - as: M.self) as! M - } - } - - // Called before the message is traversed to do any error preflights. - // Since traverse() will use _value, this is our chance to throw - // when _value can't. - func preTraverse() throws { - switch state { - case .binary: - // Nothing to be checked. - break - - case .message: - // When set from a developer provided message, partial support - // is done. Any message that comes in from another format isn't - // checked, and transcoding the isInitialized requirement is - // never inserted. - break - - case .contentJSON: - // contentJSON requires a good URL and our ability to look up - // the message type to transcode. - if Google_Protobuf_Any.messageType(forTypeURL: _typeURL) == nil { - // Isn't registered, we can't transform it for binary. - throw BinaryEncodingError.anyTranscodeFailure - } - } - } -} - -/// Custom handling for Text format. -extension AnyMessageStorage { - func decodeTextFormat(typeURL url: String, decoder: inout TextFormatDecoder) throws { - // Decoding the verbose form requires knowing the type. - _typeURL = url - guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: url) else { - // The type wasn't registered, can't parse it. - throw TextFormatDecodingError.malformedText - } - let terminator = try decoder.scanner.skipObjectStart() - var subDecoder = try TextFormatDecoder(messageType: messageType, scanner: decoder.scanner, terminator: terminator) - if messageType == Google_Protobuf_Any.self { - var any = Google_Protobuf_Any() - try any.decodeTextFormat(decoder: &subDecoder) - state = .message(any) - } else { - var m = messageType.init() - try m.decodeMessage(decoder: &subDecoder) - state = .message(m) - } - decoder.scanner = subDecoder.scanner - if try decoder.nextFieldNumber() != nil { - // Verbose any can never have additional keys. - throw TextFormatDecodingError.malformedText - } - } - - // Specialized traverse for writing out a Text form of the Any. - // This prefers the more-legible "verbose" format if it can - // use it, otherwise will fall back to simpler forms. - internal func textTraverse(visitor: inout TextFormatEncodingVisitor) { - switch state { - case .binary(let valueData): - if let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) { - // If we can decode it, we can write the readable verbose form: - do { - let m = try messageType.init(serializedData: valueData, partial: true) - emitVerboseTextForm(visitor: &visitor, message: m, typeURL: _typeURL) - return - } catch { - // Fall through to just print the type and raw binary data - } - } - if !_typeURL.isEmpty { - try! visitor.visitSingularStringField(value: _typeURL, fieldNumber: 1) - } - if !valueData.isEmpty { - try! visitor.visitSingularBytesField(value: valueData, fieldNumber: 2) - } - - case .message(let msg): - emitVerboseTextForm(visitor: &visitor, message: msg, typeURL: _typeURL) - - case .contentJSON(let contentJSON, let options): - // If we can decode it, we can write the readable verbose form: - if let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) { - do { - let m = try unpack(contentJSON: contentJSON, - options: options, - as: messageType) - emitVerboseTextForm(visitor: &visitor, message: m, typeURL: _typeURL) - return - } catch { - // Fall through to just print the raw JSON data - } - } - if !_typeURL.isEmpty { - try! visitor.visitSingularStringField(value: _typeURL, fieldNumber: 1) - } - // Build a readable form of the JSON: - let contentJSONAsObject = asJSONObject(body: contentJSON) - visitor.visitAnyJSONDataField(value: contentJSONAsObject) - } - } -} - -/// The obvious goal for Hashable/Equatable conformance would be for -/// hash and equality to behave as if we always decoded the inner -/// object and hashed or compared that. Unfortunately, Any typically -/// stores serialized contents and we don't always have the ability to -/// deserialize it. Since none of our supported serializations are -/// fully deterministic, we can't even ensure that equality will -/// behave this way when the Any contents are in the same -/// serialization. -/// -/// As a result, we can only really perform a "best effort" equality -/// test. Of course, regardless of the above, we must guarantee that -/// hashValue is compatible with equality. -extension AnyMessageStorage { -#if swift(>=4.2) - // Can't use _valueData for a few reasons: - // 1. Since decode is done on demand, two objects could be equal - // but created differently (one from JSON, one for Message, etc.), - // and the hash values have to be equal even if we don't have data - // yet. - // 2. map<> serialization order is undefined. At the time of writing - // the Swift, Objective-C, and Go runtimes all tend to have random - // orders, so the messages could be identical, but in binary form - // they could differ. - public func hash(into hasher: inout Hasher) { - if !_typeURL.isEmpty { - hasher.combine(_typeURL) - } - } -#else // swift(>=4.2) - var hashValue: Int { - var hash: Int = i_2166136261 - if !_typeURL.isEmpty { - hash = (hash &* i_16777619) ^ _typeURL.hashValue - } - return hash - } -#endif // swift(>=4.2) - - func isEqualTo(other: AnyMessageStorage) -> Bool { - if (_typeURL != other._typeURL) { - return false - } - - // Since the library does lazy Any decode, equality is a very hard problem. - // It things exactly match, that's pretty easy, otherwise, one ends up having - // to error on saying they aren't equal. - // - // The best option would be to have Message forms and compare those, as that - // removes issues like map<> serialization order, some other protocol buffer - // implementation details/bugs around serialized form order, etc.; but that - // would also greatly slow down equality tests. - // - // Do our best to compare what is present have... - - // If both have messages, check if they are the same. - if case .message(let myMsg) = state, case .message(let otherMsg) = other.state, type(of: myMsg) == type(of: otherMsg) { - // Since the messages are known to be same type, we can claim both equal and - // not equal based on the equality comparison. - return myMsg.isEqualTo(message: otherMsg) - } - - // If both have serialized data, and they exactly match; the messages are equal. - // Because there could be map in the message, the fact that the data isn't the - // same doesn't always mean the messages aren't equal. Likewise, the binary could - // have been created by a library that doesn't order the fields, or the binary was - // created using the appending ability in of the binary format. - if case .binary(let myValue) = state, case .binary(let otherValue) = other.state, myValue == otherValue { - return true - } - - // If both have contentJSON, and they exactly match; the messages are equal. - // Because there could be map in the message (or the JSON could just be in a different - // order), the fact that the JSON isn't the same doesn't always mean the messages - // aren't equal. - if case .contentJSON(let myJSON, _) = state, - case .contentJSON(let otherJSON, _) = other.state, - myJSON == otherJSON { - return true - } - - // Out of options. To do more compares, the states conversions would have to be - // done to do comparisions; and since equality can be used somewhat removed from - // a developer (if they put protos in a Set, use them as keys to a Dictionary, etc), - // the conversion cost might be to high for those uses. Give up and say they aren't equal. - return false - } -} - -// _CustomJSONCodable support for Google_Protobuf_Any -extension AnyMessageStorage { - // Override the traversal-based JSON encoding - // This builds an Any JSON representation from one of: - // * The message we were initialized with, - // * The JSON fields we last deserialized, or - // * The protobuf field we were deserialized from. - // The last case requires locating the type, deserializing - // into an object, then reserializing back to JSON. - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - switch state { - case .binary(let valueData): - // Transcode by decoding the binary data to a message object - // and then recode back into JSON. - guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) else { - // If we don't have the type available, we can't decode the - // binary value, so we're stuck. (The Google spec does not - // provide a way to just package the binary value for someone - // else to decode later.) - throw JSONEncodingError.anyTranscodeFailure - } - let m = try messageType.init(serializedData: valueData, partial: true) - return try serializeAnyJSON(for: m, typeURL: _typeURL, options: options) - - case .message(let msg): - // We should have been initialized with a typeURL, but - // ensure it wasn't cleared. - let url = !_typeURL.isEmpty ? _typeURL : buildTypeURL(forMessage: msg, typePrefix: defaultAnyTypeURLPrefix) - return try serializeAnyJSON(for: msg, typeURL: url, options: options) - - case .contentJSON(let contentJSON, _): - var jsonEncoder = JSONEncoder() - jsonEncoder.startObject() - jsonEncoder.startField(name: "@type") - jsonEncoder.putStringValue(value: _typeURL) - if !contentJSON.isEmpty { - jsonEncoder.append(staticText: ",") - // NOTE: This doesn't really take `options` into account since it is - // just reflecting out what was taken in originally. - jsonEncoder.append(utf8Data: contentJSON) - } - jsonEncoder.endObject() - return jsonEncoder.stringResult - } - } - - // TODO: If the type is well-known or has already been registered, - // we should consider decoding eagerly. Eager decoding would - // catch certain errors earlier (good) but would probably be - // a performance hit if the Any contents were never accessed (bad). - // Of course, we can't always decode eagerly (we don't always have the - // message type available), so the deferred logic here is still needed. - func decodeJSON(from decoder: inout JSONDecoder) throws { - try decoder.scanner.skipRequiredObjectStart() - // Reset state - _typeURL = String() - state = .binary(Internal.emptyData) - if decoder.scanner.skipOptionalObjectEnd() { - return - } - - var jsonEncoder = JSONEncoder() - while true { - let key = try decoder.scanner.nextQuotedString() - try decoder.scanner.skipRequiredColon() - if key == "@type" { - _typeURL = try decoder.scanner.nextQuotedString() - } else { - jsonEncoder.startField(name: key) - let keyValueJSON = try decoder.scanner.skip() - jsonEncoder.append(text: keyValueJSON) - } - if decoder.scanner.skipOptionalObjectEnd() { - // Capture the options, but set the messageDepthLimit to be what - // was left right now, as that is the limit when the JSON is finally - // parsed. - var updatedOptions = decoder.options - updatedOptions.messageDepthLimit = decoder.scanner.recursionBudget - state = .contentJSON(jsonEncoder.dataResult, updatedOptions) - return - } - try decoder.scanner.skipRequiredComma() - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift deleted file mode 100644 index 29fb0d0..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/AnyUnpackError.swift +++ /dev/null @@ -1,37 +0,0 @@ -// Sources/SwiftProtobuf/AnyUnpackError.swift - Any Unpacking Errors -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Errors that can be throw when unpacking a Google_Protobuf_Any. -/// -// ----------------------------------------------------------------------------- - -/// Describes errors that can occur when unpacking an `Google_Protobuf_Any` -/// message. -/// -/// `Google_Protobuf_Any` messages can be decoded from protobuf binary, text -/// format, or JSON. The contents are not parsed immediately; the raw data is -/// held in the `Google_Protobuf_Any` message until you `unpack()` it into a -/// message. At this time, any error can occur that might have occurred from a -/// regular decoding operation. There are also other errors that can occur due -/// to problems with the `Any` value's structure. -public enum AnyUnpackError: Error { - /// The `type_url` field in the `Google_Protobuf_Any` message did not match - /// the message type provided to the `unpack()` method. - case typeMismatch - - /// Well-known types being decoded from JSON must have only two fields: the - /// `@type` field and a `value` field containing the specialized JSON coding - /// of the well-known type. - case malformedWellKnownTypeJSON - - /// The `Google_Protobuf_Any` message was malformed in some other way not - /// covered by the other error cases. - case malformedAnyField -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift deleted file mode 100644 index 53144d0..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecoder.swift +++ /dev/null @@ -1,1503 +0,0 @@ -// Sources/SwiftProtobuf/BinaryDecoder.swift - Binary decoding -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Protobuf binary format decoding engine. -/// -/// This provides the Decoder interface that interacts directly -/// with the generated code. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -internal struct BinaryDecoder: Decoder { - // Current position - private var p : UnsafePointer - // Remaining bytes in input. - private var available : Int - // Position of start of field currently being parsed - private var fieldStartP : UnsafePointer - // Position of end of field currently being parsed, nil if we don't know. - private var fieldEndP : UnsafePointer? - // Whether or not the field value has actually been parsed - private var consumed = true - // Wire format for last-examined field - internal var fieldWireFormat = WireFormat.varint - // Field number for last-parsed field tag - private var fieldNumber: Int = 0 - // Collection of extension fields for this decode - private var extensions: ExtensionMap? - // The current group number. See decodeFullGroup(group:fieldNumber:) for how - // this is used. - private var groupFieldNumber: Int? - // The options for decoding. - private var options: BinaryDecodingOptions - - private var recursionBudget: Int - - // Collects the unknown data found while decoding a message. - private var unknownData: Data? - // Custom data to use as the unknown data while parsing a field. Used only by - // packed repeated enums; see below - private var unknownOverride: Data? - - private var complete: Bool {return available == 0} - - internal init( - forReadingFrom pointer: UnsafePointer, - count: Int, - options: BinaryDecodingOptions, - extensions: ExtensionMap? = nil - ) { - // Assuming baseAddress is not nil. - p = pointer - available = count - fieldStartP = p - self.extensions = extensions - self.options = options - recursionBudget = options.messageDepthLimit - } - - internal init( - forReadingFrom pointer: UnsafePointer, - count: Int, - parent: BinaryDecoder - ) { - self.init(forReadingFrom: pointer, - count: count, - options: parent.options, - extensions: parent.extensions) - recursionBudget = parent.recursionBudget - } - - private mutating func incrementRecursionDepth() throws { - recursionBudget -= 1 - if recursionBudget < 0 { - throw BinaryDecodingError.messageDepthLimit - } - } - - private mutating func decrementRecursionDepth() { - recursionBudget += 1 - // This should never happen, if it does, something is probably corrupting memory, and - // simply throwing doesn't make much sense. - if recursionBudget > options.messageDepthLimit { - fatalError("Somehow BinaryDecoding unwound more objects than it started") - } - } - - internal mutating func handleConflictingOneOf() throws { - /// Protobuf simply allows conflicting oneof values to overwrite - } - - /// Return the next field number or nil if there are no more fields. - internal mutating func nextFieldNumber() throws -> Int? { - // Since this is called for every field, I've taken some pains - // to optimize it, including unrolling a tweaked version of - // the varint parser. - if fieldNumber > 0 { - if let override = unknownOverride { - assert(!options.discardUnknownFields) - assert(fieldWireFormat != .startGroup && fieldWireFormat != .endGroup) - if unknownData == nil { - unknownData = override - } else { - unknownData!.append(override) - } - unknownOverride = nil - } else if !consumed { - if options.discardUnknownFields { - try skip() - } else { - let u = try getRawField() - if unknownData == nil { - unknownData = u - } else { - unknownData!.append(u) - } - } - } - } - - // Quit if end of input - if available == 0 { - return nil - } - - // Get the next field number - fieldStartP = p - fieldEndP = nil - let start = p - let c0 = start[0] - if let wireFormat = WireFormat(rawValue: c0 & 7) { - fieldWireFormat = wireFormat - } else { - throw BinaryDecodingError.malformedProtobuf - } - if (c0 & 0x80) == 0 { - p += 1 - available -= 1 - fieldNumber = Int(c0) >> 3 - } else { - fieldNumber = Int(c0 & 0x7f) >> 3 - if available < 2 { - throw BinaryDecodingError.malformedProtobuf - } - let c1 = start[1] - if (c1 & 0x80) == 0 { - p += 2 - available -= 2 - fieldNumber |= Int(c1) << 4 - } else { - fieldNumber |= Int(c1 & 0x7f) << 4 - if available < 3 { - throw BinaryDecodingError.malformedProtobuf - } - let c2 = start[2] - fieldNumber |= Int(c2 & 0x7f) << 11 - if (c2 & 0x80) == 0 { - p += 3 - available -= 3 - } else { - if available < 4 { - throw BinaryDecodingError.malformedProtobuf - } - let c3 = start[3] - fieldNumber |= Int(c3 & 0x7f) << 18 - if (c3 & 0x80) == 0 { - p += 4 - available -= 4 - } else { - if available < 5 { - throw BinaryDecodingError.malformedProtobuf - } - let c4 = start[4] - if c4 > 15 { - throw BinaryDecodingError.malformedProtobuf - } - fieldNumber |= Int(c4 & 0x7f) << 25 - p += 5 - available -= 5 - } - } - } - } - if fieldNumber != 0 { - consumed = false - - if fieldWireFormat == .endGroup { - if groupFieldNumber == fieldNumber { - // Reached the end of the current group, single the - // end of the message. - return nil - } else { - // .endGroup when not in a group or for a different - // group is an invalid binary. - throw BinaryDecodingError.malformedProtobuf - } - } - return fieldNumber - } - throw BinaryDecodingError.malformedProtobuf - } - - internal mutating func decodeSingularFloatField(value: inout Float) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - try decodeFourByteNumber(value: &value) - consumed = true - } - - internal mutating func decodeSingularFloatField(value: inout Float?) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - value = try decodeFloat() - consumed = true - } - - internal mutating func decodeRepeatedFloatField(value: inout [Float]) throws { - switch fieldWireFormat { - case WireFormat.fixed32: - let i = try decodeFloat() - value.append(i) - consumed = true - case WireFormat.lengthDelimited: - let bodyBytes = try decodeVarint() - if bodyBytes > 0 { - let itemSize = UInt64(MemoryLayout.size) - let itemCount = bodyBytes / itemSize - if bodyBytes % itemSize != 0 || itemCount > UInt64(Int.max) { - throw BinaryDecodingError.truncated - } - value.reserveCapacity(value.count + Int(truncatingIfNeeded: itemCount)) - for _ in 1...itemCount { - value.append(try decodeFloat()) - } - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularDoubleField(value: inout Double) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - value = try decodeDouble() - consumed = true - } - - internal mutating func decodeSingularDoubleField(value: inout Double?) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - value = try decodeDouble() - consumed = true - } - - internal mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { - switch fieldWireFormat { - case WireFormat.fixed64: - let i = try decodeDouble() - value.append(i) - consumed = true - case WireFormat.lengthDelimited: - let bodyBytes = try decodeVarint() - if bodyBytes > 0 { - let itemSize = UInt64(MemoryLayout.size) - let itemCount = bodyBytes / itemSize - if bodyBytes % itemSize != 0 || itemCount > UInt64(Int.max) { - throw BinaryDecodingError.truncated - } - value.reserveCapacity(value.count + Int(truncatingIfNeeded: itemCount)) - for _ in 1...itemCount { - let i = try decodeDouble() - value.append(i) - } - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularInt32Field(value: inout Int32) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = Int32(truncatingIfNeeded: varint) - consumed = true - } - - internal mutating func decodeSingularInt32Field(value: inout Int32?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = Int32(truncatingIfNeeded: varint) - consumed = true - } - - internal mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(Int32(truncatingIfNeeded: varint)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let varint = try decoder.decodeVarint() - value.append(Int32(truncatingIfNeeded: varint)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularInt64Field(value: inout Int64) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let v = try decodeVarint() - value = Int64(bitPattern: v) - consumed = true - } - - internal mutating func decodeSingularInt64Field(value: inout Int64?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = Int64(bitPattern: varint) - consumed = true - } - - internal mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(Int64(bitPattern: varint)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let varint = try decoder.decodeVarint() - value.append(Int64(bitPattern: varint)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularUInt32Field(value: inout UInt32) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = UInt32(truncatingIfNeeded: varint) - consumed = true - } - - internal mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = UInt32(truncatingIfNeeded: varint) - consumed = true - } - - internal mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(UInt32(truncatingIfNeeded: varint)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let t = try decoder.decodeVarint() - value.append(UInt32(truncatingIfNeeded: t)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularUInt64Field(value: inout UInt64) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - value = try decodeVarint() - consumed = true - } - - internal mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - value = try decodeVarint() - consumed = true - } - - internal mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(varint) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let t = try decoder.decodeVarint() - value.append(t) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularSInt32Field(value: inout Int32) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - let t = UInt32(truncatingIfNeeded: varint) - value = ZigZag.decoded(t) - consumed = true - } - - internal mutating func decodeSingularSInt32Field(value: inout Int32?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - let t = UInt32(truncatingIfNeeded: varint) - value = ZigZag.decoded(t) - consumed = true - } - - internal mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - let t = UInt32(truncatingIfNeeded: varint) - value.append(ZigZag.decoded(t)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let varint = try decoder.decodeVarint() - let t = UInt32(truncatingIfNeeded: varint) - value.append(ZigZag.decoded(t)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularSInt64Field(value: inout Int64) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = ZigZag.decoded(varint) - consumed = true - } - - internal mutating func decodeSingularSInt64Field(value: inout Int64?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - value = ZigZag.decoded(varint) - consumed = true - } - - internal mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(ZigZag.decoded(varint)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let varint = try decoder.decodeVarint() - value.append(ZigZag.decoded(varint)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularFixed32Field(value: inout UInt32) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - var i: UInt32 = 0 - try decodeFourByteNumber(value: &i) - value = UInt32(littleEndian: i) - consumed = true - } - - internal mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - var i: UInt32 = 0 - try decodeFourByteNumber(value: &i) - value = UInt32(littleEndian: i) - consumed = true - } - - internal mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { - switch fieldWireFormat { - case WireFormat.fixed32: - var i: UInt32 = 0 - try decodeFourByteNumber(value: &i) - value.append(UInt32(littleEndian: i)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value.reserveCapacity(value.count + n / MemoryLayout.size) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - var i: UInt32 = 0 - while !decoder.complete { - try decoder.decodeFourByteNumber(value: &i) - value.append(UInt32(littleEndian: i)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularFixed64Field(value: inout UInt64) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - var i: UInt64 = 0 - try decodeEightByteNumber(value: &i) - value = UInt64(littleEndian: i) - consumed = true - } - - internal mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - var i: UInt64 = 0 - try decodeEightByteNumber(value: &i) - value = UInt64(littleEndian: i) - consumed = true - } - - internal mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { - switch fieldWireFormat { - case WireFormat.fixed64: - var i: UInt64 = 0 - try decodeEightByteNumber(value: &i) - value.append(UInt64(littleEndian: i)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value.reserveCapacity(value.count + n / MemoryLayout.size) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - var i: UInt64 = 0 - while !decoder.complete { - try decoder.decodeEightByteNumber(value: &i) - value.append(UInt64(littleEndian: i)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularSFixed32Field(value: inout Int32) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - var i: Int32 = 0 - try decodeFourByteNumber(value: &i) - value = Int32(littleEndian: i) - consumed = true - } - - internal mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { - guard fieldWireFormat == WireFormat.fixed32 else { - return - } - var i: Int32 = 0 - try decodeFourByteNumber(value: &i) - value = Int32(littleEndian: i) - consumed = true - } - - internal mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { - switch fieldWireFormat { - case WireFormat.fixed32: - var i: Int32 = 0 - try decodeFourByteNumber(value: &i) - value.append(Int32(littleEndian: i)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value.reserveCapacity(value.count + n / MemoryLayout.size) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - var i: Int32 = 0 - while !decoder.complete { - try decoder.decodeFourByteNumber(value: &i) - value.append(Int32(littleEndian: i)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularSFixed64Field(value: inout Int64) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - var i: Int64 = 0 - try decodeEightByteNumber(value: &i) - value = Int64(littleEndian: i) - consumed = true - } - - internal mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { - guard fieldWireFormat == WireFormat.fixed64 else { - return - } - var i: Int64 = 0 - try decodeEightByteNumber(value: &i) - value = Int64(littleEndian: i) - consumed = true - } - - internal mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { - switch fieldWireFormat { - case WireFormat.fixed64: - var i: Int64 = 0 - try decodeEightByteNumber(value: &i) - value.append(Int64(littleEndian: i)) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value.reserveCapacity(value.count + n / MemoryLayout.size) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - var i: Int64 = 0 - while !decoder.complete { - try decoder.decodeEightByteNumber(value: &i) - value.append(Int64(littleEndian: i)) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularBoolField(value: inout Bool) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - value = try decodeVarint() != 0 - consumed = true - } - - internal mutating func decodeSingularBoolField(value: inout Bool?) throws { - guard fieldWireFormat == WireFormat.varint else { - return - } - value = try decodeVarint() != 0 - consumed = true - } - - internal mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - value.append(varint != 0) - consumed = true - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var decoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !decoder.complete { - let t = try decoder.decodeVarint() - value.append(t != 0) - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularStringField(value: inout String) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - if let s = utf8ToString(bytes: p, count: n) { - value = s - consumed = true - } else { - throw BinaryDecodingError.invalidUTF8 - } - } - - internal mutating func decodeSingularStringField(value: inout String?) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - if let s = utf8ToString(bytes: p, count: n) { - value = s - consumed = true - } else { - throw BinaryDecodingError.invalidUTF8 - } - } - - internal mutating func decodeRepeatedStringField(value: inout [String]) throws { - switch fieldWireFormat { - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - if let s = utf8ToString(bytes: p, count: n) { - value.append(s) - consumed = true - } else { - throw BinaryDecodingError.invalidUTF8 - } - default: - return - } - } - - internal mutating func decodeSingularBytesField(value: inout Data) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value = Data(bytes: p, count: n) - consumed = true - } - - internal mutating func decodeSingularBytesField(value: inout Data?) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value = Data(bytes: p, count: n) - consumed = true - } - - internal mutating func decodeRepeatedBytesField(value: inout [Data]) throws { - switch fieldWireFormat { - case WireFormat.lengthDelimited: - var n: Int = 0 - let p = try getFieldBodyBytes(count: &n) - value.append(Data(bytes: p, count: n)) - consumed = true - default: - return - } - } - - internal mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { - value = v - consumed = true - } - } - - internal mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int { - guard fieldWireFormat == WireFormat.varint else { - return - } - let varint = try decodeVarint() - if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { - value = v - consumed = true - } - } - - internal mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int { - switch fieldWireFormat { - case WireFormat.varint: - let varint = try decodeVarint() - if let v = E(rawValue: Int(Int32(truncatingIfNeeded: varint))) { - value.append(v) - consumed = true - } - case WireFormat.lengthDelimited: - var n: Int = 0 - var extras: [Int32]? - let p = try getFieldBodyBytes(count: &n) - let ints = Varint.countVarintsInBuffer(start: p, count: n) - value.reserveCapacity(value.count + ints) - var subdecoder = BinaryDecoder(forReadingFrom: p, count: n, parent: self) - while !subdecoder.complete { - let u64 = try subdecoder.decodeVarint() - let i32 = Int32(truncatingIfNeeded: u64) - if let v = E(rawValue: Int(i32)) { - value.append(v) - } else if !options.discardUnknownFields { - if extras == nil { - extras = [] - } - extras!.append(i32) - } - } - if let extras = extras { - let fieldTag = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var bodySize = 0 - for v in extras { - bodySize += Varint.encodedSize(of: Int64(v)) - } - let fieldSize = Varint.encodedSize(of: fieldTag.rawValue) + Varint.encodedSize(of: Int64(bodySize)) + bodySize - var field = Data(count: fieldSize) - field.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - var encoder = BinaryEncoder(forWritingInto: pointer) - encoder.startField(tag: fieldTag) - encoder.putVarInt(value: Int64(bodySize)) - for v in extras { - encoder.putVarInt(value: Int64(v)) - } - } - } - unknownOverride = field - } - consumed = true - default: - return - } - } - - internal mutating func decodeSingularMessageField(value: inout M?) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var count: Int = 0 - let p = try getFieldBodyBytes(count: &count) - if value == nil { - value = M() - } - var subDecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) - try subDecoder.decodeFullMessage(message: &value!) - consumed = true - } - - internal mutating func decodeRepeatedMessageField(value: inout [M]) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var count: Int = 0 - let p = try getFieldBodyBytes(count: &count) - var newValue = M() - var subDecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) - try subDecoder.decodeFullMessage(message: &newValue) - value.append(newValue) - consumed = true - } - - internal mutating func decodeFullMessage(message: inout M) throws { - try incrementRecursionDepth() - try message.decodeMessage(decoder: &self) - decrementRecursionDepth() - guard complete else { - throw BinaryDecodingError.trailingGarbage - } - if let unknownData = unknownData { - message.unknownFields.append(protobufData: unknownData) - } - } - - internal mutating func decodeSingularGroupField(value: inout G?) throws { - var group = value ?? G() - if try decodeFullGroup(group: &group, fieldNumber: fieldNumber) { - value = group - consumed = true - } - } - - internal mutating func decodeRepeatedGroupField(value: inout [G]) throws { - var group = G() - if try decodeFullGroup(group: &group, fieldNumber: fieldNumber) { - value.append(group) - consumed = true - } - } - - private mutating func decodeFullGroup(group: inout G, fieldNumber: Int) throws -> Bool { - guard fieldWireFormat == WireFormat.startGroup else { - return false - } - assert(unknownData == nil) - - try incrementRecursionDepth() - - // This works by making a clone of the current decoder state and - // setting `groupFieldNumber` to signal `nextFieldNumber()` to watch - // for that as a marker for having reached the end of a group/message. - // Groups within groups works because this effectively makes a stack - // of decoders, each one looking for their ending tag. - - var subDecoder = self - subDecoder.groupFieldNumber = fieldNumber - // startGroup was read, so current tag/data is done (otherwise the - // startTag will end up in the unknowns of the first thing decoded). - subDecoder.consumed = true - try group.decodeMessage(decoder: &subDecoder) - guard subDecoder.fieldNumber == fieldNumber && subDecoder.fieldWireFormat == .endGroup else { - throw BinaryDecodingError.truncated - } - if let groupUnknowns = subDecoder.unknownData { - group.unknownFields.append(protobufData: groupUnknowns) - } - // Advance over what was parsed. - consume(length: available - subDecoder.available) - assert(recursionBudget == subDecoder.recursionBudget) - decrementRecursionDepth() - return true - } - - internal mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var k: KeyType.BaseType? - var v: ValueType.BaseType? - var count: Int = 0 - let p = try getFieldBodyBytes(count: &count) - var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) - while let tag = try subdecoder.getTag() { - if tag.wireFormat == .endGroup { - throw BinaryDecodingError.malformedProtobuf - } - let fieldNumber = tag.fieldNumber - switch fieldNumber { - case 1: - try KeyType.decodeSingular(value: &k, from: &subdecoder) - case 2: - try ValueType.decodeSingular(value: &v, from: &subdecoder) - default: // Skip any other fields within the map entry object - try subdecoder.skip() - } - } - if !subdecoder.complete { - throw BinaryDecodingError.trailingGarbage - } - // A map<> definition can't provide a default value for the keys/values, - // so it is safe to use the proto3 default to get the right - // integer/string/bytes. The one catch is a proto2 enum (which can be the - // value) can have a non zero value, but that case is the next - // custom decodeMapField<>() method and handles it. - value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType.proto3DefaultValue - consumed = true - } - - internal mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var k: KeyType.BaseType? - var v: ValueType? - var count: Int = 0 - let p = try getFieldBodyBytes(count: &count) - var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) - while let tag = try subdecoder.getTag() { - if tag.wireFormat == .endGroup { - throw BinaryDecodingError.malformedProtobuf - } - let fieldNumber = tag.fieldNumber - switch fieldNumber { - case 1: // Keys are basic types - try KeyType.decodeSingular(value: &k, from: &subdecoder) - case 2: // Value is an Enum type - try subdecoder.decodeSingularEnumField(value: &v) - if v == nil && tag.wireFormat == .varint { - // Enum decode fail and wire format was varint, so this had to - // have been a proto2 unknown enum value. This whole map entry - // into the parent message's unknown fields. If the wire format - // was wrong, treat it like an unknown field and drop it with - // the map entry. - return - } - default: // Skip any other fields within the map entry object - try subdecoder.skip() - } - } - if !subdecoder.complete { - throw BinaryDecodingError.trailingGarbage - } - // A map<> definition can't provide a default value for the keys, so it - // is safe to use the proto3 default to get the right integer/string/bytes. - value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType() - consumed = true - } - - internal mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { - guard fieldWireFormat == WireFormat.lengthDelimited else { - return - } - var k: KeyType.BaseType? - var v: ValueType? - var count: Int = 0 - let p = try getFieldBodyBytes(count: &count) - var subdecoder = BinaryDecoder(forReadingFrom: p, count: count, parent: self) - while let tag = try subdecoder.getTag() { - if tag.wireFormat == .endGroup { - throw BinaryDecodingError.malformedProtobuf - } - let fieldNumber = tag.fieldNumber - switch fieldNumber { - case 1: // Keys are basic types - try KeyType.decodeSingular(value: &k, from: &subdecoder) - case 2: // Value is a message type - try subdecoder.decodeSingularMessageField(value: &v) - default: // Skip any other fields within the map entry object - try subdecoder.skip() - } - } - if !subdecoder.complete { - throw BinaryDecodingError.trailingGarbage - } - // A map<> definition can't provide a default value for the keys, so it - // is safe to use the proto3 default to get the right integer/string/bytes. - value[k ?? KeyType.proto3DefaultValue] = v ?? ValueType() - consumed = true - } - - internal mutating func decodeExtensionField( - values: inout ExtensionFieldValueSet, - messageType: Message.Type, - fieldNumber: Int - ) throws { - if let ext = extensions?[messageType, fieldNumber] { - try decodeExtensionField(values: &values, - messageType: messageType, - fieldNumber: fieldNumber, - messageExtension: ext) - } - } - - /// Helper to reuse between Extension decoding and MessageSet Extension decoding. - private mutating func decodeExtensionField( - values: inout ExtensionFieldValueSet, - messageType: Message.Type, - fieldNumber: Int, - messageExtension ext: AnyMessageExtension - ) throws { - assert(!consumed) - assert(fieldNumber == ext.fieldNumber) - var fieldValue = values[fieldNumber] - // Message/Group extensions both will call back into the matching - // decode methods, so the recursion depth will be tracked there. - if fieldValue != nil { - try fieldValue!.decodeExtensionField(decoder: &self) - } else { - fieldValue = try ext._protobuf_newField(decoder: &self) - } - if consumed { - if fieldValue != nil { - values[fieldNumber] = fieldValue - } else { - // Really things should never get here, if the decoder says - // the bytes were consumed, then there should have been a - // field that consumed them (existing or created). This - // specific error result is to allow this to be more detectable. - throw BinaryDecodingError.internalExtensionError - } - } - } - - internal mutating func decodeExtensionFieldsAsMessageSet( - values: inout ExtensionFieldValueSet, - messageType: Message.Type - ) throws { - // Spin looking for the Item group, everything else will end up in unknown fields. - while let fieldNumber = try self.nextFieldNumber() { - guard fieldNumber == WireFormat.MessageSet.FieldNumbers.item && - fieldWireFormat == WireFormat.startGroup else { - continue - } - - // This is similiar to decodeFullGroup - - try incrementRecursionDepth() - var subDecoder = self - subDecoder.groupFieldNumber = fieldNumber - subDecoder.consumed = true - - let itemResult = try subDecoder.decodeMessageSetItem(values: &values, - messageType: messageType) - switch itemResult { - case .success: - // Advance over what was parsed. - consume(length: available - subDecoder.available) - consumed = true - case .handleAsUnknown: - // Nothing to do. - break - - case .malformed: - throw BinaryDecodingError.malformedProtobuf - } - - assert(recursionBudget == subDecoder.recursionBudget) - decrementRecursionDepth() - } - } - - private enum DecodeMessageSetItemResult { - case success - case handleAsUnknown - case malformed - } - - private mutating func decodeMessageSetItem( - values: inout ExtensionFieldValueSet, - messageType: Message.Type - ) throws -> DecodeMessageSetItemResult { - // This is loosely based on the C++: - // ExtensionSet::ParseMessageSetItem() - // WireFormat::ParseAndMergeMessageSetItem() - // (yes, there have two versions that are almost the same) - - var msgExtension: AnyMessageExtension? - var fieldData: Data? - - // In this loop, if wire types are wrong, things don't decode, - // just bail instead of letting things go into unknown fields. - // Wrongly formed MessageSets don't seem don't have real - // spelled out behaviors. - while let fieldNumber = try self.nextFieldNumber() { - switch fieldNumber { - case WireFormat.MessageSet.FieldNumbers.typeId: - var extensionFieldNumber: Int32 = 0 - try decodeSingularInt32Field(value: &extensionFieldNumber) - if extensionFieldNumber == 0 { return .malformed } - guard let ext = extensions?[messageType, Int(extensionFieldNumber)] else { - return .handleAsUnknown // Unknown extension. - } - msgExtension = ext - - // If there already was fieldData, decode it. - if let data = fieldData { - var wasDecoded = false - try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - var extDecoder = BinaryDecoder(forReadingFrom: pointer, - count: body.count, - parent: self) - // Prime the decode to be correct. - extDecoder.consumed = false - extDecoder.fieldWireFormat = .lengthDelimited - try extDecoder.decodeExtensionField(values: &values, - messageType: messageType, - fieldNumber: fieldNumber, - messageExtension: ext) - wasDecoded = extDecoder.consumed - } - } - if !wasDecoded { - return .malformed - } - fieldData = nil - } - - case WireFormat.MessageSet.FieldNumbers.message: - if let ext = msgExtension { - assert(consumed == false) - try decodeExtensionField(values: &values, - messageType: messageType, - fieldNumber: ext.fieldNumber, - messageExtension: ext) - if !consumed { - return .malformed - } - } else { - // The C++ references ends up appending the blocks together as length - // delimited blocks, but the parsing will only use the first block. - // So just capture a block, and then skip any others that happen to - // be found. - if fieldData == nil { - var d: Data? - try decodeSingularBytesField(value: &d) - guard let data = d else { return .malformed } - // Save it as length delimited - let payloadSize = Varint.encodedSize(of: Int64(data.count)) + data.count - var payload = Data(count: payloadSize) - payload.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - var encoder = BinaryEncoder(forWritingInto: pointer) - encoder.putBytesValue(value: data) - } - } - fieldData = payload - } else { - guard fieldWireFormat == .lengthDelimited else { return .malformed } - try skip() - consumed = true - } - } - - default: - // Skip everything else - try skip() - consumed = true - } - } - - return .success - } - - // - // Private building blocks for the parsing above. - // - // Having these be private gives the compiler maximum latitude for - // inlining. - // - - /// Private: Advance the current position. - private mutating func consume(length: Int) { - available -= length - p += length - } - - /// Private: Skip the body for the given tag. If the given tag is - /// a group, it parses up through the corresponding group end. - private mutating func skipOver(tag: FieldTag) throws { - switch tag.wireFormat { - case .varint: - if available < 1 { - throw BinaryDecodingError.truncated - } - var c = p[0] - while (c & 0x80) != 0 { - p += 1 - available -= 1 - if available < 1 { - throw BinaryDecodingError.truncated - } - c = p[0] - } - p += 1 - available -= 1 - case .fixed64: - if available < 8 { - throw BinaryDecodingError.truncated - } - p += 8 - available -= 8 - case .lengthDelimited: - let n = try decodeVarint() - if n <= UInt64(available) { - p += Int(n) - available -= Int(n) - } else { - throw BinaryDecodingError.truncated - } - case .startGroup: - try incrementRecursionDepth() - while true { - if let innerTag = try getTagWithoutUpdatingFieldStart() { - if innerTag.wireFormat == .endGroup { - if innerTag.fieldNumber == tag.fieldNumber { - decrementRecursionDepth() - break - } else { - // .endGroup for a something other than the current - // group is an invalid binary. - throw BinaryDecodingError.malformedProtobuf - } - } else { - try skipOver(tag: innerTag) - } - } else { - throw BinaryDecodingError.truncated - } - } - case .endGroup: - throw BinaryDecodingError.malformedProtobuf - case .fixed32: - if available < 4 { - throw BinaryDecodingError.truncated - } - p += 4 - available -= 4 - } - } - - /// Private: Skip to the end of the current field. - /// - /// Assumes that fieldStartP was bookmarked by a previous - /// call to getTagType(). - /// - /// On exit, fieldStartP points to the first byte of the tag, fieldEndP points - /// to the first byte after the field contents, and p == fieldEndP. - private mutating func skip() throws { - if let end = fieldEndP { - p = end - } else { - // Rewind to start of current field. - available += p - fieldStartP - p = fieldStartP - guard let tag = try getTagWithoutUpdatingFieldStart() else { - throw BinaryDecodingError.truncated - } - try skipOver(tag: tag) - fieldEndP = p - } - } - - /// Private: Parse the next raw varint from the input. - private mutating func decodeVarint() throws -> UInt64 { - if available < 1 { - throw BinaryDecodingError.truncated - } - var start = p - var length = available - var c = start[0] - start += 1 - length -= 1 - if c & 0x80 == 0 { - p = start - available = length - return UInt64(c) - } - var value = UInt64(c & 0x7f) - var shift = UInt64(7) - while true { - if length < 1 || shift > 63 { - throw BinaryDecodingError.malformedProtobuf - } - c = start[0] - start += 1 - length -= 1 - value |= UInt64(c & 0x7f) << shift - if c & 0x80 == 0 { - p = start - available = length - return value - } - shift += 7 - } - } - - /// Private: Get the tag that starts a new field. - /// This also bookmarks the start of field for a possible skip(). - internal mutating func getTag() throws -> FieldTag? { - fieldStartP = p - fieldEndP = nil - return try getTagWithoutUpdatingFieldStart() - } - - /// Private: Parse and validate the next tag without - /// bookmarking the start of the field. This is used within - /// skip() to skip over fields within a group. - private mutating func getTagWithoutUpdatingFieldStart() throws -> FieldTag? { - if available < 1 { - return nil - } - let t = try decodeVarint() - if t < UInt64(UInt32.max) { - guard let tag = FieldTag(rawValue: UInt32(truncatingIfNeeded: t)) else { - throw BinaryDecodingError.malformedProtobuf - } - fieldWireFormat = tag.wireFormat - fieldNumber = tag.fieldNumber - return tag - } else { - throw BinaryDecodingError.malformedProtobuf - } - } - - /// Private: Return a Data containing the entirety of - /// the current field, including tag. - private mutating func getRawField() throws -> Data { - try skip() - return Data(bytes: fieldStartP, count: fieldEndP! - fieldStartP) - } - - /// Private: decode a fixed-length four-byte number. This generic - /// helper handles all four-byte number types. - private mutating func decodeFourByteNumber(value: inout T) throws { - guard available >= 4 else {throw BinaryDecodingError.truncated} - withUnsafeMutablePointer(to: &value) { ip -> Void in - let dest = UnsafeMutableRawPointer(ip).assumingMemoryBound(to: UInt8.self) - let src = UnsafeRawPointer(p).assumingMemoryBound(to: UInt8.self) - dest.initialize(from: src, count: 4) - } - consume(length: 4) - } - - /// Private: decode a fixed-length eight-byte number. This generic - /// helper handles all eight-byte number types. - private mutating func decodeEightByteNumber(value: inout T) throws { - guard available >= 8 else {throw BinaryDecodingError.truncated} - withUnsafeMutablePointer(to: &value) { ip -> Void in - let dest = UnsafeMutableRawPointer(ip).assumingMemoryBound(to: UInt8.self) - let src = UnsafeRawPointer(p).assumingMemoryBound(to: UInt8.self) - dest.initialize(from: src, count: 8) - } - consume(length: 8) - } - - private mutating func decodeFloat() throws -> Float { - var littleEndianBytes: UInt32 = 0 - try decodeFourByteNumber(value: &littleEndianBytes) - var nativeEndianBytes = UInt32(littleEndian: littleEndianBytes) - var float: Float = 0 - let n = MemoryLayout.size - memcpy(&float, &nativeEndianBytes, n) - return float - } - - private mutating func decodeDouble() throws -> Double { - var littleEndianBytes: UInt64 = 0 - try decodeEightByteNumber(value: &littleEndianBytes) - var nativeEndianBytes = UInt64(littleEndian: littleEndianBytes) - var double: Double = 0 - let n = MemoryLayout.size - memcpy(&double, &nativeEndianBytes, n) - return double - } - - /// Private: Get the start and length for the body of - // a length-delimited field. - private mutating func getFieldBodyBytes(count: inout Int) throws -> UnsafePointer { - let length = try decodeVarint() - if length <= UInt64(available) { - count = Int(length) - let body = p - consume(length: count) - return body - } - throw BinaryDecodingError.truncated - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift deleted file mode 100644 index 6c6d34f..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingError.swift +++ /dev/null @@ -1,44 +0,0 @@ -// Sources/SwiftProtobuf/BinaryDecodingError.swift - Protobuf binary decoding errors -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Protobuf binary format decoding errors -/// -// ----------------------------------------------------------------------------- - -/// Describes errors that can occur when decoding a message from binary format. -public enum BinaryDecodingError: Error { - /// Extraneous data remained after decoding should have been complete. - case trailingGarbage - - /// The decoder unexpectedly reached the end of the data before it was - /// expected. - case truncated - - /// A string field was not encoded as valid UTF-8. - case invalidUTF8 - - /// The binary data was malformed in some way, such as an invalid wire format - /// or field tag. - case malformedProtobuf - - /// The definition of the message or one of its nested messages has required - /// fields but the binary data did not include values for them. You must pass - /// `partial: true` during decoding if you wish to explicitly ignore missing - /// required fields. - case missingRequiredFields - - /// An internal error happened while decoding. If this is ever encountered, - /// please file an issue with SwiftProtobuf with as much details as possible - /// for what happened (proto definitions, bytes being decoded (if possible)). - case internalExtensionError - - /// Reached the nesting limit for messages within messages while decoding. - case messageDepthLimit -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift deleted file mode 100644 index 63eefa8..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDecodingOptions.swift +++ /dev/null @@ -1,39 +0,0 @@ -// Sources/SwiftProtobuf/BinaryDecodingOptions.swift - Binary decoding options -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Binary decoding options -/// -// ----------------------------------------------------------------------------- - -/// Options for JSONDecoding. -public struct BinaryDecodingOptions { - /// The maximum nesting of message with messages. The default is 100. - /// - /// To prevent corrupt or malicious messages from causing stack overflows, - /// this controls how deep messages can be nested within other messages - /// while parsing. - public var messageDepthLimit: Int = 100 - - /// Discard unknown fields while parsing. The default is false, so parsering - /// does not discard unknown fields. - /// - /// The Protobuf binary format allows unknown fields to be still parsed - /// so the schema can be expanded without requiring all readers to be updated. - /// This works in part by haivng any unknown fields preserved so they can - /// be relayed on without loss. For a while the proto3 syntax definition - /// called for unknown fields to be dropped, but that lead to problems in - /// some case. The default is to follow the spec and keep them, but setting - /// this option to `true` allows a developer to strip them during a parse - /// in case they have a specific need to drop the unknown fields from the - /// object graph being created. - public var discardUnknownFields: Bool = false - - public init() {} -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift deleted file mode 100644 index 25420a6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryDelimited.swift +++ /dev/null @@ -1,227 +0,0 @@ -// Sources/SwiftProtobuf/BinaryDelimited.swift - Delimited support -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Helpers to read/write message with a length prefix. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Helper methods for reading/writing messages with a length prefix. -public enum BinaryDelimited { - /// Additional errors for delimited message handing. - public enum Error: Swift.Error { - /// If a read/write to the stream fails, but the stream's `streamError` is nil, - /// this error will be throw instead since the stream didn't provide anything - /// more specific. A common cause for this can be failing to open the stream - /// before trying to read/write to it. - case unknownStreamError - - /// While reading/writing to the stream, less than the expected bytes was - /// read/written. - case truncated - } - - /// Serialize a single size-delimited message from the given stream. Delimited - /// format allows a single file or stream to contain multiple messages, - /// whereas normally writing multiple non-delimited messages to the same - /// stream would cause them to be merged. A delimited message is a varint - /// encoding the message size followed by a message of exactly that size. - /// - /// - Parameters: - /// - message: The message to be written. - /// - to: The `OutputStream` to write the message to. The stream is - /// is assumed to be ready to be written to. - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - Throws: `BinaryEncodingError` if encoding fails, throws - /// `BinaryDelimited.Error` for some writing errors, or the - /// underlying `OutputStream.streamError` for a stream error. - public static func serialize( - message: Message, - to stream: OutputStream, - partial: Bool = false - ) throws { - // TODO: Revisit to avoid the extra buffering when encoding is streamed in general. - let serialized = try message.serializedData(partial: partial) - let totalSize = Varint.encodedSize(of: UInt64(serialized.count)) + serialized.count - var data = Data(count: totalSize) - data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - var encoder = BinaryEncoder(forWritingInto: pointer) - encoder.putBytesValue(value: serialized) - } - } - - var written: Int = 0 - data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - written = stream.write(pointer, maxLength: totalSize) - } - } - - if written != totalSize { - if written == -1 { - if let streamError = stream.streamError { - throw streamError - } - throw BinaryDelimited.Error.unknownStreamError - } - throw BinaryDelimited.Error.truncated - } - } - - /// Reads a single size-delimited message from the given stream. Delimited - /// format allows a single file or stream to contain multiple messages, - /// whereas normally parsing consumes the entire input. A delimited message - /// is a varint encoding the message size followed by a message of exactly - /// exactly that size. - /// - /// - Parameters: - /// - messageType: The type of message to read. - /// - from: The `InputStream` to read the data from. The stream is assumed - /// to be ready to read from. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - options: The BinaryDecodingOptions to use. - /// - Returns: The message read. - /// - Throws: `BinaryDecodingError` if decoding fails, throws - /// `BinaryDelimited.Error` for some reading errors, and the - /// underlying InputStream.streamError for a stream error. - public static func parse( - messageType: M.Type, - from stream: InputStream, - extensions: ExtensionMap? = nil, - partial: Bool = false, - options: BinaryDecodingOptions = BinaryDecodingOptions() - ) throws -> M { - var message = M() - try merge(into: &message, - from: stream, - extensions: extensions, - partial: partial, - options: options) - return message - } - - /// Updates the message by reading a single size-delimited message from - /// the given stream. Delimited format allows a single file or stream to - /// contain multiple messages, whereas normally parsing consumes the entire - /// input. A delimited message is a varint encoding the message size - /// followed by a message of exactly that size. - /// - /// - Note: If this method throws an error, the message may still have been - /// partially mutated by the binary data that was decoded before the error - /// occurred. - /// - /// - Parameters: - /// - mergingTo: The message to merge the data into. - /// - from: The `InputStream` to read the data from. The stream is assumed - /// to be ready to read from. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - options: The BinaryDecodingOptions to use. - /// - Throws: `BinaryDecodingError` if decoding fails, throws - /// `BinaryDelimited.Error` for some reading errors, and the - /// underlying InputStream.streamError for a stream error. - public static func merge( - into message: inout M, - from stream: InputStream, - extensions: ExtensionMap? = nil, - partial: Bool = false, - options: BinaryDecodingOptions = BinaryDecodingOptions() - ) throws { - let length = try Int(decodeVarint(stream)) - if length == 0 { - // The message was all defaults, nothing to actually read. - return - } - - var data = Data(count: length) - var bytesRead: Int = 0 - data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - bytesRead = stream.read(pointer, maxLength: length) - } - } - - if bytesRead != length { - if bytesRead == -1 { - if let streamError = stream.streamError { - throw streamError - } - throw BinaryDelimited.Error.unknownStreamError - } - throw BinaryDelimited.Error.truncated - } - - try message.merge(serializedData: data, - extensions: extensions, - partial: partial, - options: options) - } -} - -// TODO: This should go away when encoding/decoding are more stream based -// as that should provide a more direct way to do this. This is basically -// a rewrite of BinaryDecoder.decodeVarint(). -internal func decodeVarint(_ stream: InputStream) throws -> UInt64 { - - // Buffer to reuse within nextByte. - var readBuffer = UnsafeMutablePointer.allocate(capacity: 1) - #if swift(>=4.1) - defer { readBuffer.deallocate() } - #else - defer { readBuffer.deallocate(capacity: 1) } - #endif - - func nextByte() throws -> UInt8 { - let bytesRead = stream.read(readBuffer, maxLength: 1) - if bytesRead != 1 { - if bytesRead == -1 { - if let streamError = stream.streamError { - throw streamError - } - throw BinaryDelimited.Error.unknownStreamError - } - throw BinaryDelimited.Error.truncated - } - return readBuffer[0] - } - - var value: UInt64 = 0 - var shift: UInt64 = 0 - while true { - let c = try nextByte() - value |= UInt64(c & 0x7f) << shift - if c & 0x80 == 0 { - return value - } - shift += 7 - if shift > 63 { - throw BinaryDecodingError.malformedProtobuf - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift deleted file mode 100644 index b3c73f1..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncoder.swift +++ /dev/null @@ -1,135 +0,0 @@ -// Sources/SwiftProtobuf/BinaryEncoder.swift - Binary encoding support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Core support for protobuf binary encoding. Note that this is built -/// on the general traversal machinery. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/* - * Encoder for Binary Protocol Buffer format - */ -internal struct BinaryEncoder { - private var pointer: UnsafeMutablePointer - - init(forWritingInto pointer: UnsafeMutablePointer) { - self.pointer = pointer - } - - private mutating func append(_ byte: UInt8) { - pointer.pointee = byte - pointer = pointer.successor() - } - - private mutating func append(contentsOf data: Data) { - let count = data.count - data.copyBytes(to: pointer, count: count) - pointer = pointer.advanced(by: count) - } - - private mutating func append(contentsOf bufferPointer: UnsafeBufferPointer) { - let count = bufferPointer.count - pointer.assign(from: bufferPointer.baseAddress!, count: count) - pointer = pointer.advanced(by: count) - } - - func distance(pointer: UnsafeMutablePointer) -> Int { - return pointer.distance(to: self.pointer) - } - - mutating func appendUnknown(data: Data) { - append(contentsOf: data) - } - - mutating func startField(fieldNumber: Int, wireFormat: WireFormat) { - startField(tag: FieldTag(fieldNumber: fieldNumber, wireFormat: wireFormat)) - } - - mutating func startField(tag: FieldTag) { - putVarInt(value: UInt64(tag.rawValue)) - } - - mutating func putVarInt(value: UInt64) { - var v = value - while v > 127 { - append(UInt8(v & 0x7f | 0x80)) - v >>= 7 - } - append(UInt8(v)) - } - - mutating func putVarInt(value: Int64) { - putVarInt(value: UInt64(bitPattern: value)) - } - - mutating func putVarInt(value: Int) { - putVarInt(value: Int64(value)) - } - - mutating func putZigZagVarInt(value: Int64) { - let coded = ZigZag.encoded(value) - putVarInt(value: coded) - } - - mutating func putBoolValue(value: Bool) { - append(value ? 1 : 0) - } - - mutating func putFixedUInt64(value: UInt64) { - var v = value.littleEndian - let n = MemoryLayout.size - memcpy(pointer, &v, n) - pointer = pointer.advanced(by: n) - } - - mutating func putFixedUInt32(value: UInt32) { - var v = value.littleEndian - let n = MemoryLayout.size - memcpy(pointer, &v, n) - pointer = pointer.advanced(by: n) - } - - mutating func putFloatValue(value: Float) { - let n = MemoryLayout.size - var v = value - var nativeBytes: UInt32 = 0 - memcpy(&nativeBytes, &v, n) - var littleEndianBytes = nativeBytes.littleEndian - memcpy(pointer, &littleEndianBytes, n) - pointer = pointer.advanced(by: n) - } - - mutating func putDoubleValue(value: Double) { - let n = MemoryLayout.size - var v = value - var nativeBytes: UInt64 = 0 - memcpy(&nativeBytes, &v, n) - var littleEndianBytes = nativeBytes.littleEndian - memcpy(pointer, &littleEndianBytes, n) - pointer = pointer.advanced(by: n) - } - - // Write a string field, including the leading index/tag value. - mutating func putStringValue(value: String) { - let count = value.utf8.count - putVarInt(value: count) - for b in value.utf8 { - pointer.pointee = b - pointer = pointer.successor() - } - } - - mutating func putBytesValue(value: Data) { - putVarInt(value: value.count) - append(contentsOf: value) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift deleted file mode 100644 index 584d823..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingError.swift +++ /dev/null @@ -1,27 +0,0 @@ -// Sources/SwiftProtobuf/BinaryEncodingError.swift - Error constants -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Enum constants that identify the particular error. -/// -// ----------------------------------------------------------------------------- - -/// Describes errors that can occur when decoding a message from binary format. -public enum BinaryEncodingError: Error { - /// `Any` fields that were decoded from JSON cannot be re-encoded to binary - /// unless the object they hold is a well-known type or a type registered via - /// `Google_Protobuf_Any.register()`. - case anyTranscodeFailure - - /// The definition of the message or one of its nested messages has required - /// fields but the message being encoded did not include values for them. You - /// must pass `partial: true` during encoding if you wish to explicitly ignore - /// missing required fields. - case missingRequiredFields -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift deleted file mode 100644 index ba5af7b..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift +++ /dev/null @@ -1,369 +0,0 @@ -// Sources/SwiftProtobuf/BinaryEncodingSizeVisitor.swift - Binary size calculation support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Visitor used during binary encoding that precalcuates the size of a -/// serialized message. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Visitor that calculates the binary-encoded size of a message so that a -/// properly sized `Data` or `UInt8` array can be pre-allocated before -/// serialization. -internal struct BinaryEncodingSizeVisitor: Visitor { - - /// Accumulates the required size of the message during traversal. - var serializedSize: Int = 0 - - init() {} - - mutating func visitUnknown(bytes: Data) throws { - serializedSize += bytes.count - } - - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt64Field(value: Int64(value), fieldNumber: fieldNumber) - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize - serializedSize += tagSize + Varint.encodedSize(of: value) - } - - mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: UInt64(value), fieldNumber: fieldNumber) - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize - serializedSize += tagSize + Varint.encodedSize(of: value) - } - - mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize - serializedSize += tagSize + Varint.encodedSize(of: ZigZag.encoded(value)) - } - - mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize - serializedSize += tagSize + Varint.encodedSize(of: ZigZag.encoded(value)) - } - - mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed32).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .fixed64).encodedSize - serializedSize += tagSize + MemoryLayout.size - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .varint).encodedSize - serializedSize += tagSize + 1 - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let count = value.utf8.count - serializedSize += tagSize + Varint.encodedSize(of: Int64(count)) + count - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let count = value.count - serializedSize += tagSize + Varint.encodedSize(of: Int64(count)) + count - } - - mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: v) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: v) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: ZigZag.encoded(v)) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: ZigZag.encoded(v)) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: v) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: v) - } - serializedSize += - tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count * MemoryLayout.size - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, wireFormat: .lengthDelimited).encodedSize - let dataSize = value.count - serializedSize += tagSize + Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitSingularEnumField(value: E, - fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .varint).encodedSize - serializedSize += tagSize - let dataSize = Varint.encodedSize(of: Int32(truncatingIfNeeded: value.rawValue)) - serializedSize += dataSize - } - - mutating func visitRepeatedEnumField(value: [E], - fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .varint).encodedSize - serializedSize += value.count * tagSize - for v in value { - let dataSize = Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) - serializedSize += dataSize - } - } - - mutating func visitPackedEnumField(value: [E], - fieldNumber: Int) throws { - guard !value.isEmpty else { - return - } - - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .varint).encodedSize - serializedSize += tagSize - var dataSize = 0 - for v in value { - dataSize += Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) - } - serializedSize += Varint.encodedSize(of: Int64(dataSize)) + dataSize - } - - mutating func visitSingularMessageField(value: M, - fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .lengthDelimited).encodedSize - let messageSize = try value.serializedDataSize() - serializedSize += - tagSize + Varint.encodedSize(of: UInt64(messageSize)) + messageSize - } - - mutating func visitRepeatedMessageField(value: [M], - fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .lengthDelimited).encodedSize - serializedSize += value.count * tagSize - for v in value { - let messageSize = try v.serializedDataSize() - serializedSize += - Varint.encodedSize(of: UInt64(messageSize)) + messageSize - } - } - - mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { - // The wire format doesn't matter here because the encoded size of the - // integer won't change based on the low three bits. - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .startGroup).encodedSize - serializedSize += 2 * tagSize - try value.traverse(visitor: &self) - } - - mutating func visitRepeatedGroupField(value: [G], - fieldNumber: Int) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .startGroup).encodedSize - serializedSize += 2 * value.count * tagSize - for v in value { - try v.traverse(visitor: &self) - } - } - - mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int - ) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .lengthDelimited).encodedSize - for (k,v) in value { - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try ValueType.visitSingular(value: v, fieldNumber: 2, with: &sizer) - let entrySize = sizer.serializedSize - serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize - } - serializedSize += value.count * tagSize - } - - mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int - ) throws where ValueType.RawValue == Int { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .lengthDelimited).encodedSize - for (k,v) in value { - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try sizer.visitSingularEnumField(value: v, fieldNumber: 2) - let entrySize = sizer.serializedSize - serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize - } - serializedSize += value.count * tagSize - } - - mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int - ) throws { - let tagSize = FieldTag(fieldNumber: fieldNumber, - wireFormat: .lengthDelimited).encodedSize - for (k,v) in value { - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try sizer.visitSingularMessageField(value: v, fieldNumber: 2) - let entrySize = sizer.serializedSize - serializedSize += Varint.encodedSize(of: Int64(entrySize)) + entrySize - } - serializedSize += value.count * tagSize - } - - mutating func visitExtensionFieldsAsMessageSet( - fields: ExtensionFieldValueSet, - start: Int, - end: Int - ) throws { - var sizer = BinaryEncodingMessageSetSizeVisitor() - try fields.traverse(visitor: &sizer, start: start, end: end) - serializedSize += sizer.serializedSize - } -} - -extension BinaryEncodingSizeVisitor { - - // Helper Visitor to compute the sizes when writing out the extensions as MessageSets. - internal struct BinaryEncodingMessageSetSizeVisitor: SelectiveVisitor { - var serializedSize: Int = 0 - - init() {} - - mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { - var groupSize = WireFormat.MessageSet.itemTagsEncodedSize - - groupSize += Varint.encodedSize(of: Int32(fieldNumber)) - - let messageSize = try value.serializedDataSize() - groupSize += Varint.encodedSize(of: UInt64(messageSize)) + messageSize - - serializedSize += groupSize - } - - // SelectiveVisitor handles the rest. - } - -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift deleted file mode 100644 index 16c68c7..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/BinaryEncodingVisitor.swift +++ /dev/null @@ -1,360 +0,0 @@ -// Sources/SwiftProtobuf/BinaryEncodingVisitor.swift - Binary encoding support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Core support for protobuf binary encoding. Note that this is built -/// on the general traversal machinery. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Visitor that encodes a message graph in the protobuf binary wire format. -internal struct BinaryEncodingVisitor: Visitor { - - var encoder: BinaryEncoder - - /// Creates a new visitor that writes the binary-coded message into the memory - /// at the given pointer. - /// - /// - Precondition: `pointer` must point to an allocated block of memory that - /// is large enough to hold the entire encoded message. For performance - /// reasons, the encoder does not make any attempts to verify this. - init(forWritingInto pointer: UnsafeMutablePointer) { - encoder = BinaryEncoder(forWritingInto: pointer) - } - - init(encoder: BinaryEncoder) { - self.encoder = encoder - } - - mutating func visitUnknown(bytes: Data) throws { - encoder.appendUnknown(data: bytes) - } - - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed32) - encoder.putFloatValue(value: value) - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed64) - encoder.putDoubleValue(value: value) - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: UInt64(bitPattern: value), fieldNumber: fieldNumber) - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .varint) - encoder.putVarInt(value: value) - } - - mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularSInt64Field(value: Int64(value), fieldNumber: fieldNumber) - } - - mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: ZigZag.encoded(value), fieldNumber: fieldNumber) - } - - mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed32) - encoder.putFixedUInt32(value: value) - } - - mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .fixed64) - encoder.putFixedUInt64(value: value) - } - - mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularFixed32Field(value: UInt32(bitPattern: value), fieldNumber: fieldNumber) - } - - mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularFixed64Field(value: UInt64(bitPattern: value), fieldNumber: fieldNumber) - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: value ? 1 : 0, fieldNumber: fieldNumber) - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putStringValue(value: value) - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putBytesValue(value: value) - } - - mutating func visitSingularEnumField(value: E, - fieldNumber: Int) throws { - try visitSingularUInt64Field(value: UInt64(bitPattern: Int64(value.rawValue)), - fieldNumber: fieldNumber) - } - - mutating func visitSingularMessageField(value: M, - fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - let length = try value.serializedDataSize() - encoder.putVarInt(value: length) - try value.traverse(visitor: &self) - } - - mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .startGroup) - try value.traverse(visitor: &self) - encoder.startField(fieldNumber: fieldNumber, wireFormat: .endGroup) - } - - // Repeated fields are handled by the default implementations in Visitor.swift - - - // Packed Fields - - mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putFloatValue(value: v) - } - } - - mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putDoubleValue(value: v) - } - } - - mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: v) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putVarInt(value: Int64(v)) - } - } - - mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: v) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putVarInt(value: v) - } - } - - mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: ZigZag.encoded(v)) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putZigZagVarInt(value: Int64(v)) - } - } - - mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: ZigZag.encoded(v)) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putZigZagVarInt(value: v) - } - } - - mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: v) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putVarInt(value: UInt64(v)) - } - } - - mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: v) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putVarInt(value: v) - } - } - - mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putFixedUInt32(value: v) - } - } - - mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putFixedUInt64(value: v) - } - } - - mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putFixedUInt32(value: UInt32(bitPattern: v)) - } - } - - mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count * MemoryLayout.size) - for v in value { - encoder.putFixedUInt64(value: UInt64(bitPattern: v)) - } - } - - mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - encoder.putVarInt(value: value.count) - for v in value { - encoder.putVarInt(value: v ? 1 : 0) - } - } - - mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var packedSize = 0 - for v in value { - packedSize += Varint.encodedSize(of: Int32(truncatingIfNeeded: v.rawValue)) - } - encoder.putVarInt(value: packedSize) - for v in value { - encoder.putVarInt(value: v.rawValue) - } - } - - mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int - ) throws { - for (k,v) in value { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try ValueType.visitSingular(value: v, fieldNumber: 2, with: &sizer) - let entrySize = sizer.serializedSize - encoder.putVarInt(value: entrySize) - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) - try ValueType.visitSingular(value: v, fieldNumber: 2, with: &self) - } - } - - mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int - ) throws where ValueType.RawValue == Int { - for (k,v) in value { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try sizer.visitSingularEnumField(value: v, fieldNumber: 2) - let entrySize = sizer.serializedSize - encoder.putVarInt(value: entrySize) - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) - try visitSingularEnumField(value: v, fieldNumber: 2) - } - } - - mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int - ) throws { - for (k,v) in value { - encoder.startField(fieldNumber: fieldNumber, wireFormat: .lengthDelimited) - var sizer = BinaryEncodingSizeVisitor() - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &sizer) - try sizer.visitSingularMessageField(value: v, fieldNumber: 2) - let entrySize = sizer.serializedSize - encoder.putVarInt(value: entrySize) - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &self) - try visitSingularMessageField(value: v, fieldNumber: 2) - } - } - - mutating func visitExtensionFieldsAsMessageSet( - fields: ExtensionFieldValueSet, - start: Int, - end: Int - ) throws { - var subVisitor = BinaryEncodingMessageSetVisitor(encoder: encoder) - try fields.traverse(visitor: &subVisitor, start: start, end: end) - encoder = subVisitor.encoder - } -} - -extension BinaryEncodingVisitor { - - // Helper Visitor to when writing out the extensions as MessageSets. - internal struct BinaryEncodingMessageSetVisitor: SelectiveVisitor { - var encoder: BinaryEncoder - - init(encoder: BinaryEncoder) { - self.encoder = encoder - } - - mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { - encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.itemStart.rawValue)) - - encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.typeId.rawValue)) - encoder.putVarInt(value: fieldNumber) - - encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.message.rawValue)) - - // Use a normal BinaryEncodingVisitor so any message fields end up in the - // normal wire format (instead of MessageSet format). - let length = try value.serializedDataSize() - encoder.putVarInt(value: length) - // Create the sub encoder after writing the length. - var subVisitor = BinaryEncodingVisitor(encoder: encoder) - try value.traverse(visitor: &subVisitor) - encoder = subVisitor.encoder - - encoder.putVarInt(value: Int64(WireFormat.MessageSet.Tags.itemEnd.rawValue)) - } - - // SelectiveVisitor handles the rest. - } - -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift deleted file mode 100644 index 64689cb..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift +++ /dev/null @@ -1,36 +0,0 @@ -// Sources/SwiftProtobuf/CustomJSONCodable.swift - Custom JSON support for WKTs -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Custom protocol for the WKTs to support their custom JSON encodings. -/// -// ----------------------------------------------------------------------------- - -/// Allows WKTs to provide their custom JSON encodings. -internal protocol _CustomJSONCodable { - func encodedJSONString(options: JSONEncodingOptions) throws -> String - mutating func decodeJSON(from: inout JSONDecoder) throws - - /// Called when the JSON `null` literal is encountered in a position where - /// a message of the conforming type is expected. The message type can then - /// handle the `null` value differently, if needed; for example, - /// `Google_Protobuf_Value` returns a special instance whose `kind` is set to - /// `.nullValue(.nullValue)`. - /// - /// The default behavior is to return `nil`, which indicates that `null` - /// should be treated as the absence of a message. - static func decodedFromJSONNull() throws -> Self? -} - -extension _CustomJSONCodable { - internal static func decodedFromJSONNull() -> Self? { - // Return nil by default. Concrete types can provide custom logic. - return nil - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift deleted file mode 100644 index 5b4e9a8..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Data+Extensions.swift +++ /dev/null @@ -1,33 +0,0 @@ -// Sources/SwiftProtobuf/Data+Extensions.swift - Extension exposing new Data API -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extension exposing new Data API to Swift versions < 5.0. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -#if !swift(>=5.0) -internal extension Data { - func withUnsafeBytes(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T { - let c = count - return try withUnsafeBytes { (p: UnsafePointer) throws -> T in - try body(UnsafeRawBufferPointer(start: p, count: c)) - } - } - - mutating func withUnsafeMutableBytes(_ body: (UnsafeMutableRawBufferPointer) throws -> T) rethrows -> T { - let c = count - return try withUnsafeMutableBytes { (p: UnsafeMutablePointer) throws -> T in - try body(UnsafeMutableRawBufferPointer(start: p, count: c)) - } - } -} -#endif diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift deleted file mode 100644 index 01a8ed8..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Decoder.swift +++ /dev/null @@ -1,150 +0,0 @@ -// Sources/SwiftProtobuf/Decoder.swift - Basic field setting -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// In this way, the generated code only knows about schema -/// information; the decoder logic knows how to decode particular -/// wire types based on that information. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// This is the abstract protocol used by the generated code -/// to deserialize data. -/// -/// The generated code looks roughly like this: -/// -/// ``` -/// while fieldNumber = try decoder.nextFieldNumber() { -/// switch fieldNumber { -/// case 1: decoder.decodeRepeatedInt32Field(value: &_field) -/// ... etc ... -/// } -/// ``` -/// -/// For performance, this is mostly broken out into a separate method -/// for singular/repeated fields of every supported type. Note that -/// we don't distinguish "packed" here, since all existing decoders -/// treat "packed" the same as "repeated" at this level. (That is, -/// even when the serializer distinguishes packed and non-packed -/// forms, the deserializer always accepts both.) -/// -/// Generics come into play at only a few points: `Enum`s and `Message`s -/// use a generic type to locate the correct initializer. Maps and -/// extensions use generics to avoid the method explosion of having to -/// support a separate method for every map and extension type. Maps -/// do distinguish `Enum`-valued and `Message`-valued maps to avoid -/// polluting the generated `Enum` and `Message` types with all of the -/// necessary generic methods to support this. -public protocol Decoder { - /// Called by a `oneof` when it already has a value and is being asked to - /// accept a new value. Some formats require `oneof` decoding to fail in this - /// case. - mutating func handleConflictingOneOf() throws - - /// Returns the next field number, or nil when the end of the input is - /// reached. - /// - /// For JSON and text format, the decoder translates the field name to a - /// number at this point, based on information it obtained from the message - /// when it was initialized. - mutating func nextFieldNumber() throws -> Int? - - // Primitive field decoders - mutating func decodeSingularFloatField(value: inout Float) throws - mutating func decodeSingularFloatField(value: inout Float?) throws - mutating func decodeRepeatedFloatField(value: inout [Float]) throws - mutating func decodeSingularDoubleField(value: inout Double) throws - mutating func decodeSingularDoubleField(value: inout Double?) throws - mutating func decodeRepeatedDoubleField(value: inout [Double]) throws - mutating func decodeSingularInt32Field(value: inout Int32) throws - mutating func decodeSingularInt32Field(value: inout Int32?) throws - mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws - mutating func decodeSingularInt64Field(value: inout Int64) throws - mutating func decodeSingularInt64Field(value: inout Int64?) throws - mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws - mutating func decodeSingularUInt32Field(value: inout UInt32) throws - mutating func decodeSingularUInt32Field(value: inout UInt32?) throws - mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws - mutating func decodeSingularUInt64Field(value: inout UInt64) throws - mutating func decodeSingularUInt64Field(value: inout UInt64?) throws - mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws - mutating func decodeSingularSInt32Field(value: inout Int32) throws - mutating func decodeSingularSInt32Field(value: inout Int32?) throws - mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws - mutating func decodeSingularSInt64Field(value: inout Int64) throws - mutating func decodeSingularSInt64Field(value: inout Int64?) throws - mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws - mutating func decodeSingularFixed32Field(value: inout UInt32) throws - mutating func decodeSingularFixed32Field(value: inout UInt32?) throws - mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws - mutating func decodeSingularFixed64Field(value: inout UInt64) throws - mutating func decodeSingularFixed64Field(value: inout UInt64?) throws - mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws - mutating func decodeSingularSFixed32Field(value: inout Int32) throws - mutating func decodeSingularSFixed32Field(value: inout Int32?) throws - mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws - mutating func decodeSingularSFixed64Field(value: inout Int64) throws - mutating func decodeSingularSFixed64Field(value: inout Int64?) throws - mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws - mutating func decodeSingularBoolField(value: inout Bool) throws - mutating func decodeSingularBoolField(value: inout Bool?) throws - mutating func decodeRepeatedBoolField(value: inout [Bool]) throws - mutating func decodeSingularStringField(value: inout String) throws - mutating func decodeSingularStringField(value: inout String?) throws - mutating func decodeRepeatedStringField(value: inout [String]) throws - mutating func decodeSingularBytesField(value: inout Data) throws - mutating func decodeSingularBytesField(value: inout Data?) throws - mutating func decodeRepeatedBytesField(value: inout [Data]) throws - - // Decode Enum fields - mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int - mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int - mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int - - // Decode Message fields - mutating func decodeSingularMessageField(value: inout M?) throws - mutating func decodeRepeatedMessageField(value: inout [M]) throws - - // Decode Group fields - mutating func decodeSingularGroupField(value: inout G?) throws - mutating func decodeRepeatedGroupField(value: inout [G]) throws - - // Decode Map fields. - // This is broken into separate methods depending on whether the value - // type is primitive (_ProtobufMap), enum (_ProtobufEnumMap), or message - // (_ProtobufMessageMap) - mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws - mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int - mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws - - // Decode extension fields - mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws - - // Run a decode loop decoding the MessageSet format for Extensions. - mutating func decodeExtensionFieldsAsMessageSet(values: inout ExtensionFieldValueSet, - messageType: Message.Type) throws -} - -/// Most Decoders won't care about Extension handing as in MessageSet -/// format, so provide a default implementation simply looping on the -/// fieldNumbers and feeding through to extension decoding. -extension Decoder { - public mutating func decodeExtensionFieldsAsMessageSet( - values: inout ExtensionFieldValueSet, - messageType: Message.Type - ) throws { - while let fieldNumber = try self.nextFieldNumber() { - try self.decodeExtensionField(values: &values, - messageType: messageType, - fieldNumber: fieldNumber) - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift deleted file mode 100644 index 5268aef..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/DoubleParser.swift +++ /dev/null @@ -1,68 +0,0 @@ -// Sources/SwiftProtobuf/DoubleParser.swift - Generally useful mathematical functions -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Numeric parsing helper for float and double strings -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Support parsing float/double values from UTF-8 -internal class DoubleParser { - // Temporary buffer so we can null-terminate the UTF-8 string - // before calling the C standard libray to parse it. - // In theory, JSON writers should be able to represent any IEEE Double - // in at most 25 bytes, but many writers will emit more digits than - // necessary, so we size this generously. - #if swift(>=4.1) - private var work = - UnsafeMutableRawBufferPointer.allocate(byteCount: 128, - alignment: MemoryLayout.alignment) - #else - private var work = UnsafeMutableRawBufferPointer.allocate(count: 128) - #endif - - deinit { - work.deallocate() - } - - func utf8ToDouble(bytes: UnsafeBufferPointer, - start: UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index) -> Double? { - return utf8ToDouble(bytes: bytes.baseAddress! + start, count: end - start) - } - - func utf8ToDouble(bytes: UnsafePointer, count: Int) -> Double? { - // Reject unreasonably long or short UTF8 number - if work.count <= count || count < 1 { - return nil - } - // Copy it to the work buffer and null-terminate it - let source = UnsafeRawBufferPointer(start: bytes, count: count) - #if swift(>=4.1) - work.copyMemory(from:source) - #else - work.copyBytes(from:source) - #endif - work[count] = 0 - - // Use C library strtod() to parse it - let start = work.baseAddress!.assumingMemoryBound(to: Int8.self) - var e: UnsafeMutablePointer? = start - let d = strtod(start, &e) - - // Fail if strtod() did not consume everything we expected - // or if strtod() thought the number was out of range. - if e != start + count || !d.isFinite { - return nil - } - return d - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift deleted file mode 100644 index 850d3d6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Enum.swift +++ /dev/null @@ -1,93 +0,0 @@ -// Sources/SwiftProtobuf/Enum.swift - Enum support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Generated enums conform to SwiftProtobuf.Enum -/// -/// See ProtobufTypes and JSONTypes for extension -/// methods to support binary and JSON coding. -/// -// ----------------------------------------------------------------------------- - -/// Generated enum types conform to this protocol. -public protocol Enum: RawRepresentable, Hashable { - /// Creates a new instance of the enum initialized to its default value. - init() - - /// Creates a new instance of the enum from the given raw integer value. - /// - /// For proto2 enums, this initializer will fail if the raw value does not - /// correspond to a valid enum value. For proto3 enums, this initializer never - /// fails; unknown values are created as instances of the `UNRECOGNIZED` case. - /// - /// - Parameter rawValue: The raw integer value from which to create the enum - /// value. - init?(rawValue: Int) - - /// The raw integer value of the enum value. - /// - /// For a recognized enum case, this is the integer value of the case as - /// defined in the .proto file. For `UNRECOGNIZED` cases in proto3, this is - /// the value that was originally decoded. - var rawValue: Int { get } -} - -extension Enum { -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(rawValue) - } -#else // swift(>=4.2) - public var hashValue: Int { - return rawValue - } -#endif // swift(>=4.2) - - /// Internal convenience property representing the name of the enum value (or - /// `nil` if it is an `UNRECOGNIZED` value or doesn't provide names). - /// - /// Since the text format and JSON names are always identical, we don't need - /// to distinguish them. - internal var name: _NameMap.Name? { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type else { - return nil - } - return nameProviding._protobuf_nameMap.names(for: rawValue)?.proto - } - - /// Internal convenience initializer that returns the enum value with the - /// given name, if it provides names. - /// - /// Since the text format and JSON names are always identical, we don't need - /// to distinguish them. - /// - /// - Parameter name: The name of the enum case. - internal init?(name: String) { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type, - let number = nameProviding._protobuf_nameMap.number(forJSONName: name) else { - return nil - } - self.init(rawValue: number) - } - - /// Internal convenience initializer that returns the enum value with the - /// given name, if it provides names. - /// - /// Since the text format and JSON names are always identical, we don't need - /// to distinguish them. - /// - /// - Parameter name: Buffer holding the UTF-8 bytes of the desired name. - internal init?(rawUTF8: UnsafeBufferPointer) { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type, - let number = nameProviding._protobuf_nameMap.number(forJSONName: rawUTF8) else { - return nil - } - self.init(rawValue: number) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift deleted file mode 100644 index 73036e5..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensibleMessage.swift +++ /dev/null @@ -1,39 +0,0 @@ -// Sources/SwiftProtobuf/ExtensibleMessage.swift - Extension support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Additional capabilities needed by messages that allow extensions. -/// -// ----------------------------------------------------------------------------- - -// Messages that support extensions implement this protocol -public protocol ExtensibleMessage: Message { - var _protobuf_extensionFieldValues: ExtensionFieldValueSet { get set } -} - -extension ExtensibleMessage { - public mutating func setExtensionValue(ext: MessageExtension, value: F.ValueType) { - _protobuf_extensionFieldValues[ext.fieldNumber] = F(protobufExtension: ext, value: value) - } - - public func getExtensionValue(ext: MessageExtension) -> F.ValueType? { - if let fieldValue = _protobuf_extensionFieldValues[ext.fieldNumber] as? F { - return fieldValue.value - } - return nil - } - - public func hasExtensionValue(ext: MessageExtension) -> Bool { - return _protobuf_extensionFieldValues[ext.fieldNumber] is F - } - - public mutating func clearExtensionValue(ext: MessageExtension) { - _protobuf_extensionFieldValues[ext.fieldNumber] = nil - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift deleted file mode 100644 index 66343d6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift +++ /dev/null @@ -1,89 +0,0 @@ -// Sources/SwiftProtobuf/ExtensionFieldValueSet.swift - Extension support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A collection of extension field values on a particular object. -/// This is only used within messages to manage the values of extension fields; -/// it does not need to be very sophisticated. -/// -// ----------------------------------------------------------------------------- - -public struct ExtensionFieldValueSet: Hashable { - fileprivate var values = [Int : AnyExtensionField]() - - public static func ==(lhs: ExtensionFieldValueSet, - rhs: ExtensionFieldValueSet) -> Bool { - guard lhs.values.count == rhs.values.count else { - return false - } - for (index, l) in lhs.values { - if let r = rhs.values[index] { - if type(of: l) != type(of: r) { - return false - } - if !l.isEqual(other: r) { - return false - } - } else { - return false - } - } - return true - } - - public init() {} - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - // AnyExtensionField is not Hashable, and the Self constraint that would - // add breaks some of the uses of it; so the only choice is to manually - // mix things in. However, one must remember to do things in an order - // independent manner. - var hash = 16777619 - for (fieldNumber, v) in values { - var localHasher = hasher - localHasher.combine(fieldNumber) - v.hash(into: &localHasher) - hash = hash &+ localHasher.finalize() - } - hasher.combine(hash) - } -#else // swift(>=4.2) - public var hashValue: Int { - var hash = 16777619 - for (fieldNumber, v) in values { - // Note: This calculation cannot depend on the order of the items. - hash = hash &+ fieldNumber &+ v.hashValue - } - return hash - } -#endif // swift(>=4.2) - - public func traverse(visitor: inout V, start: Int, end: Int) throws { - let validIndexes = values.keys.filter {$0 >= start && $0 < end} - for i in validIndexes.sorted() { - let value = values[i]! - try value.traverse(visitor: &visitor) - } - } - - public subscript(index: Int) -> AnyExtensionField? { - get { return values[index] } - set { values[index] = newValue } - } - - public var isInitialized: Bool { - for (_, v) in values { - if !v.isInitialized { - return false - } - } - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift deleted file mode 100644 index 880f3a2..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionFields.swift +++ /dev/null @@ -1,708 +0,0 @@ -// Sources/SwiftProtobuf/ExtensionFields.swift - Extension support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Core protocols implemented by generated extensions. -/// -// ----------------------------------------------------------------------------- - -#if !swift(>=4.2) -private let i_2166136261 = Int(bitPattern: 2166136261) -private let i_16777619 = Int(16777619) -#endif - -// -// Type-erased Extension field implementation. -// Note that it has no "self or associated type" references, so can -// be used as a protocol type. (In particular, although it does have -// a hashValue property, it cannot be Hashable.) -// -// This can encode, decode, return a hashValue and test for -// equality with some other extension field; but it's type-sealed -// so you can't actually access the contained value itself. -// -public protocol AnyExtensionField: CustomDebugStringConvertible { -#if swift(>=4.2) - func hash(into hasher: inout Hasher) -#else - var hashValue: Int { get } -#endif - var protobufExtension: AnyMessageExtension { get } - func isEqual(other: AnyExtensionField) -> Bool - - /// Merging field decoding - mutating func decodeExtensionField(decoder: inout T) throws - - /// Fields know their own type, so can dispatch to a visitor - func traverse(visitor: inout V) throws - - /// Check if the field is initialized. - var isInitialized: Bool { get } -} - -extension AnyExtensionField { - // Default implementation for extensions fields. The message types below provide - // custom versions. - public var isInitialized: Bool { return true } -} - -/// -/// The regular ExtensionField type exposes the value directly. -/// -public protocol ExtensionField: AnyExtensionField, Hashable { - associatedtype ValueType - var value: ValueType { get set } - init(protobufExtension: AnyMessageExtension, value: ValueType) - init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws -} - -/// -/// Singular field -/// -public struct OptionalExtensionField: ExtensionField { - public typealias BaseType = T.BaseType - public typealias ValueType = BaseType - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: OptionalExtensionField, - rhs: OptionalExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - - public var debugDescription: String { - get { - return String(reflecting: value) - } - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { return value.hashValue } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! OptionalExtensionField - return self == o - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - var v: ValueType? - try T.decodeSingular(value: &v, from: &decoder) - if let v = v { - value = v - } - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType? - try T.decodeSingular(value: &v, from: &decoder) - if let v = v { - self.init(protobufExtension: protobufExtension, value: v) - } else { - return nil - } - } - - public func traverse(visitor: inout V) throws { - try T.visitSingular(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) - } -} - -/// -/// Repeated fields -/// -public struct RepeatedExtensionField: ExtensionField { - public typealias BaseType = T.BaseType - public typealias ValueType = [BaseType] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: RepeatedExtensionField, - rhs: RepeatedExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! RepeatedExtensionField - return self == o - } - - public var debugDescription: String { - return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try T.decodeRepeated(value: &value, from: &decoder) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try T.decodeRepeated(value: &v, from: &decoder) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try T.visitRepeated(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) - } - } -} - -/// -/// Packed Repeated fields -/// -/// TODO: This is almost (but not quite) identical to RepeatedFields; -/// find a way to collapse the implementations. -/// -public struct PackedExtensionField: ExtensionField { - public typealias BaseType = T.BaseType - public typealias ValueType = [BaseType] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: PackedExtensionField, - rhs: PackedExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! PackedExtensionField - return self == o - } - - public var debugDescription: String { - return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try T.decodeRepeated(value: &value, from: &decoder) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try T.decodeRepeated(value: &v, from: &decoder) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try T.visitPacked(value: value, fieldNumber: protobufExtension.fieldNumber, with: &visitor) - } - } -} - -/// -/// Enum extensions -/// -public struct OptionalEnumExtensionField: ExtensionField where E.RawValue == Int { - public typealias BaseType = E - public typealias ValueType = E - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: OptionalEnumExtensionField, - rhs: OptionalEnumExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - - public var debugDescription: String { - get { - return String(reflecting: value) - } - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { return value.hashValue } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! OptionalEnumExtensionField - return self == o - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - var v: ValueType? - try decoder.decodeSingularEnumField(value: &v) - if let v = v { - value = v - } - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType? - try decoder.decodeSingularEnumField(value: &v) - if let v = v { - self.init(protobufExtension: protobufExtension, value: v) - } else { - return nil - } - } - - public func traverse(visitor: inout V) throws { - try visitor.visitSingularEnumField( - value: value, - fieldNumber: protobufExtension.fieldNumber) - } -} - -/// -/// Repeated Enum fields -/// -public struct RepeatedEnumExtensionField: ExtensionField where E.RawValue == Int { - public typealias BaseType = E - public typealias ValueType = [E] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: RepeatedEnumExtensionField, - rhs: RepeatedEnumExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! RepeatedEnumExtensionField - return self == o - } - - public var debugDescription: String { - return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try decoder.decodeRepeatedEnumField(value: &value) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try decoder.decodeRepeatedEnumField(value: &v) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try visitor.visitRepeatedEnumField( - value: value, - fieldNumber: protobufExtension.fieldNumber) - } - } -} - -/// -/// Packed Repeated Enum fields -/// -/// TODO: This is almost (but not quite) identical to RepeatedEnumFields; -/// find a way to collapse the implementations. -/// -public struct PackedEnumExtensionField: ExtensionField where E.RawValue == Int { - public typealias BaseType = E - public typealias ValueType = [E] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: PackedEnumExtensionField, - rhs: PackedEnumExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! PackedEnumExtensionField - return self == o - } - - public var debugDescription: String { - return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try decoder.decodeRepeatedEnumField(value: &value) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try decoder.decodeRepeatedEnumField(value: &v) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try visitor.visitPackedEnumField( - value: value, - fieldNumber: protobufExtension.fieldNumber) - } - } -} - -// -// ========== Message ========== -// -public struct OptionalMessageExtensionField: - ExtensionField { - public typealias BaseType = M - public typealias ValueType = BaseType - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: OptionalMessageExtensionField, - rhs: OptionalMessageExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - - public var debugDescription: String { - get { - return String(reflecting: value) - } - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - value.hash(into: &hasher) - } -#else // swift(>=4.2) - public var hashValue: Int {return value.hashValue} -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! OptionalMessageExtensionField - return self == o - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - var v: ValueType? = value - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - self.value = v - } - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType? - try decoder.decodeSingularMessageField(value: &v) - if let v = v { - self.init(protobufExtension: protobufExtension, value: v) - } else { - return nil - } - } - - public func traverse(visitor: inout V) throws { - try visitor.visitSingularMessageField( - value: value, fieldNumber: protobufExtension.fieldNumber) - } - - public var isInitialized: Bool { - return value.isInitialized - } -} - -public struct RepeatedMessageExtensionField: - ExtensionField { - public typealias BaseType = M - public typealias ValueType = [BaseType] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: RepeatedMessageExtensionField, - rhs: RepeatedMessageExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - for e in value { - e.hash(into: &hasher) - } - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! RepeatedMessageExtensionField - return self == o - } - - public var debugDescription: String { - return "[" + value.map{String(reflecting: $0)}.joined(separator: ",") + "]" - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try decoder.decodeRepeatedMessageField(value: &value) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try decoder.decodeRepeatedMessageField(value: &v) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try visitor.visitRepeatedMessageField( - value: value, fieldNumber: protobufExtension.fieldNumber) - } - } - - public var isInitialized: Bool { - return Internal.areAllInitialized(value) - } -} - -// -// ======== Groups within Messages ======== -// -// Protoc internally treats groups the same as messages, but -// they serialize very differently, so we have separate serialization -// handling here... -public struct OptionalGroupExtensionField: - ExtensionField { - public typealias BaseType = G - public typealias ValueType = BaseType - public var value: G - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: OptionalGroupExtensionField, - rhs: OptionalGroupExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int {return value.hashValue} -#endif // swift(>=4.2) - - public var debugDescription: String { get {return value.debugDescription} } - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! OptionalGroupExtensionField - return self == o - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - var v: ValueType? = value - try decoder.decodeSingularGroupField(value: &v) - if let v = v { - value = v - } - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType? - try decoder.decodeSingularGroupField(value: &v) - if let v = v { - self.init(protobufExtension: protobufExtension, value: v) - } else { - return nil - } - } - - public func traverse(visitor: inout V) throws { - try visitor.visitSingularGroupField( - value: value, fieldNumber: protobufExtension.fieldNumber) - } - - public var isInitialized: Bool { - return value.isInitialized - } -} - -public struct RepeatedGroupExtensionField: - ExtensionField { - public typealias BaseType = G - public typealias ValueType = [BaseType] - public var value: ValueType - public var protobufExtension: AnyMessageExtension - - public static func ==(lhs: RepeatedGroupExtensionField, - rhs: RepeatedGroupExtensionField) -> Bool { - return lhs.value == rhs.value - } - - public init(protobufExtension: AnyMessageExtension, value: ValueType) { - self.protobufExtension = protobufExtension - self.value = value - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -#else // swift(>=4.2) - public var hashValue: Int { - get { - var hash = i_2166136261 - for e in value { - hash = (hash &* i_16777619) ^ e.hashValue - } - return hash - } - } -#endif // swift(>=4.2) - - public var debugDescription: String { - return "[" + value.map{$0.debugDescription}.joined(separator: ",") + "]" - } - - public func isEqual(other: AnyExtensionField) -> Bool { - let o = other as! RepeatedGroupExtensionField - return self == o - } - - public mutating func decodeExtensionField(decoder: inout D) throws { - try decoder.decodeRepeatedGroupField(value: &value) - } - - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { - var v: ValueType = [] - try decoder.decodeRepeatedGroupField(value: &v) - self.init(protobufExtension: protobufExtension, value: v) - } - - public func traverse(visitor: inout V) throws { - if value.count > 0 { - try visitor.visitRepeatedGroupField( - value: value, fieldNumber: protobufExtension.fieldNumber) - } - } - - public var isInitialized: Bool { - return Internal.areAllInitialized(value) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift deleted file mode 100644 index b1115d7..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ExtensionMap.swift +++ /dev/null @@ -1,38 +0,0 @@ -// Sources/SwiftProtobuf/ExtensionMap.swift - Extension support -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A set of extensions that can be passed into deserializers -/// to provide details of the particular extensions that should -/// be recognized. -/// -// ----------------------------------------------------------------------------- - -/// A collection of extension objects. -/// -/// An `ExtensionMap` is used during decoding to look up -/// extension objects corresponding to the serialized data. -/// -/// This is a protocol so that developers can build their own -/// extension handling if they need something more complex than the -/// standard `SimpleExtensionMap` implementation. -public protocol ExtensionMap { - /// Returns the extension object describing an extension or nil - subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { get } - - /// Returns the field number for a message with a specific field name - /// - /// The field name here matches the format used by the protobuf - /// Text serialization: it typically looks like - /// `package.message.field_name`, where `package` is the package - /// for the proto file and `message` is the name of the message in - /// which the extension was defined. (This is different from the - /// message that is being extended!) - func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift deleted file mode 100644 index 139897f..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTag.swift +++ /dev/null @@ -1,69 +0,0 @@ -// Sources/SwiftProtobuf/FieldTag.swift - Describes a binary field tag -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Types related to binary encoded tags (field numbers and wire formats). -/// -// ----------------------------------------------------------------------------- - -/// Encapsulates the number and wire format of a field, which together form the -/// "tag". -/// -/// This type also validates tags in that it will never allow a tag with an -/// improper field number (such as zero) or wire format (such as 6 or 7) to -/// exist. In other words, a `FieldTag`'s properties never need to be tested -/// for validity because they are guaranteed correct at initialization time. -internal struct FieldTag: RawRepresentable { - - typealias RawValue = UInt32 - - /// The raw numeric value of the tag, which contains both the field number and - /// wire format. - let rawValue: UInt32 - - /// The field number component of the tag. - var fieldNumber: Int { - return Int(rawValue >> 3) - } - - /// The wire format component of the tag. - var wireFormat: WireFormat { - // This force-unwrap is safe because there are only two initialization - // paths: one that takes a WireFormat directly (and is guaranteed valid at - // compile-time), or one that takes a raw value but which only lets valid - // wire formats through. - return WireFormat(rawValue: UInt8(rawValue & 7))! - } - - /// A helper property that returns the number of bytes required to - /// varint-encode this tag. - var encodedSize: Int { - return Varint.encodedSize(of: rawValue) - } - - /// Creates a new tag from its raw numeric representation. - /// - /// Note that if the raw value given here is not a valid tag (for example, it - /// has an invalid wire format), this initializer will fail. - init?(rawValue: UInt32) { - // Verify that the field number and wire format are valid and fail if they - // are not. - guard rawValue & ~0x07 != 0, - let _ = WireFormat(rawValue: UInt8(rawValue % 8)) else { - return nil - } - self.rawValue = rawValue - } - - /// Creates a new tag by composing the given field number and wire format. - init(fieldNumber: Int, wireFormat: WireFormat) { - self.rawValue = UInt32(truncatingIfNeeded: fieldNumber) << 3 | - UInt32(wireFormat.rawValue) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift deleted file mode 100644 index ed269ff..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/FieldTypes.swift +++ /dev/null @@ -1,412 +0,0 @@ -// Sources/SwiftProtobuf/FieldTypes.swift - Proto data types -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Serialization/deserialization support for each proto field type. -/// -/// Note that we cannot just extend the standard Int32, etc, types -/// with serialization information since proto language supports -/// distinct types (with different codings) that use the same -/// in-memory representation. For example, proto "sint32" and -/// "sfixed32" both are represented in-memory as Int32. -/// -/// These types are used generically and also passed into -/// various coding/decoding functions to provide type-specific -/// information. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -// Note: The protobuf- and JSON-specific methods here are defined -// in ProtobufTypeAdditions.swift and JSONTypeAdditions.swift -public protocol FieldType { - // The Swift type used to store data for this field. For example, - // proto "sint32" fields use Swift "Int32" type. - associatedtype BaseType: Hashable - - // The default value for this field type before it has been set. - // This is also used, for example, when JSON decodes a "null" - // value for a field. - static var proto3DefaultValue: BaseType { get } - - // Generic reflector methods for looking up the correct - // encoding/decoding for extension fields, map keys, and map - // values. - static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws - static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws - static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws - static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws - static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws -} - -/// -/// Marker protocol for types that can be used as map keys -/// -public protocol MapKeyType: FieldType { -} - -/// -/// Marker Protocol for types that can be used as map values. -/// -public protocol MapValueType: FieldType { -} - -// -// We have a struct for every basic proto field type which provides -// serialization/deserialization support as static methods. -// - -/// -/// Float traits -/// -public struct ProtobufFloat: FieldType, MapValueType { - public typealias BaseType = Float - public static var proto3DefaultValue: Float {return 0.0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularFloatField(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedFloatField(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularFloatField(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedFloatField(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedFloatField(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Double -/// -public struct ProtobufDouble: FieldType, MapValueType { - public typealias BaseType = Double - public static var proto3DefaultValue: Double {return 0.0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularDoubleField(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedDoubleField(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularDoubleField(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedDoubleField(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedDoubleField(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Int32 -/// -public struct ProtobufInt32: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int32 - public static var proto3DefaultValue: Int32 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularInt32Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedInt32Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedInt32Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Int64 -/// - -public struct ProtobufInt64: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int64 - public static var proto3DefaultValue: Int64 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularInt64Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedInt64Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedInt64Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// UInt32 -/// -public struct ProtobufUInt32: FieldType, MapKeyType, MapValueType { - public typealias BaseType = UInt32 - public static var proto3DefaultValue: UInt32 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularUInt32Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedUInt32Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// UInt64 -/// - -public struct ProtobufUInt64: FieldType, MapKeyType, MapValueType { - public typealias BaseType = UInt64 - public static var proto3DefaultValue: UInt64 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularUInt64Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedUInt64Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// SInt32 -/// -public struct ProtobufSInt32: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int32 - public static var proto3DefaultValue: Int32 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularSInt32Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedSInt32Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularSInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedSInt32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedSInt32Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// SInt64 -/// - -public struct ProtobufSInt64: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int64 - public static var proto3DefaultValue: Int64 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularSInt64Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedSInt64Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularSInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedSInt64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedSInt64Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Fixed32 -/// -public struct ProtobufFixed32: FieldType, MapKeyType, MapValueType { - public typealias BaseType = UInt32 - public static var proto3DefaultValue: UInt32 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularFixed32Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedFixed32Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularFixed32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedFixed32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedFixed32Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Fixed64 -/// -public struct ProtobufFixed64: FieldType, MapKeyType, MapValueType { - public typealias BaseType = UInt64 - public static var proto3DefaultValue: UInt64 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularFixed64Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedFixed64Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularFixed64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedFixed64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedFixed64Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// SFixed32 -/// -public struct ProtobufSFixed32: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int32 - public static var proto3DefaultValue: Int32 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularSFixed32Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedSFixed32Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularSFixed32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedSFixed32Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedSFixed32Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// SFixed64 -/// -public struct ProtobufSFixed64: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Int64 - public static var proto3DefaultValue: Int64 {return 0} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularSFixed64Field(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedSFixed64Field(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularSFixed64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedSFixed64Field(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedSFixed64Field(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// Bool -/// -public struct ProtobufBool: FieldType, MapKeyType, MapValueType { - public typealias BaseType = Bool - public static var proto3DefaultValue: Bool {return false} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularBoolField(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedBoolField(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularBoolField(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedBoolField(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitPackedBoolField(value: value, fieldNumber: fieldNumber) - } -} - -/// -/// String -/// -public struct ProtobufString: FieldType, MapKeyType, MapValueType { - public typealias BaseType = String - public static var proto3DefaultValue: String {return String()} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularStringField(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedStringField(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularStringField(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedStringField(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - assert(false) - } -} - -/// -/// Bytes -/// -public struct ProtobufBytes: FieldType, MapValueType { - public typealias BaseType = Data - public static var proto3DefaultValue: Data {return Internal.emptyData} - public static func decodeSingular(value: inout BaseType?, from decoder: inout D) throws { - try decoder.decodeSingularBytesField(value: &value) - } - public static func decodeRepeated(value: inout [BaseType], from decoder: inout D) throws { - try decoder.decodeRepeatedBytesField(value: &value) - } - public static func visitSingular(value: BaseType, fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitSingularBytesField(value: value, fieldNumber: fieldNumber) - } - public static func visitRepeated(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - try visitor.visitRepeatedBytesField(value: value, fieldNumber: fieldNumber) - } - public static func visitPacked(value: [BaseType], fieldNumber: Int, with visitor: inout V) throws { - assert(false) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift deleted file mode 100644 index d607744..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift +++ /dev/null @@ -1,145 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift - Well-known Any type -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extends the `Google_Protobuf_Any` type with various custom behaviors. -/// -// ----------------------------------------------------------------------------- - -// Explicit import of Foundation is necessary on Linux, -// don't remove unless obsolete on all platforms -import Foundation - -public let defaultAnyTypeURLPrefix: String = "type.googleapis.com" - -extension Google_Protobuf_Any { - /// Initialize an Any object from the provided message. - /// - /// This corresponds to the `pack` operation in the C++ API. - /// - /// Unlike the C++ implementation, the message is not immediately - /// serialized; it is merely stored until the Any object itself - /// needs to be serialized. This design avoids unnecessary - /// decoding/recoding when writing JSON format. - /// - /// - Parameters: - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - typePrefix: The prefix to be used when building the `type_url`. - /// Defaults to "type.googleapis.com". - /// - Throws: `BinaryEncodingError.missingRequiredFields` if `partial` is - /// false and `message` wasn't fully initialized. - public init( - message: Message, - partial: Bool = false, - typePrefix: String = defaultAnyTypeURLPrefix - ) throws { - if !partial && !message.isInitialized { - throw BinaryEncodingError.missingRequiredFields - } - self.init() - typeURL = buildTypeURL(forMessage:message, typePrefix: typePrefix) - _storage.state = .message(message) - } - - /// Creates a new `Google_Protobuf_Any` by decoding the given string - /// containing a serialized message in Protocol Buffer text format. - /// - /// - Parameters: - /// - textFormatString: The text format string to decode. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - Throws: an instance of `TextFormatDecodingError` on failure. - public init( - textFormatString: String, - extensions: ExtensionMap? = nil - ) throws { - self.init() - if !textFormatString.isEmpty { - if let data = textFormatString.data(using: String.Encoding.utf8) { - try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - - var textDecoder = try TextFormatDecoder( - messageType: Google_Protobuf_Any.self, - utf8Pointer: bytes, - count: body.count, - extensions: extensions) - try decodeTextFormat(decoder: &textDecoder) - if !textDecoder.complete { - throw TextFormatDecodingError.trailingGarbage - } - } - } - } - } - } - - /// Returns true if this `Google_Protobuf_Any` message contains the given - /// message type. - /// - /// The check is performed by looking at the passed `Message.Type` and the - /// `typeURL` of this message. - /// - /// - Parameter type: The concrete message type. - /// - Returns: True if the receiver contains the given message type. - public func isA(_ type: M.Type) -> Bool { - return _storage.isA(type) - } - -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - _storage.hash(into: &hasher) - } -#else // swift(>=4.2) - public var hashValue: Int { - return _storage.hashValue - } -#endif // swift(>=4.2) -} - -extension Google_Protobuf_Any { - internal func textTraverse(visitor: inout TextFormatEncodingVisitor) { - _storage.textTraverse(visitor: &visitor) - try! unknownFields.traverse(visitor: &visitor) - } -} - -extension Google_Protobuf_Any: _CustomJSONCodable { - // Custom text format decoding support for Any objects. - // (Note: This is not a part of any protocol; it's invoked - // directly from TextFormatDecoder whenever it sees an attempt - // to decode an Any object) - internal mutating func decodeTextFormat( - decoder: inout TextFormatDecoder - ) throws { - // First, check if this uses the "verbose" Any encoding. - // If it does, and we have the type available, we can - // eagerly decode the contained Message object. - if let url = try decoder.scanner.nextOptionalAnyURL() { - try _uniqueStorage().decodeTextFormat(typeURL: url, decoder: &decoder) - } else { - // This is not using the specialized encoding, so we can use the - // standard path to decode the binary value. - try decodeMessage(decoder: &decoder) - } - } - - internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { - return try _storage.encodedJSONString(options: options) - } - - internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - try _uniqueStorage().decodeJSON(from: &decoder) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift deleted file mode 100644 index 1e241d3..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift +++ /dev/null @@ -1,135 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift - Registry for JSON support -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Support for registering and looking up Message types. Used -/// in support of Google_Protobuf_Any. -/// -// ----------------------------------------------------------------------------- - -import Foundation -import Dispatch - -// TODO: Should these first four be exposed as methods to go with -// the general registry support? - -internal func buildTypeURL(forMessage message: Message, typePrefix: String) -> String { - var url = typePrefix - let needsSlash = typePrefix.isEmpty || typePrefix.last != "/" - if needsSlash { - url += "/" - } - return url + typeName(fromMessage: message) -} - -internal func typeName(fromMessage message: Message) -> String { - let messageType = type(of: message) - return messageType.protoMessageName -} - -internal func typeName(fromURL s: String) -> String { - var typeStart = s.startIndex - var i = typeStart - while i < s.endIndex { - let c = s[i] - i = s.index(after: i) - if c == "/" { - typeStart = i - } - } - - return String(s[typeStart.. Bool { - let messageTypeName = messageType.protoMessageName - var result: Bool = false - serialQueue.sync { - if let alreadyRegistered = knownTypes[messageTypeName] { - // Success/failure when something was already registered is - // based on if they are registering the same class or trying - // to register a different type - result = alreadyRegistered == messageType - } else { - knownTypes[messageTypeName] = messageType - result = true - } - } - return result - } - - /// Returns the Message.Type expected for the given type URL. - public static func messageType(forTypeURL url: String) -> Message.Type? { - let messageTypeName = typeName(fromURL: url) - return messageType(forMessageName: messageTypeName) - } - - /// Returns the Message.Type expected for the given proto message name. - public static func messageType(forMessageName name: String) -> Message.Type? { - var result: Message.Type? - serialQueue.sync { - result = knownTypes[name] - } - return result - } - -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift deleted file mode 100644 index c8b5175..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift +++ /dev/null @@ -1,234 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Duration+Extensions.swift - Extensions for Duration type -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extends the generated Duration struct with various custom behaviors: -/// * JSON coding and decoding -/// * Arithmetic operations -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let minDurationSeconds: Int64 = -maxDurationSeconds -private let maxDurationSeconds: Int64 = 315576000000 - -private func parseDuration(text: String) throws -> (Int64, Int32) { - var digits = [Character]() - var digitCount = 0 - var total = 0 - var chars = text.makeIterator() - var seconds: Int64? - var nanos: Int32 = 0 - while let c = chars.next() { - switch c { - case "-": - // Only accept '-' as very first character - if total > 0 { - throw JSONDecodingError.malformedDuration - } - digits.append(c) - case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": - digits.append(c) - digitCount += 1 - case ".": - if let _ = seconds { - throw JSONDecodingError.malformedDuration - } - let digitString = String(digits) - if let s = Int64(digitString), - s >= minDurationSeconds && s <= maxDurationSeconds { - seconds = s - } else { - throw JSONDecodingError.malformedDuration - } - digits.removeAll() - digitCount = 0 - case "s": - if let seconds = seconds { - // Seconds already set, digits holds nanos - while (digitCount < 9) { - digits.append(Character("0")) - digitCount += 1 - } - while digitCount > 9 { - digits.removeLast() - digitCount -= 1 - } - let digitString = String(digits) - if let rawNanos = Int32(digitString) { - if seconds < 0 { - nanos = -rawNanos - } else { - nanos = rawNanos - } - } else { - throw JSONDecodingError.malformedDuration - } - } else { - // No fraction, we just have an integral number of seconds - let digitString = String(digits) - if let s = Int64(digitString), - s >= minDurationSeconds && s <= maxDurationSeconds { - seconds = s - } else { - throw JSONDecodingError.malformedDuration - } - } - // Fail if there are characters after 's' - if chars.next() != nil { - throw JSONDecodingError.malformedDuration - } - return (seconds!, nanos) - default: - throw JSONDecodingError.malformedDuration - } - total += 1 - } - throw JSONDecodingError.malformedDuration -} - -private func formatDuration(seconds: Int64, nanos: Int32) -> String? { - let (seconds, nanos) = normalizeForDuration(seconds: seconds, nanos: nanos) - guard seconds >= minDurationSeconds && seconds <= maxDurationSeconds else { - return nil - } - - if nanos == 0 { - return String(format: "%llds", seconds) - } else if nanos % 1000000 == 0 { - return String(format: "%lld.%03ds", seconds, abs(nanos) / 1000000) - } else if nanos % 1000 == 0 { - return String(format: "%lld.%06ds", seconds, abs(nanos) / 1000) - } else { - return String(format: "%lld.%09ds", seconds, abs(nanos)) - } -} - -extension Google_Protobuf_Duration { - /// Creates a new `Google_Protobuf_Duration` equal to the given number of - /// seconds and nanoseconds. - /// - /// - Parameter seconds: The number of seconds. - /// - Parameter nanos: The number of nanoseconds. - public init(seconds: Int64 = 0, nanos: Int32 = 0) { - self.init() - self.seconds = seconds - self.nanos = nanos - } -} - -extension Google_Protobuf_Duration: _CustomJSONCodable { - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - let s = try decoder.scanner.nextQuotedString() - (seconds, nanos) = try parseDuration(text: s) - } - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - if let formatted = formatDuration(seconds: seconds, nanos: nanos) { - return "\"\(formatted)\"" - } else { - throw JSONEncodingError.durationRange - } - } -} - -extension Google_Protobuf_Duration: ExpressibleByFloatLiteral { - public typealias FloatLiteralType = Double - - /// Creates a new `Google_Protobuf_Duration` from a floating point literal - /// that is interpreted as a duration in seconds, rounded to the nearest - /// nanosecond. - public init(floatLiteral value: Double) { - let sd = trunc(value) - let nd = round((value - sd) * TimeInterval(nanosPerSecond)) - let (s, n) = normalizeForDuration(seconds: Int64(sd), nanos: Int32(nd)) - self.init(seconds: s, nanos: n) - } -} - -extension Google_Protobuf_Duration { - /// Creates a new `Google_Protobuf_Duration` that is equal to the given - /// `TimeInterval` (measured in seconds), rounded to the nearest nanosecond. - /// - /// - Parameter timeInterval: The `TimeInterval`. - public init(timeInterval: TimeInterval) { - let sd = trunc(timeInterval) - let nd = round((timeInterval - sd) * TimeInterval(nanosPerSecond)) - let (s, n) = normalizeForDuration(seconds: Int64(sd), nanos: Int32(nd)) - self.init(seconds: s, nanos: n) - } - - /// The `TimeInterval` (measured in seconds) equal to this duration. - public var timeInterval: TimeInterval { - return TimeInterval(self.seconds) + - TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) - } -} - -private func normalizeForDuration( - seconds: Int64, - nanos: Int32 -) -> (seconds: Int64, nanos: Int32) { - var s = seconds - var n = nanos - - // If the magnitude of n exceeds a second then - // we need to factor it into s instead. - if n >= nanosPerSecond || n <= -nanosPerSecond { - s += Int64(n / nanosPerSecond) - n = n % nanosPerSecond - } - - // The Duration spec says that when s != 0, s and - // n must have the same sign. - if s > 0 && n < 0 { - n += nanosPerSecond - s -= 1 - } else if s < 0 && n > 0 { - n -= nanosPerSecond - s += 1 - } - - return (seconds: s, nanos: n) -} - -public prefix func - ( - operand: Google_Protobuf_Duration -) -> Google_Protobuf_Duration { - let (s, n) = normalizeForDuration(seconds: -operand.seconds, - nanos: -operand.nanos) - return Google_Protobuf_Duration(seconds: s, nanos: n) -} - -public func + ( - lhs: Google_Protobuf_Duration, - rhs: Google_Protobuf_Duration -) -> Google_Protobuf_Duration { - let (s, n) = normalizeForDuration(seconds: lhs.seconds + rhs.seconds, - nanos: lhs.nanos + rhs.nanos) - return Google_Protobuf_Duration(seconds: s, nanos: n) -} - -public func - ( - lhs: Google_Protobuf_Duration, - rhs: Google_Protobuf_Duration -) -> Google_Protobuf_Duration { - let (s, n) = normalizeForDuration(seconds: lhs.seconds - rhs.seconds, - nanos: lhs.nanos - rhs.nanos) - return Google_Protobuf_Duration(seconds: s, nanos: n) -} - -public func - ( - lhs: Google_Protobuf_Timestamp, - rhs: Google_Protobuf_Timestamp -) -> Google_Protobuf_Duration { - let (s, n) = normalizeForDuration(seconds: lhs.seconds - rhs.seconds, - nanos: lhs.nanos - rhs.nanos) - return Google_Protobuf_Duration(seconds: s, nanos: n) -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift deleted file mode 100644 index 6720c94..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift +++ /dev/null @@ -1,163 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift - Fieldmask extensions -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extend the generated FieldMask message with customized JSON coding and -/// convenience methods. -/// -// ----------------------------------------------------------------------------- - -// TODO: We should have utilities to apply a fieldmask to an arbitrary -// message, intersect two fieldmasks, etc. - -private func ProtoToJSON(name: String) -> String? { - var jsonPath = String() - var chars = name.makeIterator() - while let c = chars.next() { - switch c { - case "_": - if let toupper = chars.next() { - switch toupper { - case "a"..."z": - jsonPath.append(String(toupper).uppercased()) - default: - return nil - } - } else { - return nil - } - case "A"..."Z": - return nil - default: - jsonPath.append(c) - } - } - return jsonPath -} - -private func JSONToProto(name: String) -> String? { - var path = String() - for c in name { - switch c { - case "_": - return nil - case "A"..."Z": - path.append(Character("_")) - path.append(String(c).lowercased()) - default: - path.append(c) - } - } - return path -} - -private func parseJSONFieldNames(names: String) -> [String]? { - // An empty field mask is the empty string (no paths). - guard !names.isEmpty else { return [] } - var fieldNameCount = 0 - var fieldName = String() - var split = [String]() - for c in names { - switch c { - case ",": - if fieldNameCount == 0 { - return nil - } - if let pbName = JSONToProto(name: fieldName) { - split.append(pbName) - } else { - return nil - } - fieldName = String() - fieldNameCount = 0 - default: - fieldName.append(c) - fieldNameCount += 1 - } - } - if fieldNameCount == 0 { // Last field name can't be empty - return nil - } - if let pbName = JSONToProto(name: fieldName) { - split.append(pbName) - } else { - return nil - } - return split -} - -extension Google_Protobuf_FieldMask { - /// Creates a new `Google_Protobuf_FieldMask` from the given array of paths. - /// - /// The paths should match the names used in the .proto file, which may be - /// different than the corresponding Swift property names. - /// - /// - Parameter protoPaths: The paths from which to create the field mask, - /// defined using the .proto names for the fields. - public init(protoPaths: [String]) { - self.init() - paths = protoPaths - } - - /// Creates a new `Google_Protobuf_FieldMask` from the given paths. - /// - /// The paths should match the names used in the .proto file, which may be - /// different than the corresponding Swift property names. - /// - /// - Parameter protoPaths: The paths from which to create the field mask, - /// defined using the .proto names for the fields. - public init(protoPaths: String...) { - self.init(protoPaths: protoPaths) - } - - /// Creates a new `Google_Protobuf_FieldMask` from the given paths. - /// - /// The paths should match the JSON names of the fields, which may be - /// different than the corresponding Swift property names. - /// - /// - Parameter jsonPaths: The paths from which to create the field mask, - /// defined using the JSON names for the fields. - public init?(jsonPaths: String...) { - // TODO: This should fail if any of the conversions from JSON fails - #if swift(>=4.1) - self.init(protoPaths: jsonPaths.compactMap(JSONToProto)) - #else - self.init(protoPaths: jsonPaths.flatMap(JSONToProto)) - #endif - } - - // It would be nice if to have an initializer that accepted Swift property - // names, but translating between swift and protobuf/json property - // names is not entirely deterministic. -} - -extension Google_Protobuf_FieldMask: _CustomJSONCodable { - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - let s = try decoder.scanner.nextQuotedString() - if let names = parseJSONFieldNames(names: s) { - paths = names - } else { - throw JSONDecodingError.malformedFieldMask - } - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - // Note: Proto requires alphanumeric field names, so there - // cannot be a ',' or '"' character to mess up this formatting. - var jsonPaths = [String]() - for p in paths { - if let jsonPath = ProtoToJSON(name: p) { - jsonPaths.append(jsonPath) - } else { - throw JSONEncodingError.fieldMaskConversion - } - } - return "\"" + jsonPaths.joined(separator: ",") + "\"" - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift deleted file mode 100644 index 453ea0d..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift +++ /dev/null @@ -1,80 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_ListValue+Extensions.swift - ListValue extensions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// ListValue is a well-known message type that can be used to parse or encode -/// arbitrary JSON arrays without a predefined schema. -/// -// ----------------------------------------------------------------------------- - -extension Google_Protobuf_ListValue: ExpressibleByArrayLiteral { - // TODO: Give this a direct array interface by proxying the interesting - // bits down to values - public typealias Element = Google_Protobuf_Value - - /// Creates a new `Google_Protobuf_ListValue` from an array literal containing - /// `Google_Protobuf_Value` elements. - public init(arrayLiteral elements: Element...) { - self.init(values: elements) - } -} - -extension Google_Protobuf_ListValue: _CustomJSONCodable { - internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var jsonEncoder = JSONEncoder() - jsonEncoder.append(text: "[") - var separator: StaticString = "" - for v in values { - jsonEncoder.append(staticText: separator) - try v.serializeJSONValue(to: &jsonEncoder, options: options) - separator = "," - } - jsonEncoder.append(text: "]") - return jsonEncoder.stringResult - } - - internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - if decoder.scanner.skipOptionalNull() { - return - } - try decoder.scanner.skipRequiredArrayStart() - if decoder.scanner.skipOptionalArrayEnd() { - return - } - while true { - var v = Google_Protobuf_Value() - try v.decodeJSON(from: &decoder) - values.append(v) - if decoder.scanner.skipOptionalArrayEnd() { - return - } - try decoder.scanner.skipRequiredComma() - } - } -} - -extension Google_Protobuf_ListValue { - /// Creates a new `Google_Protobuf_ListValue` from the given array of - /// `Google_Protobuf_Value` elements. - /// - /// - Parameter values: The list of `Google_Protobuf_Value` messages from - /// which to create the `Google_Protobuf_ListValue`. - public init(values: [Google_Protobuf_Value]) { - self.init() - self.values = values - } - - /// Accesses the `Google_Protobuf_Value` at the specified position. - /// - /// - Parameter index: The position of the element to access. - public subscript(index: Int) -> Google_Protobuf_Value { - get {return values[index]} - set(newValue) {values[index] = newValue} - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift deleted file mode 100644 index 1a7c31c..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift +++ /dev/null @@ -1,85 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Struct+Extensions.swift - Struct extensions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Struct is a well-known message type that can be used to parse or encode -/// arbitrary JSON objects without a predefined schema. -/// -// ----------------------------------------------------------------------------- - -extension Google_Protobuf_Struct: ExpressibleByDictionaryLiteral { - public typealias Key = String - public typealias Value = Google_Protobuf_Value - - /// Creates a new `Google_Protobuf_Struct` from a dictionary of string keys to - /// values of type `Google_Protobuf_Value`. - public init(dictionaryLiteral: (String, Google_Protobuf_Value)...) { - self.init() - for (k,v) in dictionaryLiteral { - fields[k] = v - } - } -} - -extension Google_Protobuf_Struct: _CustomJSONCodable { - internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var jsonEncoder = JSONEncoder() - jsonEncoder.startObject() - var mapVisitor = JSONMapEncodingVisitor(encoder: jsonEncoder, options: options) - for (k,v) in fields { - try mapVisitor.visitSingularStringField(value: k, fieldNumber: 1) - try mapVisitor.visitSingularMessageField(value: v, fieldNumber: 2) - } - mapVisitor.encoder.endObject() - return mapVisitor.encoder.stringResult - } - - internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - try decoder.scanner.skipRequiredObjectStart() - if decoder.scanner.skipOptionalObjectEnd() { - return - } - while true { - let key = try decoder.scanner.nextQuotedString() - try decoder.scanner.skipRequiredColon() - var value = Google_Protobuf_Value() - try value.decodeJSON(from: &decoder) - fields[key] = value - if decoder.scanner.skipOptionalObjectEnd() { - return - } - try decoder.scanner.skipRequiredComma() - } - } -} - -extension Google_Protobuf_Struct { - /// Creates a new `Google_Protobuf_Struct` from a dictionary of string keys to - /// values of type `Google_Protobuf_Value`. - /// - /// - Parameter fields: The dictionary from field names to - /// `Google_Protobuf_Value` messages that should be used to create the - /// `Struct`. - public init(fields: [String: Google_Protobuf_Value]) { - self.init() - self.fields = fields - } - - /// Accesses the `Google_Protobuf_Value` with the given key for reading and - /// writing. - /// - /// This key-based subscript returns the `Value` for the given key if the key - /// is found in the `Struct`, or nil if the key is not found. If you assign - /// nil as the `Value` for the given key, the `Struct` removes that key and - /// its associated `Value`. - public subscript(key: String) -> Google_Protobuf_Value? { - get {return fields[key]} - set(newValue) {fields[key] = newValue} - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift deleted file mode 100644 index 11735f6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift +++ /dev/null @@ -1,337 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Timestamp+Extensions.swift - Timestamp extensions -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extend the generated Timestamp message with customized JSON coding, -/// arithmetic operations, and convenience methods. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let minTimestampSeconds: Int64 = -62135596800 // 0001-01-01T00:00:00Z -private let maxTimestampSeconds: Int64 = 253402300799 // 9999-12-31T23:59:59Z - -// TODO: Add convenience methods to interoperate with standard -// date/time classes: an initializer that accepts Unix timestamp as -// Int or Double, an easy way to convert to/from Foundation's -// NSDateTime (on Apple platforms only?), others? - - -// Parse an RFC3339 timestamp into a pair of seconds-since-1970 and nanos. -private func parseTimestamp(s: String) throws -> (Int64, Int32) { - // Convert to an array of integer character values - let value = s.utf8.map{Int($0)} - if value.count < 20 { - throw JSONDecodingError.malformedTimestamp - } - // Since the format is fixed-layout, we can just decode - // directly as follows. - let zero = Int(48) - let nine = Int(57) - let dash = Int(45) - let colon = Int(58) - let plus = Int(43) - let letterT = Int(84) - let letterZ = Int(90) - let period = Int(46) - - func fromAscii2(_ digit0: Int, _ digit1: Int) throws -> Int { - if digit0 < zero || digit0 > nine || digit1 < zero || digit1 > nine { - throw JSONDecodingError.malformedTimestamp - } - return digit0 * 10 + digit1 - 528 - } - - func fromAscii4( - _ digit0: Int, - _ digit1: Int, - _ digit2: Int, - _ digit3: Int - ) throws -> Int { - if (digit0 < zero || digit0 > nine - || digit1 < zero || digit1 > nine - || digit2 < zero || digit2 > nine - || digit3 < zero || digit3 > nine) { - throw JSONDecodingError.malformedTimestamp - } - return digit0 * 1000 + digit1 * 100 + digit2 * 10 + digit3 - 53328 - } - - // Year: 4 digits followed by '-' - let year = try fromAscii4(value[0], value[1], value[2], value[3]) - if value[4] != dash || year < Int(1) || year > Int(9999) { - throw JSONDecodingError.malformedTimestamp - } - - // Month: 2 digits followed by '-' - let month = try fromAscii2(value[5], value[6]) - if value[7] != dash || month < Int(1) || month > Int(12) { - throw JSONDecodingError.malformedTimestamp - } - - // Day: 2 digits followed by 'T' - let mday = try fromAscii2(value[8], value[9]) - if value[10] != letterT || mday < Int(1) || mday > Int(31) { - throw JSONDecodingError.malformedTimestamp - } - - // Hour: 2 digits followed by ':' - let hour = try fromAscii2(value[11], value[12]) - if value[13] != colon || hour > Int(23) { - throw JSONDecodingError.malformedTimestamp - } - - // Minute: 2 digits followed by ':' - let minute = try fromAscii2(value[14], value[15]) - if value[16] != colon || minute > Int(59) { - throw JSONDecodingError.malformedTimestamp - } - - // Second: 2 digits (following char is checked below) - let second = try fromAscii2(value[17], value[18]) - if second > Int(61) { - throw JSONDecodingError.malformedTimestamp - } - - // timegm() is almost entirely useless. It's nonexistent on - // some platforms, broken on others. Everything else I've tried - // is even worse. Hence the code below. - // (If you have a better way to do this, try it and see if it - // passes the test suite on both Linux and OS X.) - - // Day of year - let mdayStart: [Int] = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] - var yday = Int64(mdayStart[month - 1]) - let isleap = (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)) - if isleap && (month > 2) { - yday += 1 - } - yday += Int64(mday - 1) - - // Days since start of epoch (including leap days) - var daysSinceEpoch = yday - daysSinceEpoch += Int64(365 * year) - Int64(719527) - daysSinceEpoch += Int64((year - 1) / 4) - daysSinceEpoch -= Int64((year - 1) / 100) - daysSinceEpoch += Int64((year - 1) / 400) - - // Second within day - var daySec = Int64(hour) - daySec *= 60 - daySec += Int64(minute) - daySec *= 60 - daySec += Int64(second) - - // Seconds since start of epoch - let t = daysSinceEpoch * Int64(86400) + daySec - - // After seconds, comes various optional bits - var pos = 19 - - var nanos: Int32 = 0 - if value[pos] == period { // "." begins fractional seconds - pos += 1 - var digitValue = 100000000 - while pos < value.count && value[pos] >= zero && value[pos] <= nine { - nanos += Int32(digitValue * (value[pos] - zero)) - digitValue /= 10 - pos += 1 - } - } - - var seconds: Int64 = 0 - // "+" or "-" starts Timezone offset - if value[pos] == plus || value[pos] == dash { - if pos + 6 > value.count { - throw JSONDecodingError.malformedTimestamp - } - let hourOffset = try fromAscii2(value[pos + 1], value[pos + 2]) - let minuteOffset = try fromAscii2(value[pos + 4], value[pos + 5]) - if hourOffset > Int(13) || minuteOffset > Int(59) || value[pos + 3] != colon { - throw JSONDecodingError.malformedTimestamp - } - var adjusted: Int64 = t - if value[pos] == plus { - adjusted -= Int64(hourOffset) * Int64(3600) - adjusted -= Int64(minuteOffset) * Int64(60) - } else { - adjusted += Int64(hourOffset) * Int64(3600) - adjusted += Int64(minuteOffset) * Int64(60) - } - if adjusted < minTimestampSeconds || adjusted > maxTimestampSeconds { - throw JSONDecodingError.malformedTimestamp - } - seconds = adjusted - pos += 6 - } else if value[pos] == letterZ { // "Z" indicator for UTC - seconds = t - pos += 1 - } else { - throw JSONDecodingError.malformedTimestamp - } - if pos != value.count { - throw JSONDecodingError.malformedTimestamp - } - return (seconds, nanos) -} - -private func formatTimestamp(seconds: Int64, nanos: Int32) -> String? { - let (seconds, nanos) = normalizeForTimestamp(seconds: seconds, nanos: nanos) - guard seconds >= minTimestampSeconds && seconds <= maxTimestampSeconds else { - return nil - } - - let (hh, mm, ss) = timeOfDayFromSecondsSince1970(seconds: seconds) - let (YY, MM, DD) = gregorianDateFromSecondsSince1970(seconds: seconds) - - if nanos == 0 { - return String(format: "%04d-%02d-%02dT%02d:%02d:%02dZ", - YY, MM, DD, hh, mm, ss) - } else if nanos % 1000000 == 0 { - return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", - YY, MM, DD, hh, mm, ss, nanos / 1000000) - } else if nanos % 1000 == 0 { - return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ", - YY, MM, DD, hh, mm, ss, nanos / 1000) - } else { - return String(format: "%04d-%02d-%02dT%02d:%02d:%02d.%09dZ", - YY, MM, DD, hh, mm, ss, nanos) - } -} - -extension Google_Protobuf_Timestamp { - /// Creates a new `Google_Protobuf_Timestamp` equal to the given number of - /// seconds and nanoseconds. - /// - /// - Parameter seconds: The number of seconds. - /// - Parameter nanos: The number of nanoseconds. - public init(seconds: Int64 = 0, nanos: Int32 = 0) { - self.init() - self.seconds = seconds - self.nanos = nanos - } -} - -extension Google_Protobuf_Timestamp: _CustomJSONCodable { - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - let s = try decoder.scanner.nextQuotedString() - (seconds, nanos) = try parseTimestamp(s: s) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - if let formatted = formatTimestamp(seconds: seconds, nanos: nanos) { - return "\"\(formatted)\"" - } else { - throw JSONEncodingError.timestampRange - } - } -} - -extension Google_Protobuf_Timestamp { - /// Creates a new `Google_Protobuf_Timestamp` initialized relative to 00:00:00 - /// UTC on 1 January 1970 by a given number of seconds. - /// - /// - Parameter timeIntervalSince1970: The `TimeInterval`, interpreted as - /// seconds relative to 00:00:00 UTC on 1 January 1970. - public init(timeIntervalSince1970: TimeInterval) { - let sd = floor(timeIntervalSince1970) - let nd = round((timeIntervalSince1970 - sd) * TimeInterval(nanosPerSecond)) - let (s, n) = normalizeForTimestamp(seconds: Int64(sd), nanos: Int32(nd)) - self.init(seconds: s, nanos: n) - } - - /// Creates a new `Google_Protobuf_Timestamp` initialized relative to 00:00:00 - /// UTC on 1 January 2001 by a given number of seconds. - /// - /// - Parameter timeIntervalSinceReferenceDate: The `TimeInterval`, - /// interpreted as seconds relative to 00:00:00 UTC on 1 January 2001. - public init(timeIntervalSinceReferenceDate: TimeInterval) { - let sd = floor(timeIntervalSinceReferenceDate) - let nd = round( - (timeIntervalSinceReferenceDate - sd) * TimeInterval(nanosPerSecond)) - // The addition of timeIntervalBetween1970And... is deliberately delayed - // until the input is separated into an integer part and a fraction - // part, so that we don't unnecessarily lose precision. - let (s, n) = normalizeForTimestamp( - seconds: Int64(sd) + Int64(Date.timeIntervalBetween1970AndReferenceDate), - nanos: Int32(nd)) - self.init(seconds: s, nanos: n) - } - - /// Creates a new `Google_Protobuf_Timestamp` initialized to the same time as - /// the given `Date`. - /// - /// - Parameter date: The `Date` with which to initialize the timestamp. - public init(date: Date) { - // Note: Internally, Date uses the "reference date," not the 1970 date. - // We use it when interacting with Dates so that Date doesn't perform - // any double arithmetic on our behalf, which might cost us precision. - self.init( - timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate) - } - - /// The interval between the timestamp and 00:00:00 UTC on 1 January 1970. - public var timeIntervalSince1970: TimeInterval { - return TimeInterval(self.seconds) + - TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) - } - - /// The interval between the timestamp and 00:00:00 UTC on 1 January 2001. - public var timeIntervalSinceReferenceDate: TimeInterval { - return TimeInterval( - self.seconds - Int64(Date.timeIntervalBetween1970AndReferenceDate)) + - TimeInterval(self.nanos) / TimeInterval(nanosPerSecond) - } - - /// A `Date` initialized to the same time as the timestamp. - public var date: Date { - return Date( - timeIntervalSinceReferenceDate: self.timeIntervalSinceReferenceDate) - } -} - -private func normalizeForTimestamp( - seconds: Int64, - nanos: Int32 -) -> (seconds: Int64, nanos: Int32) { - // The Timestamp spec says that nanos must be in the range [0, 999999999), - // as in actual modular arithmetic. - - let s = seconds + Int64(div(nanos, nanosPerSecond)) - let n = mod(nanos, nanosPerSecond) - return (seconds: s, nanos: n) -} - -public func + ( - lhs: Google_Protobuf_Timestamp, - rhs: Google_Protobuf_Duration -) -> Google_Protobuf_Timestamp { - let (s, n) = normalizeForTimestamp(seconds: lhs.seconds + rhs.seconds, - nanos: lhs.nanos + rhs.nanos) - return Google_Protobuf_Timestamp(seconds: s, nanos: n) -} - -public func + ( - lhs: Google_Protobuf_Duration, - rhs: Google_Protobuf_Timestamp -) -> Google_Protobuf_Timestamp { - let (s, n) = normalizeForTimestamp(seconds: lhs.seconds + rhs.seconds, - nanos: lhs.nanos + rhs.nanos) - return Google_Protobuf_Timestamp(seconds: s, nanos: n) -} - -public func - ( - lhs: Google_Protobuf_Timestamp, - rhs: Google_Protobuf_Duration -) -> Google_Protobuf_Timestamp { - let (s, n) = normalizeForTimestamp(seconds: lhs.seconds - rhs.seconds, - nanos: lhs.nanos - rhs.nanos) - return Google_Protobuf_Timestamp(seconds: s, nanos: n) -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift deleted file mode 100644 index 9d4c7d7..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift +++ /dev/null @@ -1,163 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Value+Extensions.swift - Value extensions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Value is a well-known message type that can be used to parse or encode -/// arbitrary JSON without a predefined schema. -/// -// ----------------------------------------------------------------------------- - -extension Google_Protobuf_Value: ExpressibleByIntegerLiteral { - public typealias IntegerLiteralType = Int64 - - /// Creates a new `Google_Protobuf_Value` from an integer literal. - public init(integerLiteral value: Int64) { - self.init(kind: .numberValue(Double(value))) - } -} - -extension Google_Protobuf_Value: ExpressibleByFloatLiteral { - public typealias FloatLiteralType = Double - - /// Creates a new `Google_Protobuf_Value` from a floating point literal. - public init(floatLiteral value: Double) { - self.init(kind: .numberValue(value)) - } -} - -extension Google_Protobuf_Value: ExpressibleByBooleanLiteral { - public typealias BooleanLiteralType = Bool - - /// Creates a new `Google_Protobuf_Value` from a boolean literal. - public init(booleanLiteral value: Bool) { - self.init(kind: .boolValue(value)) - } -} - -extension Google_Protobuf_Value: ExpressibleByStringLiteral { - public typealias StringLiteralType = String - public typealias ExtendedGraphemeClusterLiteralType = String - public typealias UnicodeScalarLiteralType = String - - /// Creates a new `Google_Protobuf_Value` from a string literal. - public init(stringLiteral value: String) { - self.init(kind: .stringValue(value)) - } - - /// Creates a new `Google_Protobuf_Value` from a Unicode scalar literal. - public init(unicodeScalarLiteral value: String) { - self.init(kind: .stringValue(value)) - } - - /// Creates a new `Google_Protobuf_Value` from a character literal. - public init(extendedGraphemeClusterLiteral value: String) { - self.init(kind: .stringValue(value)) - } -} - -extension Google_Protobuf_Value: ExpressibleByNilLiteral { - /// Creates a new `Google_Protobuf_Value` from the nil literal. - public init(nilLiteral: ()) { - self.init(kind: .nullValue(.nullValue)) - } -} - -extension Google_Protobuf_Value: _CustomJSONCodable { - internal func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var jsonEncoder = JSONEncoder() - try serializeJSONValue(to: &jsonEncoder, options: options) - return jsonEncoder.stringResult - } - - internal mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - let c = try decoder.scanner.peekOneCharacter() - switch c { - case "n": - if !decoder.scanner.skipOptionalNull() { - throw JSONDecodingError.failure - } - kind = .nullValue(.nullValue) - case "[": - var l = Google_Protobuf_ListValue() - try l.decodeJSON(from: &decoder) - kind = .listValue(l) - case "{": - var s = Google_Protobuf_Struct() - try s.decodeJSON(from: &decoder) - kind = .structValue(s) - case "t", "f": - let b = try decoder.scanner.nextBool() - kind = .boolValue(b) - case "\"": - let s = try decoder.scanner.nextQuotedString() - kind = .stringValue(s) - default: - let d = try decoder.scanner.nextDouble() - kind = .numberValue(d) - } - } - - internal static func decodedFromJSONNull() -> Google_Protobuf_Value? { - return Google_Protobuf_Value(kind: .nullValue(.nullValue)) - } -} - -extension Google_Protobuf_Value { - /// Creates a new `Google_Protobuf_Value` with the given kind. - fileprivate init(kind: OneOf_Kind) { - self.init() - self.kind = kind - } - - /// Creates a new `Google_Protobuf_Value` whose `kind` is `numberValue` with - /// the given floating-point value. - public init(numberValue: Double) { - self.init(kind: .numberValue(numberValue)) - } - - /// Creates a new `Google_Protobuf_Value` whose `kind` is `stringValue` with - /// the given string value. - public init(stringValue: String) { - self.init(kind: .stringValue(stringValue)) - } - - /// Creates a new `Google_Protobuf_Value` whose `kind` is `boolValue` with the - /// given boolean value. - public init(boolValue: Bool) { - self.init(kind: .boolValue(boolValue)) - } - - /// Creates a new `Google_Protobuf_Value` whose `kind` is `structValue` with - /// the given `Google_Protobuf_Struct` value. - public init(structValue: Google_Protobuf_Struct) { - self.init(kind: .structValue(structValue)) - } - - /// Creates a new `Google_Protobuf_Value` whose `kind` is `listValue` with the - /// given `Google_Struct_ListValue` value. - public init(listValue: Google_Protobuf_ListValue) { - self.init(kind: .listValue(listValue)) - } - - /// Writes out the JSON representation of the value to the given encoder. - internal func serializeJSONValue( - to encoder: inout JSONEncoder, - options: JSONEncodingOptions - ) throws { - switch kind { - case .nullValue?: encoder.putNullValue() - case .numberValue(let v)?: encoder.putDoubleValue(value: v) - case .stringValue(let v)?: encoder.putStringValue(value: v) - case .boolValue(let v)?: encoder.putBoolValue(value: v) - case .structValue(let v)?: encoder.append(text: try v.jsonString(options: options)) - case .listValue(let v)?: encoder.append(text: try v.jsonString(options: options)) - case nil: throw JSONEncodingError.missingValue - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift deleted file mode 100644 index 2860791..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift +++ /dev/null @@ -1,283 +0,0 @@ -// Sources/SwiftProtobuf/Google_Protobuf_Wrappers+Extensions.swift - Well-known wrapper type extensions -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extensions to the well-known types in wrapper.proto that customize the JSON -/// format of those messages and provide convenience initializers from literals. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Internal protocol that minimizes the code duplication across the multiple -/// wrapper types extended below. -protocol ProtobufWrapper { - - /// The wrapped protobuf type (for example, `ProtobufDouble`). - associatedtype WrappedType: FieldType - - /// Exposes the generated property to the extensions here. - var value: WrappedType.BaseType { get set } - - /// Exposes the parameterless initializer to the extensions here. - init() - - /// Creates a new instance of the wrapper with the given value. - init(_ value: WrappedType.BaseType) -} - -extension Google_Protobuf_DoubleValue: - ProtobufWrapper, ExpressibleByFloatLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufDouble - public typealias FloatLiteralType = WrappedType.BaseType - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(floatLiteral: FloatLiteralType) { - self.init(floatLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putDoubleValue(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_FloatValue: - ProtobufWrapper, ExpressibleByFloatLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufFloat - public typealias FloatLiteralType = Float - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(floatLiteral: FloatLiteralType) { - self.init(floatLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putFloatValue(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_Int64Value: - ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufInt64 - public typealias IntegerLiteralType = WrappedType.BaseType - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(integerLiteral: IntegerLiteralType) { - self.init(integerLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putInt64(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_UInt64Value: - ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufUInt64 - public typealias IntegerLiteralType = WrappedType.BaseType - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(integerLiteral: IntegerLiteralType) { - self.init(integerLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putUInt64(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_Int32Value: - ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufInt32 - public typealias IntegerLiteralType = WrappedType.BaseType - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(integerLiteral: IntegerLiteralType) { - self.init(integerLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - return String(value) - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_UInt32Value: - ProtobufWrapper, ExpressibleByIntegerLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufUInt32 - public typealias IntegerLiteralType = WrappedType.BaseType - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(integerLiteral: IntegerLiteralType) { - self.init(integerLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - return String(value) - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_BoolValue: - ProtobufWrapper, ExpressibleByBooleanLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufBool - public typealias BooleanLiteralType = Bool - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(booleanLiteral: Bool) { - self.init(booleanLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - return value ? "true" : "false" - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_StringValue: - ProtobufWrapper, ExpressibleByStringLiteral, _CustomJSONCodable { - - public typealias WrappedType = ProtobufString - public typealias StringLiteralType = String - public typealias ExtendedGraphemeClusterLiteralType = String - public typealias UnicodeScalarLiteralType = String - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - public init(stringLiteral: String) { - self.init(stringLiteral) - } - - public init(extendedGraphemeClusterLiteral: String) { - self.init(extendedGraphemeClusterLiteral) - } - - public init(unicodeScalarLiteral: String) { - self.init(unicodeScalarLiteral) - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putStringValue(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} - -extension Google_Protobuf_BytesValue: ProtobufWrapper, _CustomJSONCodable { - - public typealias WrappedType = ProtobufBytes - - public init(_ value: WrappedType.BaseType) { - self.init() - self.value = value - } - - func encodedJSONString(options: JSONEncodingOptions) throws -> String { - var encoder = JSONEncoder() - encoder.putBytesValue(value: value) - return encoder.stringResult - } - - mutating func decodeJSON(from decoder: inout JSONDecoder) throws { - var v: WrappedType.BaseType? - try WrappedType.decodeSingular(value: &v, from: &decoder) - value = v ?? WrappedType.proto3DefaultValue - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift deleted file mode 100644 index 240ade1..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/HashVisitor.swift +++ /dev/null @@ -1,408 +0,0 @@ -// Sources/SwiftProtobuf/HashVisitor.swift - Hashing support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Hashing is basically a serialization problem, so we can leverage the -/// generated traversal methods for that. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let i_2166136261 = Int(bitPattern: 2166136261) -private let i_16777619 = Int(16777619) - -/// Computes the hash of a message by visiting its fields recursively. -/// -/// Note that because this visits every field, it has the potential to be slow -/// for large or deeply nested messages. Users who need to use such messages as -/// dictionary keys or set members can use a wrapper struct around the message -/// and use a custom Hashable implementation that looks at the subset of the -/// message fields they want to include. -internal struct HashVisitor: Visitor { - -#if swift(>=4.2) - internal private(set) var hasher: Hasher -#else // swift(>=4.2) - // Roughly based on FNV hash: http://tools.ietf.org/html/draft-eastlake-fnv-03 - private(set) var hashValue = i_2166136261 - - private mutating func mix(_ hash: Int) { - hashValue = (hashValue ^ hash) &* i_16777619 - } - - private mutating func mixMap(map: Dictionary) { - var mapHash = 0 - for (k, v) in map { - // Note: This calculation cannot depend on the order of the items. - mapHash = mapHash &+ (k.hashValue ^ v.hashValue) - } - mix(mapHash) - } -#endif // swift(>=4.2) - -#if swift(>=4.2) - init(_ hasher: Hasher) { - self.hasher = hasher - } -#else - init() {} -#endif - - mutating func visitUnknown(bytes: Data) throws { - #if swift(>=4.2) - hasher.combine(bytes) - #else - mix(bytes.hashValue) - #endif - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularEnumField(value: E, - fieldNumber: Int) { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitSingularMessageField(value: M, fieldNumber: Int) { - #if swift(>=4.2) - hasher.combine(fieldNumber) - value.hash(into: &hasher) - #else - mix(fieldNumber) - mix(value.hashValue) - #endif - } - - mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - for v in value { - v.hash(into: &hasher) - } - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - for v in value { - v.hash(into: &hasher) - } - #else - mix(fieldNumber) - for v in value { - mix(v.hashValue) - } - #endif - } - - mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int - ) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mixMap(map: value) - #endif - } - - mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int - ) throws where ValueType.RawValue == Int { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mixMap(map: value) - #endif - } - - mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int - ) throws { - #if swift(>=4.2) - hasher.combine(fieldNumber) - hasher.combine(value) - #else - mix(fieldNumber) - mixMap(map: value) - #endif - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift deleted file mode 100644 index 6402e22..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Internal.swift +++ /dev/null @@ -1,51 +0,0 @@ -// Sources/SwiftProtobuf/Internal.swift - Message support -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Internal helpers on Messages for the library. These are public -/// just so the generated code can call them, but shouldn't be called -/// by developers directly. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Functions that are public only because they are used by generated message -/// implementations. NOT INTENDED TO BE CALLED BY CLIENTS. -public enum Internal { - - /// A singleton instance of an empty data that is used by the generated code - /// for default values. This is a performance enhancement to work around the - /// fact that the `Data` type in Swift involves a new heap allocation every - /// time an empty instance is initialized, instead of sharing a common empty - /// backing storage. - public static let emptyData = Data() - - /// Helper to loop over a list of Messages to see if they are all - /// initialized (see Message.isInitialized for what that means). - public static func areAllInitialized(_ listOfMessages: [Message]) -> Bool { - for msg in listOfMessages { - if !msg.isInitialized { - return false - } - } - return true - } - - /// Helper to loop over dictionary with values that are Messages to see if - /// they are all initialized (see Message.isInitialized for what that means). - public static func areAllInitialized(_ mapToMessages: [K: Message]) -> Bool { - for (_, msg) in mapToMessages { - if !msg.isInitialized { - return false - } - } - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift deleted file mode 100644 index 54566b2..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecoder.swift +++ /dev/null @@ -1,702 +0,0 @@ -// Sources/SwiftProtobuf/JSONDecoder.swift - JSON format decoding -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON format decoding engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -internal struct JSONDecoder: Decoder { - internal var scanner: JSONScanner - internal var options: JSONDecodingOptions - private var fieldCount = 0 - private var isMapKey = false - private var fieldNameMap: _NameMap? - - mutating func handleConflictingOneOf() throws { - throw JSONDecodingError.conflictingOneOf - } - - internal init(source: UnsafeBufferPointer, options: JSONDecodingOptions) { - self.options = options - self.scanner = JSONScanner(source: source, - messageDepthLimit: self.options.messageDepthLimit, - ignoreUnknownFields: self.options.ignoreUnknownFields) - } - - private init(decoder: JSONDecoder) { - // The scanner is copied over along with the options. - scanner = decoder.scanner - options = decoder.options - } - - mutating func nextFieldNumber() throws -> Int? { - if scanner.skipOptionalObjectEnd() { - return nil - } - if fieldCount > 0 { - try scanner.skipRequiredComma() - } - if let fieldNumber = try scanner.nextFieldNumber(names: fieldNameMap!) { - fieldCount += 1 - return fieldNumber - } - return nil - } - - mutating func decodeSingularFloatField(value: inout Float) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - value = try scanner.nextFloat() - } - - mutating func decodeSingularFloatField(value: inout Float?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextFloat() - } - - mutating func decodeRepeatedFloatField(value: inout [Float]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextFloat() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularDoubleField(value: inout Double) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - value = try scanner.nextDouble() - } - - mutating func decodeSingularDoubleField(value: inout Double?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextDouble() - } - - mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextDouble() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularInt32Field(value: inout Int32) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw JSONDecodingError.numberRange - } - value = Int32(truncatingIfNeeded: n) - } - - mutating func decodeSingularInt32Field(value: inout Int32?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw JSONDecodingError.numberRange - } - value = Int32(truncatingIfNeeded: n) - } - - mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw JSONDecodingError.numberRange - } - value.append(Int32(truncatingIfNeeded: n)) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularInt64Field(value: inout Int64) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - value = try scanner.nextSInt() - } - - mutating func decodeSingularInt64Field(value: inout Int64?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextSInt() - } - - mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextSInt() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularUInt32Field(value: inout UInt32) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw JSONDecodingError.numberRange - } - value = UInt32(truncatingIfNeeded: n) - } - - mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw JSONDecodingError.numberRange - } - value = UInt32(truncatingIfNeeded: n) - } - - mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw JSONDecodingError.numberRange - } - value.append(UInt32(truncatingIfNeeded: n)) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularUInt64Field(value: inout UInt64) throws { - if scanner.skipOptionalNull() { - value = 0 - return - } - value = try scanner.nextUInt() - } - - mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextUInt() - } - - mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextUInt() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularSInt32Field(value: inout Int32) throws { - try decodeSingularInt32Field(value: &value) - } - - mutating func decodeSingularSInt32Field(value: inout Int32?) throws { - try decodeSingularInt32Field(value: &value) - } - - mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { - try decodeRepeatedInt32Field(value: &value) - } - - mutating func decodeSingularSInt64Field(value: inout Int64) throws { - try decodeSingularInt64Field(value: &value) - } - - mutating func decodeSingularSInt64Field(value: inout Int64?) throws { - try decodeSingularInt64Field(value: &value) - } - - mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { - try decodeRepeatedInt64Field(value: &value) - } - - mutating func decodeSingularFixed32Field(value: inout UInt32) throws { - try decodeSingularUInt32Field(value: &value) - } - - mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { - try decodeSingularUInt32Field(value: &value) - } - - mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { - try decodeRepeatedUInt32Field(value: &value) - } - - mutating func decodeSingularFixed64Field(value: inout UInt64) throws { - try decodeSingularUInt64Field(value: &value) - } - - mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { - try decodeSingularUInt64Field(value: &value) - } - - mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { - try decodeRepeatedUInt64Field(value: &value) - } - - mutating func decodeSingularSFixed32Field(value: inout Int32) throws { - try decodeSingularInt32Field(value: &value) - } - - mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { - try decodeSingularInt32Field(value: &value) - } - - mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { - try decodeRepeatedInt32Field(value: &value) - } - - mutating func decodeSingularSFixed64Field(value: inout Int64) throws { - try decodeSingularInt64Field(value: &value) - } - - mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { - try decodeSingularInt64Field(value: &value) - } - - mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { - try decodeRepeatedInt64Field(value: &value) - } - - mutating func decodeSingularBoolField(value: inout Bool) throws { - if scanner.skipOptionalNull() { - value = false - return - } - if isMapKey { - value = try scanner.nextQuotedBool() - } else { - value = try scanner.nextBool() - } - } - - mutating func decodeSingularBoolField(value: inout Bool?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - if isMapKey { - value = try scanner.nextQuotedBool() - } else { - value = try scanner.nextBool() - } - } - - mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextBool() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularStringField(value: inout String) throws { - if scanner.skipOptionalNull() { - value = String() - return - } - value = try scanner.nextQuotedString() - } - - mutating func decodeSingularStringField(value: inout String?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextQuotedString() - } - - mutating func decodeRepeatedStringField(value: inout [String]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextQuotedString() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularBytesField(value: inout Data) throws { - if scanner.skipOptionalNull() { - value = Internal.emptyData - return - } - value = try scanner.nextBytesValue() - } - - mutating func decodeSingularBytesField(value: inout Data?) throws { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextBytesValue() - } - - mutating func decodeRepeatedBytesField(value: inout [Data]) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let n = try scanner.nextBytesValue() - value.append(n) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularEnumField(value: inout E?) throws - where E.RawValue == Int { - if scanner.skipOptionalNull() { - value = nil - return - } - value = try scanner.nextEnumValue() as E - } - - mutating func decodeSingularEnumField(value: inout E) throws - where E.RawValue == Int { - if scanner.skipOptionalNull() { - value = E() - return - } - value = try scanner.nextEnumValue() - } - - mutating func decodeRepeatedEnumField(value: inout [E]) throws - where E.RawValue == Int { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - let e: E = try scanner.nextEnumValue() - value.append(e) - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - internal mutating func decodeFullObject(message: inout M) throws { - guard let nameProviding = (M.self as? _ProtoNameProviding.Type) else { - throw JSONDecodingError.missingFieldNames - } - fieldNameMap = nameProviding._protobuf_nameMap - if let m = message as? _CustomJSONCodable { - var customCodable = m - try customCodable.decodeJSON(from: &self) - message = customCodable as! M - } else { - try scanner.skipRequiredObjectStart() - if scanner.skipOptionalObjectEnd() { - return - } - try message.decodeMessage(decoder: &self) - } - } - - mutating func decodeSingularMessageField(value: inout M?) throws { - if scanner.skipOptionalNull() { - if M.self is _CustomJSONCodable.Type { - value = - try (M.self as! _CustomJSONCodable.Type).decodedFromJSONNull() as? M - return - } - // All other message field types treat 'null' as an unset - value = nil - return - } - if value == nil { - value = M() - } - var subDecoder = JSONDecoder(decoder: self) - try subDecoder.decodeFullObject(message: &value!) - assert(scanner.recursionBudget == subDecoder.scanner.recursionBudget) - scanner = subDecoder.scanner - } - - mutating func decodeRepeatedMessageField( - value: inout [M] - ) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredArrayStart() - if scanner.skipOptionalArrayEnd() { - return - } - while true { - if scanner.skipOptionalNull() { - var appended = false - if M.self is _CustomJSONCodable.Type { - if let message = try (M.self as! _CustomJSONCodable.Type) - .decodedFromJSONNull() as? M { - value.append(message) - appended = true - } - } - if !appended { - throw JSONDecodingError.illegalNull - } - } else { - var message = M() - var subDecoder = JSONDecoder(decoder: self) - try subDecoder.decodeFullObject(message: &message) - value.append(message) - assert(scanner.recursionBudget == subDecoder.scanner.recursionBudget) - scanner = subDecoder.scanner - } - if scanner.skipOptionalArrayEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeSingularGroupField(value: inout G?) throws { - throw JSONDecodingError.schemaMismatch - } - - mutating func decodeRepeatedGroupField(value: inout [G]) throws { - throw JSONDecodingError.schemaMismatch - } - - mutating func decodeMapField( - fieldType: _ProtobufMap.Type, - value: inout _ProtobufMap.BaseType - ) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredObjectStart() - if scanner.skipOptionalObjectEnd() { - return - } - while true { - // Next character must be double quote, because - // map keys must always be quoted strings. - let c = try scanner.peekOneCharacter() - if c != "\"" { - throw JSONDecodingError.unquotedMapKey - } - isMapKey = true - var keyField: KeyType.BaseType? - try KeyType.decodeSingular(value: &keyField, from: &self) - isMapKey = false - try scanner.skipRequiredColon() - var valueField: ValueType.BaseType? - try ValueType.decodeSingular(value: &valueField, from: &self) - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - } else { - throw JSONDecodingError.malformedMap - } - if scanner.skipOptionalObjectEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeMapField( - fieldType: _ProtobufEnumMap.Type, - value: inout _ProtobufEnumMap.BaseType - ) throws where ValueType.RawValue == Int { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredObjectStart() - if scanner.skipOptionalObjectEnd() { - return - } - while true { - // Next character must be double quote, because - // map keys must always be quoted strings. - let c = try scanner.peekOneCharacter() - if c != "\"" { - throw JSONDecodingError.unquotedMapKey - } - isMapKey = true - var keyField: KeyType.BaseType? - try KeyType.decodeSingular(value: &keyField, from: &self) - isMapKey = false - try scanner.skipRequiredColon() - var valueField: ValueType? - try decodeSingularEnumField(value: &valueField) - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - } else { - throw JSONDecodingError.malformedMap - } - if scanner.skipOptionalObjectEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeMapField( - fieldType: _ProtobufMessageMap.Type, - value: inout _ProtobufMessageMap.BaseType - ) throws { - if scanner.skipOptionalNull() { - return - } - try scanner.skipRequiredObjectStart() - if scanner.skipOptionalObjectEnd() { - return - } - while true { - // Next character must be double quote, because - // map keys must always be quoted strings. - let c = try scanner.peekOneCharacter() - if c != "\"" { - throw JSONDecodingError.unquotedMapKey - } - isMapKey = true - var keyField: KeyType.BaseType? - try KeyType.decodeSingular(value: &keyField, from: &self) - isMapKey = false - try scanner.skipRequiredColon() - var valueField: ValueType? - try decodeSingularMessageField(value: &valueField) - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - } else { - throw JSONDecodingError.malformedMap - } - if scanner.skipOptionalObjectEnd() { - return - } - try scanner.skipRequiredComma() - } - } - - mutating func decodeExtensionField( - values: inout ExtensionFieldValueSet, - messageType: Message.Type, - fieldNumber: Int - ) throws { - throw JSONDecodingError.schemaMismatch - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift deleted file mode 100644 index 8008eb0..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingError.swift +++ /dev/null @@ -1,62 +0,0 @@ -// Sources/SwiftProtobuf/JSONDecodingError.swift - JSON decoding errors -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON decoding errors -/// -// ----------------------------------------------------------------------------- - -public enum JSONDecodingError: Error { - /// Something was wrong - case failure - /// A number could not be parsed - case malformedNumber - /// Numeric value was out of range or was not an integer value when expected - case numberRange - /// A map could not be parsed - case malformedMap - /// A bool could not be parsed - case malformedBool - /// We expected a quoted string, or a quoted string has a malformed backslash sequence - case malformedString - /// We encountered malformed UTF8 - case invalidUTF8 - /// The message does not have fieldName information - case missingFieldNames - /// The data type does not match the schema description - case schemaMismatch - /// A value (text or numeric) for an enum was not found on the enum - case unrecognizedEnumValue - /// A 'null' token appeared in an illegal location. - /// For example, Protobuf JSON does not allow 'null' tokens to appear - /// in lists. - case illegalNull - /// A map key was not quoted - case unquotedMapKey - /// JSON RFC 7519 does not allow numbers to have extra leading zeros - case leadingZero - /// We hit the end of the JSON string and expected something more... - case truncated - /// A JSON Duration could not be parsed - case malformedDuration - /// A JSON Timestamp could not be parsed - case malformedTimestamp - /// A FieldMask could not be parsed - case malformedFieldMask - /// Extraneous data remained after decoding should have been complete - case trailingGarbage - /// More than one value was specified for the same oneof field - case conflictingOneOf - /// Reached the nesting limit for messages within messages while decoding. - case messageDepthLimit - /// Encountered an unknown field with the given name. When parsing JSON, you - /// can instead instruct the library to ignore this via - /// JSONDecodingOptions.ignoreUnknownFields. - case unknownField(String) -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift deleted file mode 100644 index da539c5..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONDecodingOptions.swift +++ /dev/null @@ -1,29 +0,0 @@ -// Sources/SwiftProtobuf/JSONDecodingOptions.swift - JSON decoding options -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON decoding options -/// -// ----------------------------------------------------------------------------- - -/// Options for JSONDecoding. -public struct JSONDecodingOptions { - /// The maximum nesting of message with messages. The default is 100. - /// - /// To prevent corrupt or malicious messages from causing stack overflows, - /// this controls how deep messages can be nested within other messages - /// while parsing. - public var messageDepthLimit: Int = 100 - - /// If unknown fields in the JSON should be ignored. If they aren't - /// ignored, an error will be raised if one is encountered. - public var ignoreUnknownFields: Bool = false - - public init() {} -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift deleted file mode 100644 index 7e811b7..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncoder.swift +++ /dev/null @@ -1,370 +0,0 @@ -// Sources/SwiftProtobuf/JSONEncoder.swift - JSON Encoding support -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON serialization engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let asciiZero = UInt8(ascii: "0") -private let asciiOne = UInt8(ascii: "1") -private let asciiTwo = UInt8(ascii: "2") -private let asciiThree = UInt8(ascii: "3") -private let asciiFour = UInt8(ascii: "4") -private let asciiFive = UInt8(ascii: "5") -private let asciiSix = UInt8(ascii: "6") -private let asciiSeven = UInt8(ascii: "7") -private let asciiEight = UInt8(ascii: "8") -private let asciiNine = UInt8(ascii: "9") -private let asciiMinus = UInt8(ascii: "-") -private let asciiPlus = UInt8(ascii: "+") -private let asciiEquals = UInt8(ascii: "=") -private let asciiColon = UInt8(ascii: ":") -private let asciiComma = UInt8(ascii: ",") -private let asciiDoubleQuote = UInt8(ascii: "\"") -private let asciiBackslash = UInt8(ascii: "\\") -private let asciiForwardSlash = UInt8(ascii: "/") -private let asciiOpenSquareBracket = UInt8(ascii: "[") -private let asciiCloseSquareBracket = UInt8(ascii: "]") -private let asciiOpenCurlyBracket = UInt8(ascii: "{") -private let asciiCloseCurlyBracket = UInt8(ascii: "}") -private let asciiUpperA = UInt8(ascii: "A") -private let asciiUpperB = UInt8(ascii: "B") -private let asciiUpperC = UInt8(ascii: "C") -private let asciiUpperD = UInt8(ascii: "D") -private let asciiUpperE = UInt8(ascii: "E") -private let asciiUpperF = UInt8(ascii: "F") -private let asciiUpperZ = UInt8(ascii: "Z") -private let asciiLowerA = UInt8(ascii: "a") -private let asciiLowerZ = UInt8(ascii: "z") - -private let base64Digits: [UInt8] = { - var digits = [UInt8]() - digits.append(contentsOf: asciiUpperA...asciiUpperZ) - digits.append(contentsOf: asciiLowerA...asciiLowerZ) - digits.append(contentsOf: asciiZero...asciiNine) - digits.append(asciiPlus) - digits.append(asciiForwardSlash) - return digits -}() - -private let hexDigits: [UInt8] = { - var digits = [UInt8]() - digits.append(contentsOf: asciiZero...asciiNine) - digits.append(contentsOf: asciiUpperA...asciiUpperF) - return digits -}() - -internal struct JSONEncoder { - private var data = [UInt8]() - private var separator: UInt8? - - internal init() {} - - internal var dataResult: Data { return Data(data) } - - internal var stringResult: String { - get { - return String(bytes: data, encoding: String.Encoding.utf8)! - } - } - - /// Append a `StaticString` to the JSON text. Because - /// `StaticString` is already UTF8 internally, this is faster - /// than appending a regular `String`. - internal mutating func append(staticText: StaticString) { - let buff = UnsafeBufferPointer(start: staticText.utf8Start, count: staticText.utf8CodeUnitCount) - data.append(contentsOf: buff) - } - - /// Append a `_NameMap.Name` to the JSON text surrounded by quotes. - /// As with StaticString above, a `_NameMap.Name` provides pre-converted - /// UTF8 bytes, so this is much faster than appending a regular - /// `String`. - internal mutating func appendQuoted(name: _NameMap.Name) { - data.append(asciiDoubleQuote) - data.append(contentsOf: name.utf8Buffer) - data.append(asciiDoubleQuote) - } - - /// Append a `String` to the JSON text. - internal mutating func append(text: String) { - data.append(contentsOf: text.utf8) - } - - /// Append a raw utf8 in a `Data` to the JSON text. - internal mutating func append(utf8Data: Data) { - data.append(contentsOf: utf8Data) - } - - /// Begin a new field whose name is given as a `_NameMap.Name` - internal mutating func startField(name: _NameMap.Name) { - if let s = separator { - data.append(s) - } - appendQuoted(name: name) - data.append(asciiColon) - separator = asciiComma - } - - /// Begin a new field whose name is given as a `String`. - internal mutating func startField(name: String) { - if let s = separator { - data.append(s) - } - data.append(asciiDoubleQuote) - // Can avoid overhead of putStringValue, since - // the JSON field names are always clean ASCII. - data.append(contentsOf: name.utf8) - append(staticText: "\":") - separator = asciiComma - } - - /// Append an open square bracket `[` to the JSON. - internal mutating func startArray() { - data.append(asciiOpenSquareBracket) - separator = nil - } - - /// Append a close square bracket `]` to the JSON. - internal mutating func endArray() { - data.append(asciiCloseSquareBracket) - separator = asciiComma - } - - /// Append a comma `,` to the JSON. - internal mutating func comma() { - data.append(asciiComma) - } - - /// Append an open curly brace `{` to the JSON. - internal mutating func startObject() { - if let s = separator { - data.append(s) - } - data.append(asciiOpenCurlyBracket) - separator = nil - } - - /// Append a close curly brace `}` to the JSON. - internal mutating func endObject() { - data.append(asciiCloseCurlyBracket) - separator = asciiComma - } - - /// Write a JSON `null` token to the output. - internal mutating func putNullValue() { - append(staticText: "null") - } - - /// Append a float value to the output. - /// This handles Nan and infinite values by - /// writing well-known string values. - internal mutating func putFloatValue(value: Float) { - if value.isNaN { - append(staticText: "\"NaN\"") - } else if !value.isFinite { - if value < 0 { - append(staticText: "\"-Infinity\"") - } else { - append(staticText: "\"Infinity\"") - } - } else { - data.append(contentsOf: value.debugDescription.utf8) - } - } - - /// Append a double value to the output. - /// This handles Nan and infinite values by - /// writing well-known string values. - internal mutating func putDoubleValue(value: Double) { - if value.isNaN { - append(staticText: "\"NaN\"") - } else if !value.isFinite { - if value < 0 { - append(staticText: "\"-Infinity\"") - } else { - append(staticText: "\"Infinity\"") - } - } else { - data.append(contentsOf: value.debugDescription.utf8) - } - } - - /// Append a UInt64 to the output (without quoting). - private mutating func appendUInt(value: UInt64) { - if value >= 10 { - appendUInt(value: value / 10) - } - data.append(asciiZero + UInt8(value % 10)) - } - - /// Append an Int64 to the output (without quoting). - private mutating func appendInt(value: Int64) { - if value < 0 { - data.append(asciiMinus) - // This is the twos-complement negation of value, - // computed in a way that won't overflow a 64-bit - // signed integer. - appendUInt(value: 1 + ~UInt64(bitPattern: value)) - } else { - appendUInt(value: UInt64(bitPattern: value)) - } - } - - /// Write an Enum as an int. - internal mutating func putEnumInt(value: Int) { - appendInt(value: Int64(value)) - } - - /// Write an `Int64` using protobuf JSON quoting conventions. - internal mutating func putInt64(value: Int64) { - data.append(asciiDoubleQuote) - appendInt(value: value) - data.append(asciiDoubleQuote) - } - - /// Write an `Int32` with quoting suitable for - /// using the value as a map key. - internal mutating func putQuotedInt32(value: Int32) { - data.append(asciiDoubleQuote) - appendInt(value: Int64(value)) - data.append(asciiDoubleQuote) - } - - /// Write an `Int32` in the default format. - internal mutating func putInt32(value: Int32) { - appendInt(value: Int64(value)) - } - - /// Write a `UInt64` using protobuf JSON quoting conventions. - internal mutating func putUInt64(value: UInt64) { - data.append(asciiDoubleQuote) - appendUInt(value: value) - data.append(asciiDoubleQuote) - } - - /// Write a `UInt32` with quoting suitable for - /// using the value as a map key. - internal mutating func putQuotedUInt32(value: UInt32) { - data.append(asciiDoubleQuote) - appendUInt(value: UInt64(value)) - data.append(asciiDoubleQuote) - } - - /// Write a `UInt32` in the default format. - internal mutating func putUInt32(value: UInt32) { - appendUInt(value: UInt64(value)) - } - - /// Write a `Bool` with quoting suitable for - /// using the value as a map key. - internal mutating func putQuotedBoolValue(value: Bool) { - data.append(asciiDoubleQuote) - putBoolValue(value: value) - data.append(asciiDoubleQuote) - } - - /// Write a `Bool` in the default format. - internal mutating func putBoolValue(value: Bool) { - if value { - append(staticText: "true") - } else { - append(staticText: "false") - } - } - - /// Append a string value escaping special characters as needed. - internal mutating func putStringValue(value: String) { - data.append(asciiDoubleQuote) - for c in value.unicodeScalars { - switch c.value { - // Special two-byte escapes - case 8: append(staticText: "\\b") - case 9: append(staticText: "\\t") - case 10: append(staticText: "\\n") - case 12: append(staticText: "\\f") - case 13: append(staticText: "\\r") - case 34: append(staticText: "\\\"") - case 92: append(staticText: "\\\\") - case 0...31, 127...159: // Hex form for C0 control chars - append(staticText: "\\u00") - data.append(hexDigits[Int(c.value / 16)]) - data.append(hexDigits[Int(c.value & 15)]) - case 23...126: - data.append(UInt8(truncatingIfNeeded: c.value)) - case 0x80...0x7ff: - data.append(0xc0 + UInt8(truncatingIfNeeded: c.value >> 6)) - data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) - case 0x800...0xffff: - data.append(0xe0 + UInt8(truncatingIfNeeded: c.value >> 12)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) - default: - data.append(0xf0 + UInt8(truncatingIfNeeded: c.value >> 18)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 12) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) - } - } - data.append(asciiDoubleQuote) - } - - /// Append a bytes value using protobuf JSON Base-64 encoding. - internal mutating func putBytesValue(value: Data) { - data.append(asciiDoubleQuote) - if value.count > 0 { - value.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let p = baseAddress.assumingMemoryBound(to: UInt8.self) - - var t: Int = 0 - var bytesInGroup: Int = 0 - for i in 0..> 18) & 63]) - data.append(base64Digits[(t >> 12) & 63]) - data.append(base64Digits[(t >> 6) & 63]) - data.append(base64Digits[t & 63]) - t = 0 - bytesInGroup = 0 - } - t = (t << 8) + Int(p[i]) - bytesInGroup += 1 - } - switch bytesInGroup { - case 3: - data.append(base64Digits[(t >> 18) & 63]) - data.append(base64Digits[(t >> 12) & 63]) - data.append(base64Digits[(t >> 6) & 63]) - data.append(base64Digits[t & 63]) - case 2: - t <<= 8 - data.append(base64Digits[(t >> 18) & 63]) - data.append(base64Digits[(t >> 12) & 63]) - data.append(base64Digits[(t >> 6) & 63]) - data.append(asciiEquals) - case 1: - t <<= 16 - data.append(base64Digits[(t >> 18) & 63]) - data.append(base64Digits[(t >> 12) & 63]) - data.append(asciiEquals) - data.append(asciiEquals) - default: - break - } - } - } - } - data.append(asciiDoubleQuote) - } -} - diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift deleted file mode 100644 index 26f828c..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingError.swift +++ /dev/null @@ -1,35 +0,0 @@ -// Sources/SwiftProtobuf/JSONEncodingError.swift - Error constants -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Enum constants that identify the particular error. -/// -// ----------------------------------------------------------------------------- - -public enum JSONEncodingError: Error { - /// Any fields that were decoded from binary format cannot be - /// re-encoded into JSON unless the object they hold is a - /// well-known type or a type registered with via - /// Google_Protobuf_Any.register() - case anyTranscodeFailure - /// Timestamp values can only be JSON encoded if they hold a value - /// between 0001-01-01Z00:00:00 and 9999-12-31Z23:59:59. - case timestampRange - /// Duration values can only be JSON encoded if they hold a value - /// less than +/- 100 years. - case durationRange - /// Field masks get edited when converting between JSON and protobuf - case fieldMaskConversion - /// Field names were not compiled into the binary - case missingFieldNames - /// Instances of `Google_Protobuf_Value` can only be encoded if they have a - /// valid `kind` (that is, they represent a null value, number, boolean, - /// string, struct, or list). - case missingValue -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift deleted file mode 100644 index 8274e08..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingOptions.swift +++ /dev/null @@ -1,26 +0,0 @@ -// Sources/SwiftProtobuf/JSONEncodingOptions.swift - JSON encoding options -// -// Copyright (c) 2014 - 2018 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON encoding options -/// -// ----------------------------------------------------------------------------- - -/// Options for JSONEncoding. -public struct JSONEncodingOptions { - - /// Always print enums as ints. By default they are printed as strings. - public var alwaysPrintEnumsAsInts: Bool = false - - /// Whether to preserve proto field names. - /// By default they are converted to JSON(lowerCamelCase) names. - public var preserveProtoFieldNames: Bool = false - - public init() {} -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift deleted file mode 100644 index 844bbeb..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONEncodingVisitor.swift +++ /dev/null @@ -1,352 +0,0 @@ -// Sources/SwiftProtobuf/JSONEncodingVisitor.swift - JSON encoding visitor -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Visitor that writes a message in JSON format. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Visitor that serializes a message into JSON format. -internal struct JSONEncodingVisitor: Visitor { - - private var encoder = JSONEncoder() - private var nameMap: _NameMap - private let options: JSONEncodingOptions - - /// The JSON text produced by the visitor, as raw UTF8 bytes. - var dataResult: Data { - return encoder.dataResult - } - - /// The JSON text produced by the visitor, as a String. - internal var stringResult: String { - return encoder.stringResult - } - - /// Creates a new visitor for serializing a message of the given type to JSON - /// format. - init(type: Message.Type, options: JSONEncodingOptions) throws { - if let nameProviding = type as? _ProtoNameProviding.Type { - self.nameMap = nameProviding._protobuf_nameMap - } else { - throw JSONEncodingError.missingFieldNames - } - self.options = options - } - - /// Creates a new visitor that serializes the given message to JSON format. - init(message: Message, options: JSONEncodingOptions) throws { - if let nameProviding = message as? _ProtoNameProviding { - self.nameMap = type(of: nameProviding)._protobuf_nameMap - } else { - throw JSONEncodingError.missingFieldNames - } - self.options = options - } - - mutating func startArray() { - encoder.startArray() - } - - mutating func endArray() { - encoder.endArray() - } - - mutating func startObject() { - encoder.startObject() - } - - mutating func endObject() { - encoder.endObject() - } - - mutating func encodeField(name: String, stringValue value: String) { - encoder.startField(name: name) - encoder.putStringValue(value: value) - } - - mutating func encodeField(name: String, jsonText text: String) { - encoder.startField(name: name) - encoder.append(text: text) - } - - mutating func visitUnknown(bytes: Data) throws { - // JSON encoding has no provision for carrying proto2 unknown fields. - } - - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putFloatValue(value: value) - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putDoubleValue(value: value) - } - - mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putInt32(value: value) - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putInt64(value: value) - } - - mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putUInt32(value: value) - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putUInt64(value: value) - } - - mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putUInt32(value: value) - } - - mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putInt32(value: value) - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putBoolValue(value: value) - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putStringValue(value: value) - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.putBytesValue(value: value) - } - - private mutating func _visitRepeated( - value: [T], - fieldNumber: Int, - encode: (inout JSONEncoder, T) throws -> () - ) throws { - try startField(for: fieldNumber) - var comma = false - encoder.startArray() - for v in value { - if comma { - encoder.comma() - } - comma = true - try encode(&encoder, v) - } - encoder.endArray() - } - - mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { - try startField(for: fieldNumber) - if !options.alwaysPrintEnumsAsInts, let n = value.name { - encoder.appendQuoted(name: n) - } else { - encoder.putEnumInt(value: value.rawValue) - } - } - - mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { - try startField(for: fieldNumber) - let json = try value.jsonUTF8Data(options: options) - encoder.append(utf8Data: json) - } - - mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { - // Google does not serialize groups into JSON - } - - mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Float) in - encoder.putFloatValue(value: v) - } - } - - mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Double) in - encoder.putDoubleValue(value: v) - } - } - - mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Int32) in - encoder.putInt32(value: v) - } - } - - mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Int64) in - encoder.putInt64(value: v) - } - } - - mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: UInt32) in - encoder.putUInt32(value: v) - } - } - - mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: UInt64) in - encoder.putUInt64(value: v) - } - } - - mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { - try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { - try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Bool) in - encoder.putBoolValue(value: v) - } - } - - mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: String) in - encoder.putStringValue(value: v) - } - } - - mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: Data) in - encoder.putBytesValue(value: v) - } - } - - mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - let alwaysPrintEnumsAsInts = options.alwaysPrintEnumsAsInts - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: E) throws in - if !alwaysPrintEnumsAsInts, let n = v.name { - encoder.appendQuoted(name: n) - } else { - encoder.putEnumInt(value: v.rawValue) - } - } - } - - mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { - let localOptions = options - try _visitRepeated(value: value, fieldNumber: fieldNumber) { - (encoder: inout JSONEncoder, v: M) throws in - let json = try v.jsonUTF8Data(options: localOptions) - encoder.append(utf8Data: json) - } - } - - mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { - // Google does not serialize groups into JSON - } - - // Packed fields are handled the same as non-packed fields, so JSON just - // relies on the default implementations in Visitor.swift - - - - mutating func visitMapField(fieldType: _ProtobufMap.Type, value: _ProtobufMap.BaseType, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.append(text: "{") - var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) - for (k,v) in value { - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) - try ValueType.visitSingular(value: v, fieldNumber: 2, with: &mapVisitor) - } - encoder = mapVisitor.encoder - encoder.append(text: "}") - } - - mutating func visitMapField(fieldType: _ProtobufEnumMap.Type, value: _ProtobufEnumMap.BaseType, fieldNumber: Int) throws where ValueType.RawValue == Int { - try startField(for: fieldNumber) - encoder.append(text: "{") - var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) - for (k, v) in value { - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) - try mapVisitor.visitSingularEnumField(value: v, fieldNumber: 2) - } - encoder = mapVisitor.encoder - encoder.append(text: "}") - } - - mutating func visitMapField(fieldType: _ProtobufMessageMap.Type, value: _ProtobufMessageMap.BaseType, fieldNumber: Int) throws { - try startField(for: fieldNumber) - encoder.append(text: "{") - var mapVisitor = JSONMapEncodingVisitor(encoder: encoder, options: options) - for (k,v) in value { - try KeyType.visitSingular(value: k, fieldNumber: 1, with: &mapVisitor) - try mapVisitor.visitSingularMessageField(value: v, fieldNumber: 2) - } - encoder = mapVisitor.encoder - encoder.append(text: "}") - } - - /// Called for each extension range. - mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { - // JSON does not store extensions - } - - /// Helper function that throws an error if the field number could not be - /// resolved. - private mutating func startField(for number: Int) throws { - let name: _NameMap.Name? - - if options.preserveProtoFieldNames { - name = nameMap.names(for: number)?.proto - } else { - name = nameMap.names(for: number)?.json - } - - if let nm = name { - encoder.startField(name: nm) - } else { - throw JSONEncodingError.missingFieldNames - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift deleted file mode 100644 index 319e51d..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift +++ /dev/null @@ -1,174 +0,0 @@ -// Sources/SwiftProtobuf/JSONMapEncodingVisitor.swift - JSON map encoding visitor -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Visitor that writes out the key/value pairs for a JSON map. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Visitor that serializes a message into JSON map format. -/// -/// This expects to alternately visit the keys and values for a JSON -/// map. It only accepts singular values. Keys should be identified -/// as `fieldNumber:1`, values should be identified as `fieldNumber:2` -/// -internal struct JSONMapEncodingVisitor: SelectiveVisitor { - private var separator: StaticString? - internal var encoder: JSONEncoder - private let options: JSONEncodingOptions - - init(encoder: JSONEncoder, options: JSONEncodingOptions) { - self.encoder = encoder - self.options = options - } - - private mutating func startKey() { - if let s = separator { - encoder.append(staticText: s) - } else { - separator = "," - } - } - - private mutating func startValue() { - encoder.append(staticText: ":") - } - - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - // Doubles/Floats can never be map keys, only values - assert(fieldNumber == 2) - startValue() - encoder.putFloatValue(value: value) - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - // Doubles/Floats can never be map keys, only values - assert(fieldNumber == 2) - startValue() - encoder.putDoubleValue(value: value) - } - - mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - encoder.putQuotedInt32(value: value) - } else { - startValue() - encoder.putInt32(value: value) - } - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - } else { - startValue() - } - // Int64 fields are always quoted anyway - encoder.putInt64(value: value) - } - - mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - encoder.putQuotedUInt32(value: value) - } else { - startValue() - encoder.putUInt32(value: value) - } - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - } else { - startValue() - } - encoder.putUInt64(value: value) - } - - mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - try visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - encoder.putQuotedBoolValue(value: value) - } else { - startValue() - encoder.putBoolValue(value: value) - } - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - if fieldNumber == 1 { - startKey() - } else { - startValue() - } - encoder.putStringValue(value: value) - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - // Bytes can only be map values, never keys - assert(fieldNumber == 2) - startValue() - encoder.putBytesValue(value: value) - } - - mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { - // Enums can only be map values, never keys - assert(fieldNumber == 2) - startValue() - if !options.alwaysPrintEnumsAsInts, let n = value.name { - encoder.putStringValue(value: String(describing: n)) - } else { - encoder.putEnumInt(value: value.rawValue) - } - } - - mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { - // Messages can only be map values, never keys - assert(fieldNumber == 2) - startValue() - let json = try value.jsonString(options: options) - encoder.append(text: json) - } - - // SelectiveVisitor will block: - // - single Groups - // - everything repeated - // - everything packed - // - all maps - // - unknown fields - // - extensions -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift deleted file mode 100644 index 20e07c6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/JSONScanner.swift +++ /dev/null @@ -1,1512 +0,0 @@ -// Sources/SwiftProtobuf/JSONScanner.swift - JSON format decoding -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// JSON format decoding engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let asciiBell = UInt8(7) -private let asciiBackspace = UInt8(8) -private let asciiTab = UInt8(9) -private let asciiNewLine = UInt8(10) -private let asciiVerticalTab = UInt8(11) -private let asciiFormFeed = UInt8(12) -private let asciiCarriageReturn = UInt8(13) -private let asciiZero = UInt8(ascii: "0") -private let asciiOne = UInt8(ascii: "1") -private let asciiSeven = UInt8(ascii: "7") -private let asciiNine = UInt8(ascii: "9") -private let asciiColon = UInt8(ascii: ":") -private let asciiPeriod = UInt8(ascii: ".") -private let asciiPlus = UInt8(ascii: "+") -private let asciiComma = UInt8(ascii: ",") -private let asciiSemicolon = UInt8(ascii: ";") -private let asciiDoubleQuote = UInt8(ascii: "\"") -private let asciiSingleQuote = UInt8(ascii: "\'") -private let asciiBackslash = UInt8(ascii: "\\") -private let asciiForwardSlash = UInt8(ascii: "/") -private let asciiHash = UInt8(ascii: "#") -private let asciiEqualSign = UInt8(ascii: "=") -private let asciiUnderscore = UInt8(ascii: "_") -private let asciiQuestionMark = UInt8(ascii: "?") -private let asciiSpace = UInt8(ascii: " ") -private let asciiOpenSquareBracket = UInt8(ascii: "[") -private let asciiCloseSquareBracket = UInt8(ascii: "]") -private let asciiOpenCurlyBracket = UInt8(ascii: "{") -private let asciiCloseCurlyBracket = UInt8(ascii: "}") -private let asciiOpenAngleBracket = UInt8(ascii: "<") -private let asciiCloseAngleBracket = UInt8(ascii: ">") -private let asciiMinus = UInt8(ascii: "-") -private let asciiLowerA = UInt8(ascii: "a") -private let asciiUpperA = UInt8(ascii: "A") -private let asciiLowerB = UInt8(ascii: "b") -private let asciiLowerE = UInt8(ascii: "e") -private let asciiUpperE = UInt8(ascii: "E") -private let asciiLowerF = UInt8(ascii: "f") -private let asciiUpperI = UInt8(ascii: "I") -private let asciiLowerL = UInt8(ascii: "l") -private let asciiLowerN = UInt8(ascii: "n") -private let asciiUpperN = UInt8(ascii: "N") -private let asciiLowerR = UInt8(ascii: "r") -private let asciiLowerS = UInt8(ascii: "s") -private let asciiLowerT = UInt8(ascii: "t") -private let asciiLowerU = UInt8(ascii: "u") -private let asciiLowerZ = UInt8(ascii: "z") -private let asciiUpperZ = UInt8(ascii: "Z") - -private func fromHexDigit(_ c: UnicodeScalar) -> UInt32? { - let n = c.value - if n >= 48 && n <= 57 { - return UInt32(n - 48) - } - switch n { - case 65, 97: return 10 - case 66, 98: return 11 - case 67, 99: return 12 - case 68, 100: return 13 - case 69, 101: return 14 - case 70, 102: return 15 - default: - return nil - } -} - -// Decode both the RFC 4648 section 4 Base 64 encoding and the RFC -// 4648 section 5 Base 64 variant. The section 5 variant is also -// known as "base64url" or the "URL-safe alphabet". -// Note that both "-" and "+" decode to 62 and "/" and "_" both -// decode as 63. -let base64Values: [Int] = [ -/* 0x00 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0x10 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0x20 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, -/* 0x30 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -/* 0x40 */ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -/* 0x50 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -/* 0x60 */ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -/* 0x70 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, -/* 0x80 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0x90 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xa0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xb0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xc0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xd0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xe0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -/* 0xf0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -] - -/// Returns a `Data` value containing bytes equivalent to the given -/// Base64-encoded string, or nil if the conversion fails. -/// -/// Notes on Google's implementation (Base64Unescape() in strutil.cc): -/// * Google's C++ implementation accepts arbitrary whitespace -/// mixed in with the base-64 characters -/// * Google's C++ implementation ignores missing '=' characters -/// but if present, there must be the exact correct number of them. -/// * The conformance test requires us to accept both standard RFC4648 -/// Base 64 encoding and the "URL and Filename Safe Alphabet" variant. -/// -private func parseBytes( - source: UnsafeBufferPointer, - index: inout UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index -) throws -> Data { - let c = source[index] - if c != asciiDoubleQuote { - throw JSONDecodingError.malformedString - } - source.formIndex(after: &index) - - // Count the base-64 digits - // Ignore most unrecognized characters in this first pass, - // stop at the closing double quote. - let digitsStart = index - var rawChars = 0 - var sawSection4Characters = false - var sawSection5Characters = false - while index != end { - var digit = source[index] - if digit == asciiDoubleQuote { - break - } - - if digit == asciiBackslash { - source.formIndex(after: &index) - if index == end { - throw JSONDecodingError.malformedString - } - let escaped = source[index] - switch escaped { - case asciiLowerU: - // TODO: Parse hex escapes such as \u0041. Note that - // such escapes are going to be extremely rare, so - // there's little point in optimizing for them. - throw JSONDecodingError.malformedString - case asciiForwardSlash: - digit = escaped - default: - // Reject \b \f \n \r \t \" or \\ and all illegal escapes - throw JSONDecodingError.malformedString - } - } - - if digit == asciiPlus || digit == asciiForwardSlash { - sawSection4Characters = true - } else if digit == asciiMinus || digit == asciiUnderscore { - sawSection5Characters = true - } - let k = base64Values[Int(digit)] - if k >= 0 { - rawChars += 1 - } - source.formIndex(after: &index) - } - - // We reached the end without seeing the close quote - if index == end { - throw JSONDecodingError.malformedString - } - // Reject mixed encodings. - if sawSection4Characters && sawSection5Characters { - throw JSONDecodingError.malformedString - } - - // Allocate a Data object of exactly the right size - var value = Data(count: rawChars * 3 / 4) - - // Scan the digits again and populate the Data object. - // In this pass, we check for (and fail) if there are - // unexpected characters. But we don't check for end-of-input, - // because the loop above already verified that there was - // a closing double quote. - index = digitsStart - try value.withUnsafeMutableBytes { - (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - var p = baseAddress.assumingMemoryBound(to: UInt8.self) - var n = 0 - var chars = 0 // # chars in current group - var padding = 0 // # padding '=' chars - digits: while true { - let digit = source[index] - var k = base64Values[Int(digit)] - if k < 0 { - switch digit { - case asciiDoubleQuote: - break digits - case asciiBackslash: - source.formIndex(after: &index) - let escaped = source[index] - switch escaped { - case asciiForwardSlash: - k = base64Values[Int(escaped)] - default: - // Note: Invalid backslash escapes were caught - // above; we should never get here. - throw JSONDecodingError.malformedString - } - case asciiSpace: - source.formIndex(after: &index) - continue digits - case asciiEqualSign: // Count padding - while true { - switch source[index] { - case asciiDoubleQuote: - break digits - case asciiSpace: - break - case 61: - padding += 1 - default: // Only '=' and whitespace permitted - throw JSONDecodingError.malformedString - } - source.formIndex(after: &index) - } - default: - throw JSONDecodingError.malformedString - } - } - n <<= 6 - n |= k - chars += 1 - if chars == 4 { - p[0] = UInt8(truncatingIfNeeded: n >> 16) - p[1] = UInt8(truncatingIfNeeded: n >> 8) - p[2] = UInt8(truncatingIfNeeded: n) - p += 3 - chars = 0 - n = 0 - } - source.formIndex(after: &index) - } - switch chars { - case 3: - p[0] = UInt8(truncatingIfNeeded: n >> 10) - p[1] = UInt8(truncatingIfNeeded: n >> 2) - if padding == 1 || padding == 0 { - return - } - case 2: - p[0] = UInt8(truncatingIfNeeded: n >> 4) - if padding == 2 || padding == 0 { - return - } - case 0: - if padding == 0 { - return - } - default: - break - } - throw JSONDecodingError.malformedString - } - } - source.formIndex(after: &index) - return value -} - -// JSON encoding allows a variety of \-escapes, including -// escaping UTF-16 code points (which may be surrogate pairs). -private func decodeString(_ s: String) -> String? { - var out = String.UnicodeScalarView() - var chars = s.unicodeScalars.makeIterator() - while let c = chars.next() { - switch c.value { - case UInt32(asciiBackslash): // backslash - if let escaped = chars.next() { - switch escaped.value { - case UInt32(asciiLowerU): // "\u" - // Exactly 4 hex digits: - if let digit1 = chars.next(), - let d1 = fromHexDigit(digit1), - let digit2 = chars.next(), - let d2 = fromHexDigit(digit2), - let digit3 = chars.next(), - let d3 = fromHexDigit(digit3), - let digit4 = chars.next(), - let d4 = fromHexDigit(digit4) { - let codePoint = ((d1 * 16 + d2) * 16 + d3) * 16 + d4 - if let scalar = UnicodeScalar(codePoint) { - out.append(scalar) - } else if codePoint < 0xD800 || codePoint >= 0xE000 { - // Not a valid Unicode scalar. - return nil - } else if codePoint >= 0xDC00 { - // Low surrogate without a preceding high surrogate. - return nil - } else { - // We have a high surrogate (in the range 0xD800..<0xDC00), so - // verify that it is followed by a low surrogate. - guard chars.next() == "\\", chars.next() == "u" else { - // High surrogate was not followed by a Unicode escape sequence. - return nil - } - if let digit1 = chars.next(), - let d1 = fromHexDigit(digit1), - let digit2 = chars.next(), - let d2 = fromHexDigit(digit2), - let digit3 = chars.next(), - let d3 = fromHexDigit(digit3), - let digit4 = chars.next(), - let d4 = fromHexDigit(digit4) { - let follower = ((d1 * 16 + d2) * 16 + d3) * 16 + d4 - guard 0xDC00 <= follower && follower < 0xE000 else { - // High surrogate was not followed by a low surrogate. - return nil - } - let high = codePoint - 0xD800 - let low = follower - 0xDC00 - let composed = 0x10000 | high << 10 | low - guard let composedScalar = UnicodeScalar(composed) else { - // Composed value is not a valid Unicode scalar. - return nil - } - out.append(composedScalar) - } else { - // Malformed \u escape for low surrogate - return nil - } - } - } else { - // Malformed \u escape - return nil - } - case UInt32(asciiLowerB): // \b - out.append("\u{08}") - case UInt32(asciiLowerF): // \f - out.append("\u{0c}") - case UInt32(asciiLowerN): // \n - out.append("\u{0a}") - case UInt32(asciiLowerR): // \r - out.append("\u{0d}") - case UInt32(asciiLowerT): // \t - out.append("\u{09}") - case UInt32(asciiDoubleQuote), UInt32(asciiBackslash), - UInt32(asciiForwardSlash): // " \ / - out.append(escaped) - default: - return nil // Unrecognized escape - } - } else { - return nil // Input ends with backslash - } - default: - out.append(c) - } - } - return String(out) -} - -/// -/// The basic scanner support is entirely private -/// -/// For performance, it works directly against UTF-8 bytes in memory. -/// -internal struct JSONScanner { - private let source: UnsafeBufferPointer - private var index: UnsafeBufferPointer.Index - private var numberParser = DoubleParser() - internal var recursionLimit: Int - internal var recursionBudget: Int - private var ignoreUnknownFields: Bool - - /// True if the scanner has read all of the data from the source, with the - /// exception of any trailing whitespace (which is consumed by reading this - /// property). - internal var complete: Bool { - mutating get { - skipWhitespace() - return !hasMoreContent - } - } - - /// True if the scanner has not yet reached the end of the source. - private var hasMoreContent: Bool { - return index != source.endIndex - } - - /// The byte (UTF-8 code unit) at the scanner's current position. - private var currentByte: UInt8 { - return source[index] - } - - internal init( - source: UnsafeBufferPointer, - messageDepthLimit: Int, - ignoreUnknownFields: Bool - ) { - self.source = source - self.index = source.startIndex - self.recursionLimit = messageDepthLimit - self.recursionBudget = messageDepthLimit - self.ignoreUnknownFields = ignoreUnknownFields - } - - private mutating func incrementRecursionDepth() throws { - recursionBudget -= 1 - if recursionBudget < 0 { - throw JSONDecodingError.messageDepthLimit - } - } - - private mutating func decrementRecursionDepth() { - recursionBudget += 1 - // This should never happen, if it does, something is probably corrupting memory, and - // simply throwing doesn't make much sense. - if recursionBudget > recursionLimit { - fatalError("Somehow JSONDecoding unwound more objects than it started") - } - } - - /// Advances the scanner to the next position in the source. - private mutating func advance() { - source.formIndex(after: &index) - } - - /// Skip whitespace - private mutating func skipWhitespace() { - while hasMoreContent { - let u = currentByte - switch u { - case asciiSpace, asciiTab, asciiNewLine, asciiCarriageReturn: - advance() - default: - return - } - } - } - - /// Returns (but does not consume) the next non-whitespace - /// character. This is used by google.protobuf.Value, for - /// example, for custom JSON parsing. - internal mutating func peekOneCharacter() throws -> Character { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - return Character(UnicodeScalar(UInt32(currentByte))!) - } - - // Parse the leading UInt64 from the provided utf8 bytes. - // - // This is called in three different situations: - // - // * Unquoted number. - // - // * Simple quoted number. If a number is quoted but has no - // backslashes, the caller can use this directly on the UTF8 by - // just verifying the quote marks. This code returns `nil` if it - // sees a backslash, in which case the caller will need to handle ... - // - // * Complex quoted number. In this case, the caller must parse the - // quoted value as a string, then convert the string to utf8 and - // use this to parse the result. This is slow but fortunately - // rare. - // - // In the common case where the number is written in integer form, - // this code does a simple straight conversion. If the number is in - // floating-point format, this uses a slower and less accurate - // approach: it identifies a substring comprising a float, and then - // uses Double() and UInt64() to convert that string to an unsigned - // integer. In particular, it cannot preserve full 64-bit integer - // values when they are written in floating-point format. - // - // If it encounters a "\" backslash character, it returns a nil. This - // is used by callers that are parsing quoted numbers. See nextSInt() - // and nextUInt() below. - private func parseBareUInt64( - source: UnsafeBufferPointer, - index: inout UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index - ) throws -> UInt64? { - if index == end { - throw JSONDecodingError.truncated - } - let start = index - let c = source[index] - switch c { - case asciiZero: // 0 - source.formIndex(after: &index) - if index != end { - let after = source[index] - switch after { - case asciiZero...asciiNine: // 0...9 - // leading '0' forbidden unless it is the only digit - throw JSONDecodingError.leadingZero - case asciiPeriod, asciiLowerE, asciiUpperE: // . e - // Slow path: JSON numbers can be written in floating-point notation - index = start - if let d = try parseBareDouble(source: source, - index: &index, - end: end) { - if let u = UInt64(exactly: d) { - return u - } - } - throw JSONDecodingError.malformedNumber - case asciiBackslash: - return nil - default: - return 0 - } - } - return 0 - case asciiOne...asciiNine: // 1...9 - var n = 0 as UInt64 - while index != end { - let digit = source[index] - switch digit { - case asciiZero...asciiNine: // 0...9 - let val = UInt64(digit - asciiZero) - if n > UInt64.max / 10 || n * 10 > UInt64.max - val { - throw JSONDecodingError.numberRange - } - source.formIndex(after: &index) - n = n * 10 + val - case asciiPeriod, asciiLowerE, asciiUpperE: // . e - // Slow path: JSON allows floating-point notation for integers - index = start - if let d = try parseBareDouble(source: source, - index: &index, - end: end) { - if let u = UInt64(exactly: d) { - return u - } - } - throw JSONDecodingError.malformedNumber - case asciiBackslash: - return nil - default: - return n - } - } - return n - case asciiBackslash: - return nil - default: - throw JSONDecodingError.malformedNumber - } - } - - // Parse the leading Int64 from the provided utf8. - // - // This uses parseBareUInt64() to do the heavy lifting; - // we just check for a leading minus and negate the result - // as necessary. - // - // As with parseBareUInt64(), if it encounters a "\" backslash - // character, it returns a nil. This allows callers to use this to - // do a "fast-path" decode of simple quoted numbers by parsing the - // UTF8 directly, only falling back to a full String decode when - // absolutely necessary. - private func parseBareSInt64( - source: UnsafeBufferPointer, - index: inout UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index - ) throws -> Int64? { - if index == end { - throw JSONDecodingError.truncated - } - let c = source[index] - if c == asciiMinus { // - - source.formIndex(after: &index) - if index == end { - throw JSONDecodingError.truncated - } - // character after '-' must be digit - let digit = source[index] - if digit < asciiZero || digit > asciiNine { - throw JSONDecodingError.malformedNumber - } - if let n = try parseBareUInt64(source: source, index: &index, end: end) { - let limit: UInt64 = 0x8000000000000000 // -Int64.min - if n >= limit { - if n > limit { - // Too large negative number - throw JSONDecodingError.numberRange - } else { - return Int64.min // Special case for Int64.min - } - } - return -Int64(bitPattern: n) - } else { - return nil - } - } else if let n = try parseBareUInt64(source: source, index: &index, end: end) { - if n > UInt64(bitPattern: Int64.max) { - throw JSONDecodingError.numberRange - } - return Int64(bitPattern: n) - } else { - return nil - } - } - - // Identify a floating-point token in the upcoming UTF8 bytes. - // - // This implements the full grammar defined by the JSON RFC 7159. - // Note that Swift's string-to-number conversions are much more - // lenient, so this is necessary if we want to accurately reject - // malformed JSON numbers. - // - // This is used by nextDouble() and nextFloat() to parse double and - // floating-point values, including values that happen to be in quotes. - // It's also used by the slow path in parseBareSInt64() and parseBareUInt64() - // above to handle integer values that are written in float-point notation. - private func parseBareDouble( - source: UnsafeBufferPointer, - index: inout UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index - ) throws -> Double? { - // RFC 7159 defines the grammar for JSON numbers as: - // number = [ minus ] int [ frac ] [ exp ] - if index == end { - throw JSONDecodingError.truncated - } - let start = index - var c = source[index] - if c == asciiBackslash { - return nil - } - - // Optional leading minus sign - if c == asciiMinus { // - - source.formIndex(after: &index) - if index == end { - index = start - throw JSONDecodingError.truncated - } - c = source[index] - if c == asciiBackslash { - return nil - } - } else if c == asciiUpperN { // Maybe NaN? - // Return nil, let the caller deal with it. - return nil - } - - if c == asciiUpperI { // Maybe Infinity, Inf, -Infinity, or -Inf ? - // Return nil, let the caller deal with it. - return nil - } - - // Integer part can be zero or a series of digits not starting with zero - // int = zero / (digit1-9 *DIGIT) - switch c { - case asciiZero: - // First digit can be zero only if not followed by a digit - source.formIndex(after: &index) - if index == end { - return 0.0 - } - c = source[index] - if c == asciiBackslash { - return nil - } - if c >= asciiZero && c <= asciiNine { - throw JSONDecodingError.leadingZero - } - case asciiOne...asciiNine: - while c >= asciiZero && c <= asciiNine { - source.formIndex(after: &index) - if index == end { - if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { - return d - } else { - throw JSONDecodingError.invalidUTF8 - } - } - c = source[index] - if c == asciiBackslash { - return nil - } - } - default: - // Integer part cannot be empty - throw JSONDecodingError.malformedNumber - } - - // frac = decimal-point 1*DIGIT - if c == asciiPeriod { - source.formIndex(after: &index) - if index == end { - // decimal point must have a following digit - throw JSONDecodingError.truncated - } - c = source[index] - switch c { - case asciiZero...asciiNine: // 0...9 - while c >= asciiZero && c <= asciiNine { - source.formIndex(after: &index) - if index == end { - if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { - return d - } else { - throw JSONDecodingError.invalidUTF8 - } - } - c = source[index] - if c == asciiBackslash { - return nil - } - } - case asciiBackslash: - return nil - default: - // decimal point must be followed by at least one digit - throw JSONDecodingError.malformedNumber - } - } - - // exp = e [ minus / plus ] 1*DIGIT - if c == asciiLowerE || c == asciiUpperE { - source.formIndex(after: &index) - if index == end { - // "e" must be followed by +,-, or digit - throw JSONDecodingError.truncated - } - c = source[index] - if c == asciiBackslash { - return nil - } - if c == asciiPlus || c == asciiMinus { // + - - source.formIndex(after: &index) - if index == end { - // must be at least one digit in exponent - throw JSONDecodingError.truncated - } - c = source[index] - if c == asciiBackslash { - return nil - } - } - switch c { - case asciiZero...asciiNine: - while c >= asciiZero && c <= asciiNine { - source.formIndex(after: &index) - if index == end { - if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { - return d - } else { - throw JSONDecodingError.invalidUTF8 - } - } - c = source[index] - if c == asciiBackslash { - return nil - } - } - default: - // must be at least one digit in exponent - throw JSONDecodingError.malformedNumber - } - } - if let d = numberParser.utf8ToDouble(bytes: source, start: start, end: index) { - return d - } else { - throw JSONDecodingError.invalidUTF8 - } - } - - /// Returns a fully-parsed string with all backslash escapes - /// correctly processed, or nil if next token is not a string. - /// - /// Assumes the leading quote has been verified (but not consumed) - private mutating func parseOptionalQuotedString() -> String? { - // Caller has already asserted that currentByte == quote here - var sawBackslash = false - advance() - let start = index - while hasMoreContent { - switch currentByte { - case asciiDoubleQuote: // " - let s = utf8ToString(bytes: source, start: start, end: index) - advance() - if let t = s { - if sawBackslash { - return decodeString(t) - } else { - return t - } - } else { - return nil // Invalid UTF8 - } - case asciiBackslash: // \ - advance() - guard hasMoreContent else { - return nil // Unterminated escape - } - sawBackslash = true - default: - break - } - advance() - } - return nil // Unterminated quoted string - } - - /// Parse an unsigned integer, whether or not its quoted. - /// This also handles cases such as quoted numbers that have - /// backslash escapes in them. - /// - /// This supports the full range of UInt64 (whether quoted or not) - /// unless the number is written in floating-point format. In that - /// case, we decode it with only Double precision. - internal mutating func nextUInt() throws -> UInt64 { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - if c == asciiDoubleQuote { - let start = index - advance() - if let u = try parseBareUInt64(source: source, - index: &index, - end: source.endIndex) { - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.malformedNumber - } - advance() - return u - } else { - // Couldn't parse because it had a "\" in the string, - // so parse out the quoted string and then reparse - // the result to get a UInt - index = start - let s = try nextQuotedString() - let raw = s.data(using: String.Encoding.utf8)! - let n = try raw.withUnsafeBytes { - (body: UnsafeRawBufferPointer) -> UInt64? in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var index = buffer.startIndex - let end = buffer.endIndex - if let u = try parseBareUInt64(source: buffer, - index: &index, - end: end) { - if index == end { - return u - } - } - } - return nil - } - if let n = n { - return n - } - } - } else if let u = try parseBareUInt64(source: source, - index: &index, - end: source.endIndex) { - return u - } - throw JSONDecodingError.malformedNumber - } - - /// Parse a signed integer, quoted or not, including handling - /// backslash escapes for quoted values. - /// - /// This supports the full range of Int64 (whether quoted or not) - /// unless the number is written in floating-point format. In that - /// case, we decode it with only Double precision. - internal mutating func nextSInt() throws -> Int64 { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - if c == asciiDoubleQuote { - let start = index - advance() - if let s = try parseBareSInt64(source: source, - index: &index, - end: source.endIndex) { - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.malformedNumber - } - advance() - return s - } else { - // Couldn't parse because it had a "\" in the string, - // so parse out the quoted string and then reparse - // the result as an SInt - index = start - let s = try nextQuotedString() - let raw = s.data(using: String.Encoding.utf8)! - let n = try raw.withUnsafeBytes { - (body: UnsafeRawBufferPointer) -> Int64? in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var index = buffer.startIndex - let end = buffer.endIndex - if let s = try parseBareSInt64(source: buffer, - index: &index, - end: end) { - if index == end { - return s - } - } - } - return nil - } - if let n = n { - return n - } - } - } else if let s = try parseBareSInt64(source: source, - index: &index, - end: source.endIndex) { - return s - } - throw JSONDecodingError.malformedNumber - } - - /// Parse the next Float value, regardless of whether it - /// is quoted, including handling backslash escapes for - /// quoted strings. - internal mutating func nextFloat() throws -> Float { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - if c == asciiDoubleQuote { // " - let start = index - advance() - if let d = try parseBareDouble(source: source, - index: &index, - end: source.endIndex) { - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.malformedNumber - } - advance() - return Float(d) - } else { - // Slow Path: parseBareDouble returned nil: It might be - // a valid float, but had something that - // parseBareDouble cannot directly handle. So we reset, - // try a full string parse, then examine the result: - index = start - let s = try nextQuotedString() - switch s { - case "NaN": return Float.nan - case "Inf": return Float.infinity - case "-Inf": return -Float.infinity - case "Infinity": return Float.infinity - case "-Infinity": return -Float.infinity - default: - let raw = s.data(using: String.Encoding.utf8)! - let n = try raw.withUnsafeBytes { - (body: UnsafeRawBufferPointer) -> Float? in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var index = buffer.startIndex - let end = buffer.endIndex - if let d = try parseBareDouble(source: buffer, - index: &index, - end: end) { - let f = Float(d) - if index == end && f.isFinite { - return f - } - } - } - return nil - } - if let n = n { - return n - } - } - } - } else { - if let d = try parseBareDouble(source: source, - index: &index, - end: source.endIndex) { - let f = Float(d) - if f.isFinite { - return f - } - } - } - throw JSONDecodingError.malformedNumber - } - - /// Parse the next Double value, regardless of whether it - /// is quoted, including handling backslash escapes for - /// quoted strings. - internal mutating func nextDouble() throws -> Double { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - if c == asciiDoubleQuote { // " - let start = index - advance() - if let d = try parseBareDouble(source: source, - index: &index, - end: source.endIndex) { - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.malformedNumber - } - advance() - return d - } else { - // Slow Path: parseBareDouble returned nil: It might be - // a valid float, but had something that - // parseBareDouble cannot directly handle. So we reset, - // try a full string parse, then examine the result: - index = start - let s = try nextQuotedString() - switch s { - case "NaN": return Double.nan - case "Inf": return Double.infinity - case "-Inf": return -Double.infinity - case "Infinity": return Double.infinity - case "-Infinity": return -Double.infinity - default: - let raw = s.data(using: String.Encoding.utf8)! - let n = try raw.withUnsafeBytes { - (body: UnsafeRawBufferPointer) -> Double? in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var index = buffer.startIndex - let end = buffer.endIndex - if let d = try parseBareDouble(source: buffer, - index: &index, - end: end) { - if index == end { - return d - } - } - } - return nil - } - if let n = n { - return n - } - } - } - } else { - if let d = try parseBareDouble(source: source, - index: &index, - end: source.endIndex) { - return d - } - } - throw JSONDecodingError.malformedNumber - } - - /// Return the contents of the following quoted string, - /// or throw an error if the next token is not a string. - internal mutating func nextQuotedString() throws -> String { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - if c != asciiDoubleQuote { - throw JSONDecodingError.malformedString - } - if let s = parseOptionalQuotedString() { - return s - } else { - throw JSONDecodingError.malformedString - } - } - - /// Return the contents of the following quoted string, - /// or nil if the next token is not a string. - /// This will only throw an error if the next token starts - /// out as a string but is malformed in some way. - internal mutating func nextOptionalQuotedString() throws -> String? { - skipWhitespace() - guard hasMoreContent else { - return nil - } - let c = currentByte - if c != asciiDoubleQuote { - return nil - } - return try nextQuotedString() - } - - /// Return a Data with the decoded contents of the - /// following base-64 string. - /// - /// Notes on Google's implementation: - /// * Google's C++ implementation accepts arbitrary whitespace - /// mixed in with the base-64 characters - /// * Google's C++ implementation ignores missing '=' characters - /// but if present, there must be the exact correct number of them. - /// * Google's C++ implementation accepts both "regular" and - /// "web-safe" base-64 variants (it seems to prefer the - /// web-safe version as defined in RFC 4648 - internal mutating func nextBytesValue() throws -> Data { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - return try parseBytes(source: source, index: &index, end: source.endIndex) - } - - /// Private function to help parse keywords. - private mutating func skipOptionalKeyword(bytes: [UInt8]) -> Bool { - let start = index - for b in bytes { - guard hasMoreContent else { - index = start - return false - } - let c = currentByte - if c != b { - index = start - return false - } - advance() - } - if hasMoreContent { - let c = currentByte - if (c >= asciiUpperA && c <= asciiUpperZ) || - (c >= asciiLowerA && c <= asciiLowerZ) { - index = start - return false - } - } - return true - } - - /// If the next token is the identifier "null", consume it and return true. - internal mutating func skipOptionalNull() -> Bool { - skipWhitespace() - if hasMoreContent && currentByte == asciiLowerN { - return skipOptionalKeyword(bytes: [ - asciiLowerN, asciiLowerU, asciiLowerL, asciiLowerL - ]) - } - return false - } - - /// Return the following Bool "true" or "false", including - /// full processing of quoted boolean values. (Used in map - /// keys, for instance.) - internal mutating func nextBool() throws -> Bool { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let c = currentByte - switch c { - case asciiLowerF: // f - if skipOptionalKeyword(bytes: [ - asciiLowerF, asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE - ]) { - return false - } - case asciiLowerT: // t - if skipOptionalKeyword(bytes: [ - asciiLowerT, asciiLowerR, asciiLowerU, asciiLowerE - ]) { - return true - } - default: - break - } - throw JSONDecodingError.malformedBool - } - - /// Return the following Bool "true" or "false", including - /// full processing of quoted boolean values. (Used in map - /// keys, for instance.) - internal mutating func nextQuotedBool() throws -> Bool { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.unquotedMapKey - } - if let s = parseOptionalQuotedString() { - switch s { - case "false": return false - case "true": return true - default: break - } - } - throw JSONDecodingError.malformedBool - } - - /// Returns pointer/count spanning the UTF8 bytes of the next regular - /// key or nil if the key contains a backslash (and therefore requires - /// the full string-parsing logic to properly parse). - private mutating func nextOptionalKey() throws -> UnsafeBufferPointer? { - skipWhitespace() - let stringStart = index - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte != asciiDoubleQuote { - return nil - } - advance() - let nameStart = index - while hasMoreContent && currentByte != asciiDoubleQuote { - if currentByte == asciiBackslash { - index = stringStart // Reset to open quote - return nil - } - advance() - } - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let buff = UnsafeBufferPointer( - start: source.baseAddress! + nameStart, - count: index - nameStart) - advance() - return buff - } - - /// Parse a field name, look it up in the provided field name map, - /// and return the corresponding field number. - /// - /// Throws if field name cannot be parsed. - /// If it encounters an unknown field name, it silently skips - /// the value and looks at the following field name. - internal mutating func nextFieldNumber(names: _NameMap) throws -> Int? { - while true { - if let key = try nextOptionalKey() { - // Fast path: We parsed it as UTF8 bytes... - try skipRequiredCharacter(asciiColon) // : - if let fieldNumber = names.number(forJSONName: key) { - return fieldNumber - } - if !ignoreUnknownFields { - let fieldName = utf8ToString(bytes: key.baseAddress!, count: key.count)! - throw JSONDecodingError.unknownField(fieldName) - } - } else { - // Slow path: We parsed a String; lookups from String are slower. - let key = try nextQuotedString() - try skipRequiredCharacter(asciiColon) // : - if let fieldNumber = names.number(forJSONName: key) { - return fieldNumber - } - if !ignoreUnknownFields { - throw JSONDecodingError.unknownField(key) - } - } - // Unknown field, skip it and try to parse the next field name - try skipValue() - if skipOptionalObjectEnd() { - return nil - } - try skipRequiredComma() - } - } - - /// Parse the next token as a string or numeric enum value. Throws - /// unrecognizedEnumValue if the string/number can't initialize the - /// enum. Will throw other errors if the JSON is malformed. - internal mutating func nextEnumValue() throws -> E { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - if currentByte == asciiDoubleQuote { - if let name = try nextOptionalKey() { - if let e = E(rawUTF8: name) { - return e - } else { - throw JSONDecodingError.unrecognizedEnumValue - } - } - let name = try nextQuotedString() - if let e = E(name: name) { - return e - } else { - throw JSONDecodingError.unrecognizedEnumValue - } - } else { - let n = try nextSInt() - if let i = Int(exactly: n) { - if let e = E(rawValue: i) { - return e - } else { - throw JSONDecodingError.unrecognizedEnumValue - } - } else { - throw JSONDecodingError.numberRange - } - } - } - - /// Helper for skipping a single-character token. - private mutating func skipRequiredCharacter(_ required: UInt8) throws { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - let next = currentByte - if next == required { - advance() - return - } - throw JSONDecodingError.failure - } - - /// Skip "{", throw if that's not the next character - internal mutating func skipRequiredObjectStart() throws { - try skipRequiredCharacter(asciiOpenCurlyBracket) // { - try incrementRecursionDepth() - } - - /// Skip ",", throw if that's not the next character - internal mutating func skipRequiredComma() throws { - try skipRequiredCharacter(asciiComma) - } - - /// Skip ":", throw if that's not the next character - internal mutating func skipRequiredColon() throws { - try skipRequiredCharacter(asciiColon) - } - - /// Skip "[", throw if that's not the next character - internal mutating func skipRequiredArrayStart() throws { - try skipRequiredCharacter(asciiOpenSquareBracket) // [ - } - - /// Helper for skipping optional single-character tokens - private mutating func skipOptionalCharacter(_ c: UInt8) -> Bool { - skipWhitespace() - if hasMoreContent && currentByte == c { - advance() - return true - } - return false - } - - /// If the next non-whitespace character is "]", skip it - /// and return true. Otherwise, return false. - internal mutating func skipOptionalArrayEnd() -> Bool { - return skipOptionalCharacter(asciiCloseSquareBracket) // ] - } - - /// If the next non-whitespace character is "}", skip it - /// and return true. Otherwise, return false. - internal mutating func skipOptionalObjectEnd() -> Bool { - let result = skipOptionalCharacter(asciiCloseCurlyBracket) // } - if result { - decrementRecursionDepth() - } - return result - } - - /// Return the next complete JSON structure as a string. - /// For example, this might return "true", or "123.456", - /// or "{\"foo\": 7, \"bar\": [8, 9]}" - /// - /// Used by Any to get the upcoming JSON value as a string. - /// Note: The value might be an object or array. - internal mutating func skip() throws -> String { - skipWhitespace() - let start = index - try skipValue() - if let s = utf8ToString(bytes: source, start: start, end: index) { - return s - } else { - throw JSONDecodingError.invalidUTF8 - } - } - - /// Advance index past the next value. This is used - /// by skip() and by unknown field handling. - private mutating func skipValue() throws { - skipWhitespace() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - switch currentByte { - case asciiDoubleQuote: // " begins a string - try skipString() - case asciiOpenCurlyBracket: // { begins an object - try skipObject() - case asciiOpenSquareBracket: // [ begins an array - try skipArray() - case asciiLowerN: // n must be null - if !skipOptionalKeyword(bytes: [ - asciiLowerN, asciiLowerU, asciiLowerL, asciiLowerL - ]) { - throw JSONDecodingError.truncated - } - case asciiLowerF: // f must be false - if !skipOptionalKeyword(bytes: [ - asciiLowerF, asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE - ]) { - throw JSONDecodingError.truncated - } - case asciiLowerT: // t must be true - if !skipOptionalKeyword(bytes: [ - asciiLowerT, asciiLowerR, asciiLowerU, asciiLowerE - ]) { - throw JSONDecodingError.truncated - } - default: // everything else is a number token - _ = try nextDouble() - } - } - - /// Advance the index past the next complete {...} construct. - private mutating func skipObject() throws { - try skipRequiredObjectStart() - if skipOptionalObjectEnd() { - return - } - while true { - skipWhitespace() - try skipString() - try skipRequiredColon() - try skipValue() - if skipOptionalObjectEnd() { - return - } - try skipRequiredComma() - } - } - - /// Advance the index past the next complete [...] construct. - private mutating func skipArray() throws { - try skipRequiredArrayStart() - if skipOptionalArrayEnd() { - return - } - while true { - try skipValue() - if skipOptionalArrayEnd() { - return - } - try skipRequiredComma() - } - } - - /// Advance the index past the next complete quoted string. - /// - // Caveat: This does not fully validate; it will accept - // strings that have malformed \ escapes. - // - // It would be nice to do better, but I don't think it's critical, - // since there are many reasons that strings (and other tokens for - // that matter) may be skippable but not parseable. For example: - // Old clients that don't know new field types will skip fields - // they don't know; newer clients may reject the same input due to - // schema mismatches or other issues. - private mutating func skipString() throws { - if currentByte != asciiDoubleQuote { - throw JSONDecodingError.malformedString - } - advance() - while hasMoreContent { - let c = currentByte - switch c { - case asciiDoubleQuote: - advance() - return - case asciiBackslash: - advance() - guard hasMoreContent else { - throw JSONDecodingError.truncated - } - advance() - default: - advance() - } - } - throw JSONDecodingError.truncated - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift deleted file mode 100644 index 6ae9b1c..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MathUtils.swift +++ /dev/null @@ -1,40 +0,0 @@ -// Sources/SwiftProtobuf/MathUtils.swift - Generally useful mathematical functions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Generally useful mathematical and arithmetic functions. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Remainder in standard modular arithmetic (modulo). This coincides with (%) -/// when a > 0. -/// -/// - Parameters: -/// - a: The dividend. Can be positive, 0 or negative. -/// - b: The divisor. This must be positive, and is an error if 0 or negative. -/// - Returns: The unique value r such that 0 <= r < b and b * q + r = a for some q. -internal func mod(_ a: T, _ b: T) -> T { - assert(b > 0) - let r = a % b - return r >= 0 ? r : r + b -} - -/// Quotient in standard modular arithmetic (Euclidean division). This coincides -/// with (/) when a > 0. -/// -/// - Parameters: -/// - a: The dividend. Can be positive, 0 or negative. -/// - b: The divisor. This must be positive, and is an error if 0 or negative. -/// - Returns: The unique value q such that for some 0 <= r < b, b * q + r = a. -internal func div(_ a: T, _ b: T) -> T { - assert(b > 0) - return a >= 0 ? a / b : (a + 1) / b - 1 -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift deleted file mode 100644 index 7023d64..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+AnyAdditions.swift +++ /dev/null @@ -1,45 +0,0 @@ -// Sources/SwiftProtobuf/Message+AnyAdditions.swift - Any-related Message extensions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extends the `Message` type with `Google_Protobuf_Any`-specific behavior. -/// -// ----------------------------------------------------------------------------- - -extension Message { - /// Initialize this message from the provided `google.protobuf.Any` - /// well-known type. - /// - /// This corresponds to the `unpack` method in the Google C++ API. - /// - /// If the Any object was decoded from Protobuf Binary or JSON - /// format, then the enclosed field data was stored and is not - /// fully decoded until you unpack the Any object into a message. - /// As such, this method will typically need to perform a full - /// deserialization of the enclosed data and can fail for any - /// reason that deserialization can fail. - /// - /// See `Google_Protobuf_Any.unpackTo()` for more discussion. - /// - /// - Parameter unpackingAny: the message to decode. - /// - Parameter extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - Parameter options: The BinaryDecodingOptions to use. - /// - Throws: an instance of `AnyUnpackError`, `JSONDecodingError`, or - /// `BinaryDecodingError` on failure. - public init( - unpackingAny: Google_Protobuf_Any, - extensions: ExtensionMap? = nil, - options: BinaryDecodingOptions = BinaryDecodingOptions() - ) throws { - self.init() - try unpackingAny._storage.unpackTo(target: &self, extensions: extensions, options: options) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift deleted file mode 100644 index dd57617..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+BinaryAdditions.swift +++ /dev/null @@ -1,126 +0,0 @@ -// Sources/SwiftProtobuf/Message+BinaryAdditions.swift - Per-type binary coding -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extensions to `Message` to provide binary coding and decoding. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Binary encoding and decoding methods for messages. -extension Message { - /// Returns a `Data` value containing the Protocol Buffer binary format - /// serialization of the message. - /// - /// - Parameters: - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - Returns: A `Data` value containing the binary serialization of the - /// message. - /// - Throws: `BinaryEncodingError` if encoding fails. - public func serializedData(partial: Bool = false) throws -> Data { - if !partial && !isInitialized { - throw BinaryEncodingError.missingRequiredFields - } - let requiredSize = try serializedDataSize() - var data = Data(count: requiredSize) - try data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - - var visitor = BinaryEncodingVisitor(forWritingInto: pointer) - try traverse(visitor: &visitor) - // Currently not exposing this from the api because it really would be - // an internal error in the library and should never happen. - assert(requiredSize == visitor.encoder.distance(pointer: pointer)) - } - } - return data - } - - /// Returns the size in bytes required to encode the message in binary format. - /// This is used by `serializedData()` to precalculate the size of the buffer - /// so that encoding can proceed without bounds checks or reallocation. - internal func serializedDataSize() throws -> Int { - // Note: since this api is internal, it doesn't currently worry about - // needing a partial argument to handle proto2 syntax required fields. - // If this become public, it will need that added. - var visitor = BinaryEncodingSizeVisitor() - try traverse(visitor: &visitor) - return visitor.serializedSize - } - - /// Creates a new message by decoding the given `Data` value containing a - /// serialized message in Protocol Buffer binary format. - /// - /// - Parameters: - /// - serializedData: The binary-encoded message data to decode. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - options: The BinaryDecodingOptions to use. - /// - Throws: `BinaryDecodingError` if decoding fails. - public init( - serializedData data: Data, - extensions: ExtensionMap? = nil, - partial: Bool = false, - options: BinaryDecodingOptions = BinaryDecodingOptions() - ) throws { - self.init() - try merge(serializedData: data, extensions: extensions, partial: partial, options: options) - } - - /// Updates the message by decoding the given `Data` value containing a - /// serialized message in Protocol Buffer binary format into the receiver. - /// - /// - Note: If this method throws an error, the message may still have been - /// partially mutated by the binary data that was decoded before the error - /// occurred. - /// - /// - Parameters: - /// - serializedData: The binary-encoded message data to decode. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - partial: If `false` (the default), this method will check - /// `Message.isInitialized` before encoding to verify that all required - /// fields are present. If any are missing, this method throws - /// `BinaryEncodingError.missingRequiredFields`. - /// - options: The BinaryDecodingOptions to use. - /// - Throws: `BinaryDecodingError` if decoding fails. - public mutating func merge( - serializedData data: Data, - extensions: ExtensionMap? = nil, - partial: Bool = false, - options: BinaryDecodingOptions = BinaryDecodingOptions() - ) throws { - if !data.isEmpty { - try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let pointer = baseAddress.assumingMemoryBound(to: UInt8.self) - var decoder = BinaryDecoder(forReadingFrom: pointer, - count: body.count, - options: options, - extensions: extensions) - try decoder.decodeFullMessage(message: &self) - } - } - } - if !partial && !isInitialized { - throw BinaryDecodingError.missingRequiredFields - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift deleted file mode 100644 index 4982d18..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift +++ /dev/null @@ -1,117 +0,0 @@ -// Sources/SwiftProtobuf/Message+JSONAdditions.swift - JSON format primitive types -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extensions to `Message` to support JSON encoding/decoding. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// JSON encoding and decoding methods for messages. -extension Message { - /// Returns a string containing the JSON serialization of the message. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to JSON. - /// - /// - Returns: A string containing the JSON serialization of the message. - /// - Parameters: - /// - options: The JSONEncodingOptions to use. - /// - Throws: `JSONEncodingError` if encoding fails. - public func jsonString( - options: JSONEncodingOptions = JSONEncodingOptions() - ) throws -> String { - let data = try jsonUTF8Data(options: options) - return String(data: data, encoding: String.Encoding.utf8)! - } - - /// Returns a Data containing the UTF-8 JSON serialization of the message. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to JSON. - /// - /// - Returns: A Data containing the JSON serialization of the message. - /// - Parameters: - /// - options: The JSONEncodingOptions to use. - /// - Throws: `JSONEncodingError` if encoding fails. - public func jsonUTF8Data( - options: JSONEncodingOptions = JSONEncodingOptions() - ) throws -> Data { - if let m = self as? _CustomJSONCodable { - let string = try m.encodedJSONString(options: options) - let data = string.data(using: String.Encoding.utf8)! // Cannot fail! - return data - } - var visitor = try JSONEncodingVisitor(message: self, options: options) - visitor.startObject() - try traverse(visitor: &visitor) - visitor.endObject() - return visitor.dataResult - } - - /// Creates a new message by decoding the given string containing a - /// serialized message in JSON format. - /// - /// - Parameter jsonString: The JSON-formatted string to decode. - /// - Parameter options: The JSONDecodingOptions to use. - /// - Throws: `JSONDecodingError` if decoding fails. - public init( - jsonString: String, - options: JSONDecodingOptions = JSONDecodingOptions() - ) throws { - if jsonString.isEmpty { - throw JSONDecodingError.truncated - } - if let data = jsonString.data(using: String.Encoding.utf8) { - try self.init(jsonUTF8Data: data, options: options) - } else { - throw JSONDecodingError.truncated - } - } - - /// Creates a new message by decoding the given `Data` containing a - /// serialized message in JSON format, interpreting the data as UTF-8 encoded - /// text. - /// - /// - Parameter jsonUTF8Data: The JSON-formatted data to decode, represented - /// as UTF-8 encoded text. - /// - Parameter options: The JSONDecodingOptions to use. - /// - Throws: `JSONDecodingError` if decoding fails. - public init( - jsonUTF8Data: Data, - options: JSONDecodingOptions = JSONDecodingOptions() - ) throws { - self.init() - try jsonUTF8Data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var decoder = JSONDecoder(source: buffer, options: options) - if !decoder.scanner.skipOptionalNull() { - try decoder.decodeFullObject(message: &self) - } else if Self.self is _CustomJSONCodable.Type { - if let message = try (Self.self as! _CustomJSONCodable.Type) - .decodedFromJSONNull() { - self = message as! Self - } else { - throw JSONDecodingError.illegalNull - } - } else { - throw JSONDecodingError.illegalNull - } - if !decoder.scanner.complete { - throw JSONDecodingError.trailingGarbage - } - } - } - } -} - diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift deleted file mode 100644 index 38bf9f3..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift +++ /dev/null @@ -1,111 +0,0 @@ -// Sources/SwiftProtobuf/Array+JSONAdditions.swift - JSON format primitive types -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extensions to `Array` to support JSON encoding/decoding. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// JSON encoding and decoding methods for arrays of messages. -extension Message { - /// Returns a string containing the JSON serialization of the messages. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to JSON. - /// - /// - Returns: A string containing the JSON serialization of the messages. - /// - Parameters: - /// - collection: The list of messages to encode. - /// - options: The JSONEncodingOptions to use. - /// - Throws: `JSONEncodingError` if encoding fails. - public static func jsonString( - from collection: C, - options: JSONEncodingOptions = JSONEncodingOptions() - ) throws -> String where C.Iterator.Element == Self { - let data = try jsonUTF8Data(from: collection, options: options) - return String(data: data, encoding: String.Encoding.utf8)! - } - - /// Returns a Data containing the UTF-8 JSON serialization of the messages. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to JSON. - /// - /// - Returns: A Data containing the JSON serialization of the messages. - /// - Parameters: - /// - collection: The list of messages to encode. - /// - options: The JSONEncodingOptions to use. - /// - Throws: `JSONEncodingError` if encoding fails. - public static func jsonUTF8Data( - from collection: C, - options: JSONEncodingOptions = JSONEncodingOptions() - ) throws -> Data where C.Iterator.Element == Self { - var visitor = try JSONEncodingVisitor(type: Self.self, options: options) - visitor.startArray() - for message in collection { - visitor.startObject() - try message.traverse(visitor: &visitor) - visitor.endObject() - } - visitor.endArray() - return visitor.dataResult - } - - /// Creates a new array of messages by decoding the given string containing a - /// serialized array of messages in JSON format. - /// - /// - Parameter jsonString: The JSON-formatted string to decode. - /// - Parameter options: The JSONDecodingOptions to use. - /// - Throws: `JSONDecodingError` if decoding fails. - public static func array( - fromJSONString jsonString: String, - options: JSONDecodingOptions = JSONDecodingOptions() - ) throws -> [Self] { - if jsonString.isEmpty { - throw JSONDecodingError.truncated - } - if let data = jsonString.data(using: String.Encoding.utf8) { - return try array(fromJSONUTF8Data: data, options: options) - } else { - throw JSONDecodingError.truncated - } - } - - /// Creates a new array of messages by decoding the given `Data` containing a - /// serialized array of messages in JSON format, interpreting the data as - /// UTF-8 encoded text. - /// - /// - Parameter jsonUTF8Data: The JSON-formatted data to decode, represented - /// as UTF-8 encoded text. - /// - Parameter options: The JSONDecodingOptions to use. - /// - Throws: `JSONDecodingError` if decoding fails. - public static func array( - fromJSONUTF8Data jsonUTF8Data: Data, - options: JSONDecodingOptions = JSONDecodingOptions() - ) throws -> [Self] { - return try jsonUTF8Data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - var array = [Self]() - - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - let buffer = UnsafeBufferPointer(start: bytes, count: body.count) - var decoder = JSONDecoder(source: buffer, options: options) - try decoder.decodeRepeatedMessageField(value: &array) - if !decoder.scanner.complete { - throw JSONDecodingError.trailingGarbage - } - } - - return array - } - } - -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift deleted file mode 100644 index 19b8370..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift +++ /dev/null @@ -1,89 +0,0 @@ -// Sources/SwiftProtobuf/Message+TextFormatAdditions.swift - Text format primitive types -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Extensions to `Message` to support text format encoding/decoding. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Text format encoding and decoding methods for messages. -extension Message { - /// Returns a string containing the Protocol Buffer text format serialization - /// of the message. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to text format. - /// - /// - Returns: A string containing the text format serialization of the - /// message. - public func textFormatString() -> String { - // This is implemented as a separate zero-argument function - // to preserve binary compatibility. - return textFormatString(options: TextFormatEncodingOptions()) - } - - /// Returns a string containing the Protocol Buffer text format serialization - /// of the message. - /// - /// Unlike binary encoding, presence of required fields is not enforced when - /// serializing to JSON. - /// - /// - Returns: A string containing the text format serialization of the message. - /// - Parameters: - /// - options: The TextFormatEncodingOptions to use. - public func textFormatString( - options: TextFormatEncodingOptions - ) -> String { - var visitor = TextFormatEncodingVisitor(message: self, options: options) - if let any = self as? Google_Protobuf_Any { - any._storage.textTraverse(visitor: &visitor) - } else { - // Although the general traversal/encoding infrastructure supports - // throwing errors (needed for JSON/Binary WKTs support, binary format - // missing required fields); TextEncoding never actually does throw. - try! traverse(visitor: &visitor) - } - return visitor.result - } - - /// Creates a new message by decoding the given string containing a - /// serialized message in Protocol Buffer text format. - /// - /// - Parameters: - /// - textFormatString: The text format string to decode. - /// - extensions: An `ExtensionMap` used to look up and decode any - /// extensions in this message or messages nested within this message's - /// fields. - /// - Throws: an instance of `TextFormatDecodingError` on failure. - public init( - textFormatString: String, - extensions: ExtensionMap? = nil - ) throws { - self.init() - if !textFormatString.isEmpty { - if let data = textFormatString.data(using: String.Encoding.utf8) { - try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let bytes = baseAddress.assumingMemoryBound(to: UInt8.self) - var decoder = try TextFormatDecoder(messageType: Self.self, - utf8Pointer: bytes, - count: body.count, - extensions: extensions) - try decodeMessage(decoder: &decoder) - if !decoder.complete { - throw TextFormatDecodingError.trailingGarbage - } - } - } - } - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift deleted file mode 100644 index b6b9b3b..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Message.swift +++ /dev/null @@ -1,216 +0,0 @@ -// Sources/SwiftProtobuf/Message.swift - Message support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// - -/// The protocol which all generated protobuf messages implement. -/// `Message` is the protocol type you should use whenever -/// you need an argument or variable which holds "some message". -/// -/// Generated messages also implement `Hashable`, and thus `Equatable`. -/// However, the protocol conformance is declared on a different protocol. -/// This allows you to use `Message` as a type directly: -/// -/// func consume(message: Message) { ... } -/// -/// Instead of needing to use it as a type constraint on a generic declaration: -/// -/// func consume(message: M) { ... } -/// -/// If you need to convince the compiler that your message is `Hashable` so -/// you can insert it into a `Set` or use it as a `Dictionary` key, use -/// a generic declaration with a type constraint: -/// -/// func insertIntoSet(message: M) { -/// mySet.insert(message) -/// } -/// -/// The actual functionality is implemented either in the generated code or in -/// default implementations of the below methods and properties. -public protocol Message: CustomDebugStringConvertible { - /// Creates a new message with all of its fields initialized to their default - /// values. - init() - - // Metadata - // Basic facts about this class and the proto message it was generated from - // Used by various encoders and decoders - - /// The fully-scoped name of the message from the original .proto file, - /// including any relevant package name. - static var protoMessageName: String { get } - - /// True if all required fields (if any) on this message and any nested - /// messages (recursively) have values set; otherwise, false. - var isInitialized: Bool { get } - - /// Some formats include enough information to transport fields that were - /// not known at generation time. When encountered, they are stored here. - var unknownFields: UnknownStorage { get set } - - // - // General serialization/deserialization machinery - // - - /// Decode all of the fields from the given decoder. - /// - /// This is a simple loop that repeatedly gets the next field number - /// from `decoder.nextFieldNumber()` and then uses the number returned - /// and the type information from the original .proto file to decide - /// what type of data should be decoded for that field. The corresponding - /// method on the decoder is then called to get the field value. - /// - /// This is the core method used by the deserialization machinery. It is - /// `public` to enable users to implement their own encoding formats by - /// conforming to `Decoder`; it should not be called otherwise. - /// - /// Note that this is not specific to binary encodng; formats that use - /// textual identifiers translate those to field numbers and also go - /// through this to decode messages. - /// - /// - Parameters: - /// - decoder: a `Decoder`; the `Message` will call the method - /// corresponding to the type of this field. - /// - Throws: an error on failure or type mismatch. The type of error - /// thrown depends on which decoder is used. - mutating func decodeMessage(decoder: inout D) throws - - /// Traverses the fields of the message, calling the appropriate methods - /// of the passed `Visitor` object. - /// - /// This is used internally by: - /// - /// * Protobuf binary serialization - /// * JSON serialization (with some twists to account for specialty JSON) - /// * Protobuf Text serialization - /// * `Hashable` computation - /// - /// Conceptually, serializers create visitor objects that are - /// then passed recursively to every message and field via generated - /// `traverse` methods. The details get a little involved due to - /// the need to allow particular messages to override particular - /// behaviors for specific encodings, but the general idea is quite simple. - func traverse(visitor: inout V) throws - - // Standard utility properties and methods. - // Most of these are simple wrappers on top of the visitor machinery. - // They are implemented in the protocol, not in the generated structs, - // so can be overridden in user code by defining custom extensions to - // the generated struct. - -#if swift(>=4.2) - /// An implementation of hash(into:) to provide conformance with the - /// `Hashable` protocol. - func hash(into hasher: inout Hasher) -#else // swift(>=4.2) - /// The hash value generated from this message's contents, for conformance - /// with the `Hashable` protocol. - var hashValue: Int { get } -#endif // swift(>=4.2) - - /// Helper to compare `Message`s when not having a specific type to use - /// normal `Equatable`. `Equatable` is provided with specific generated - /// types. - func isEqualTo(message: Message) -> Bool -} - -extension Message { - /// Generated proto2 messages that contain required fields, nested messages - /// that contain required fields, and/or extensions will provide their own - /// implementation of this property that tests that all required fields are - /// set. Users of the generated code SHOULD NOT override this property. - public var isInitialized: Bool { - // The generated code will include a specialization as needed. - return true - } - - /// A hash based on the message's full contents. -#if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - var visitor = HashVisitor(hasher) - try? traverse(visitor: &visitor) - hasher = visitor.hasher - } -#else // swift(>=4.2) - public var hashValue: Int { - var visitor = HashVisitor() - try? traverse(visitor: &visitor) - return visitor.hashValue - } -#endif // swift(>=4.2) - - /// A description generated by recursively visiting all fields in the message, - /// including messages. - public var debugDescription: String { - // TODO Ideally there would be something like serializeText() that can - // take a prefix so we could do something like: - // [class name]( - // [text format] - // ) - let className = String(reflecting: type(of: self)) - let header = "\(className):\n" - return header + textFormatString() - } - - /// Creates an instance of the message type on which this method is called, - /// executes the given block passing the message in as its sole `inout` - /// argument, and then returns the message. - /// - /// This method acts essentially as a "builder" in that the initialization of - /// the message is captured within the block, allowing the returned value to - /// be set in an immutable variable. For example, - /// - /// let msg = MyMessage.with { $0.myField = "foo" } - /// msg.myOtherField = 5 // error: msg is immutable - /// - /// - Parameter populator: A block or function that populates the new message, - /// which is passed into the block as an `inout` argument. - /// - Returns: The message after execution of the block. - public static func with( - _ populator: (inout Self) throws -> () - ) rethrows -> Self { - var message = Self() - try populator(&message) - return message - } -} - -/// Implementation base for all messages; not intended for client use. -/// -/// In general, use `SwiftProtobuf.Message` instead when you need a variable or -/// argument that can hold any type of message. Occasionally, you can use -/// `SwiftProtobuf.Message & Equatable` or `SwiftProtobuf.Message & Hashable` as -/// generic constraints if you need to write generic code that can be applied to -/// multiple message types that uses equality tests, puts messages in a `Set`, -/// or uses them as `Dictionary` keys. -public protocol _MessageImplementationBase: Message, Hashable { - - // Legacy function; no longer used, but left to maintain source compatibility. - func _protobuf_generated_isEqualTo(other: Self) -> Bool -} - -extension _MessageImplementationBase { - public func isEqualTo(message: Message) -> Bool { - guard let other = message as? Self else { - return false - } - return self == other - } - - // Legacy default implementation that is used by old generated code, current - // versions of the plugin/generator provide this directly, but this is here - // just to avoid breaking source compatibility. - public static func ==(lhs: Self, rhs: Self) -> Bool { - return lhs._protobuf_generated_isEqualTo(other: rhs) - } - - // Legacy function that is generated by old versions of the plugin/generator, - // defaulted to keep things simple without changing the api surface. - public func _protobuf_generated_isEqualTo(other: Self) -> Bool { - return self == other - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift deleted file mode 100644 index 42c75da..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/MessageExtension.swift +++ /dev/null @@ -1,41 +0,0 @@ -// Sources/SwiftProtobuf/MessageExtension.swift - Extension support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A 'Message Extension' is an immutable class object that describes -/// a particular extension field, including string and number -/// identifiers, serialization details, and the identity of the -/// message that is being extended. -/// -// ----------------------------------------------------------------------------- - -/// Type-erased MessageExtension field implementation. -public protocol AnyMessageExtension { - var fieldNumber: Int { get } - var fieldName: String { get } - var messageType: Message.Type { get } - func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? -} - -/// A "Message Extension" relates a particular extension field to -/// a particular message. The generic constraints allow -/// compile-time compatibility checks. -public class MessageExtension: AnyMessageExtension { - public let fieldNumber: Int - public let fieldName: String - public let messageType: Message.Type - public init(_protobuf_fieldNumber: Int, fieldName: String) { - self.fieldNumber = _protobuf_fieldNumber - self.fieldName = fieldName - self.messageType = MessageType.self - } - public func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? { - return try FieldType(protobufExtension: self, decoder: &decoder) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift deleted file mode 100644 index 3405ebe..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/NameMap.swift +++ /dev/null @@ -1,286 +0,0 @@ -// Sources/SwiftProtobuf/NameMap.swift - Bidirectional number/name mapping -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- - -/// TODO: Right now, only the NameMap and the NameDescription enum -/// (which are directly used by the generated code) are public. -/// This means that code outside the library has no way to actually -/// use this data. We should develop and publicize a suitable API -/// for that purpose. (Which might be the same as the internal API.) - -/// This must be exactly the same as the corresponding code in the -/// protoc-gen-swift code generator. Changing it will break -/// compatibility of the library with older generated code. -/// -/// It does not necessarily need to match protoc's JSON field naming -/// logic, however. -private func toJsonFieldName(_ s: String) -> String { - var result = String() - var capitalizeNext = false - for c in s { - if c == "_" { - capitalizeNext = true - } else if capitalizeNext { - result.append(String(c).uppercased()) - capitalizeNext = false - } else { - result.append(String(c)) - } - } - return result -} - -/// Allocate static memory buffers to intern UTF-8 -/// string data. Track the buffers and release all of those buffers -/// in case we ever get deallocated. -fileprivate class InternPool { - private var interned = [UnsafeBufferPointer]() - - func intern(utf8: String.UTF8View) -> UnsafeBufferPointer { - let bytePointer = UnsafeMutablePointer.allocate(capacity: utf8.count) - let mutable = UnsafeMutableBufferPointer(start: bytePointer, count: utf8.count) - _ = mutable.initialize(from: utf8) - let immutable = UnsafeBufferPointer(start: bytePointer, count: utf8.count) - interned.append(immutable) - return immutable - } - - deinit { - for buff in interned { - #if swift(>=4.1) - buff.deallocate() - #else - let p = UnsafeMutableRawPointer(mutating: buff.baseAddress)! - p.deallocate(bytes: buff.count, alignedTo: 1) - #endif - } - } -} - -#if !swift(>=4.2) -// Constants for FNV hash http://tools.ietf.org/html/draft-eastlake-fnv-03 -private let i_2166136261 = Int(bitPattern: 2166136261) -private let i_16777619 = Int(16777619) -#endif - -/// An immutable bidirectional mapping between field/enum-case names -/// and numbers, used to record field names for text-based -/// serialization (JSON and text). These maps are lazily instantiated -/// for each message as needed, so there is no run-time overhead for -/// users who do not use text-based serialization formats. -public struct _NameMap: ExpressibleByDictionaryLiteral { - - /// An immutable interned string container. The `utf8Start` pointer - /// is guaranteed valid for the lifetime of the `NameMap` that you - /// fetched it from. Since `NameMap`s are only instantiated as - /// immutable static values, that should be the lifetime of the - /// program. - /// - /// Internally, this uses `StaticString` (which refers to a fixed - /// block of UTF-8 data) where possible. In cases where the string - /// has to be computed, it caches the UTF-8 bytes in an - /// unmovable and immutable heap area. - internal struct Name: Hashable, CustomStringConvertible { - // This is safe to use elsewhere in this library - internal init(staticString: StaticString) { - self.nameString = .staticString(staticString) - self.utf8Buffer = UnsafeBufferPointer(start: staticString.utf8Start, count: staticString.utf8CodeUnitCount) - } - - // This should not be used outside of this file, as it requires - // coordinating the lifecycle with the lifecycle of the pool - // where the raw UTF8 gets interned. - fileprivate init(string: String, pool: InternPool) { - let utf8 = string.utf8 - self.utf8Buffer = pool.intern(utf8: utf8) - self.nameString = .string(string) - } - - // This is for building a transient `Name` object sufficient for lookup purposes. - // It MUST NOT be exposed outside of this file. - fileprivate init(transientUtf8Buffer: UnsafeBufferPointer) { - self.nameString = .staticString("") - self.utf8Buffer = transientUtf8Buffer - } - - private(set) var utf8Buffer: UnsafeBufferPointer - - private enum NameString { - case string(String) - case staticString(StaticString) - } - private var nameString: NameString - - public var description: String { - switch nameString { - case .string(let s): return s - case .staticString(let s): return s.description - } - } - - #if swift(>=4.2) - public func hash(into hasher: inout Hasher) { - for byte in utf8Buffer { - hasher.combine(byte) - } - } - #else // swift(>=4.2) - public var hashValue: Int { - var h = i_2166136261 - for byte in utf8Buffer { - h = (h ^ Int(byte)) &* i_16777619 - } - return h - } - #endif // swift(>=4.2) - - public static func ==(lhs: Name, rhs: Name) -> Bool { - if lhs.utf8Buffer.count != rhs.utf8Buffer.count { - return false - } - return lhs.utf8Buffer.elementsEqual(rhs.utf8Buffer) - } - } - - /// The JSON and proto names for a particular field, enum case, or extension. - internal struct Names { - private(set) var json: Name? - private(set) var proto: Name - } - - /// A description of the names for a particular field or enum case. - /// The different forms here let us minimize the amount of string - /// data that we store in the binary. - /// - /// These are only used in the generated code to initialize a NameMap. - public enum NameDescription { - - /// The proto (text format) name and the JSON name are the same string. - case same(proto: StaticString) - - /// The JSON name can be computed from the proto string - case standard(proto: StaticString) - - /// The JSON and text format names are just different. - case unique(proto: StaticString, json: StaticString) - - /// Used for enum cases only to represent a value's primary proto name (the - /// first defined case) and its aliases. The JSON and text format names for - /// enums are always the same. - case aliased(proto: StaticString, aliases: [StaticString]) - } - - private var internPool = InternPool() - - /// The mapping from field/enum-case numbers to names. - private var numberToNameMap: [Int: Names] = [:] - - /// The mapping from proto/text names to field/enum-case numbers. - private var protoToNumberMap: [Name: Int] = [:] - - /// The mapping from JSON names to field/enum-case numbers. - /// Note that this also contains all of the proto/text names, - /// as required by Google's spec for protobuf JSON. - private var jsonToNumberMap: [Name: Int] = [:] - - /// Creates a new empty field/enum-case name/number mapping. - public init() {} - - /// Build the bidirectional maps between numbers and proto/JSON names. - public init(dictionaryLiteral elements: (Int, NameDescription)...) { - for (number, description) in elements { - switch description { - - case .same(proto: let p): - let protoName = Name(staticString: p) - let names = Names(json: protoName, proto: protoName) - numberToNameMap[number] = names - protoToNumberMap[protoName] = number - jsonToNumberMap[protoName] = number - - case .standard(proto: let p): - let protoName = Name(staticString: p) - let jsonString = toJsonFieldName(protoName.description) - let jsonName = Name(string: jsonString, pool: internPool) - let names = Names(json: jsonName, proto: protoName) - numberToNameMap[number] = names - protoToNumberMap[protoName] = number - jsonToNumberMap[protoName] = number - jsonToNumberMap[jsonName] = number - - case .unique(proto: let p, json: let j): - let jsonName = Name(staticString: j) - let protoName = Name(staticString: p) - let names = Names(json: jsonName, proto: protoName) - numberToNameMap[number] = names - protoToNumberMap[protoName] = number - jsonToNumberMap[protoName] = number - jsonToNumberMap[jsonName] = number - - case .aliased(proto: let p, aliases: let aliases): - let protoName = Name(staticString: p) - let names = Names(json: protoName, proto: protoName) - numberToNameMap[number] = names - protoToNumberMap[protoName] = number - jsonToNumberMap[protoName] = number - for alias in aliases { - let protoName = Name(staticString: alias) - protoToNumberMap[protoName] = number - jsonToNumberMap[protoName] = number - } - } - } - } - - /// Returns the name bundle for the field/enum-case with the given number, or - /// `nil` if there is no match. - internal func names(for number: Int) -> Names? { - return numberToNameMap[number] - } - - /// Returns the field/enum-case number that has the given JSON name, - /// or `nil` if there is no match. - /// - /// This is used by the Text format parser to look up field or enum - /// names using a direct reference to the un-decoded UTF8 bytes. - internal func number(forProtoName raw: UnsafeBufferPointer) -> Int? { - let n = Name(transientUtf8Buffer: raw) - return protoToNumberMap[n] - } - - /// Returns the field/enum-case number that has the given JSON name, - /// or `nil` if there is no match. - /// - /// This accepts a regular `String` and is used in JSON parsing - /// only when a field name or enum name was decoded from a string - /// containing backslash escapes. - /// - /// JSON parsing must interpret *both* the JSON name of the - /// field/enum-case provided by the descriptor *as well as* its - /// original proto/text name. - internal func number(forJSONName name: String) -> Int? { - let utf8 = Array(name.utf8) - return utf8.withUnsafeBufferPointer { (buffer: UnsafeBufferPointer) in - let n = Name(transientUtf8Buffer: buffer) - return jsonToNumberMap[n] - } - } - - /// Returns the field/enum-case number that has the given JSON name, - /// or `nil` if there is no match. - /// - /// This is used by the JSON parser when a field name or enum name - /// required no special processing. As a result, we can avoid - /// copying the name and look up the number using a direct reference - /// to the un-decoded UTF8 bytes. - internal func number(forJSONName raw: UnsafeBufferPointer) -> Int? { - let n = Name(transientUtf8Buffer: raw) - return jsonToNumberMap[n] - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift deleted file mode 100644 index 42ed9b4..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtoNameProviding.swift +++ /dev/null @@ -1,23 +0,0 @@ -// Sources/SwiftProtobuf/ProtoNameProviding.swift - Support for accessing proto names -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- - - -/// SwiftProtobuf Internal: Common support looking up field names. -/// -/// Messages conform to this protocol to provide the proto/text and JSON field -/// names for their fields. This allows these names to be pulled out into -/// extensions in separate files so that users can omit them in release builds -/// (reducing bloat and minimizing leaks of field names). -public protocol _ProtoNameProviding { - - /// The mapping between field numbers and proto/JSON field names defined in - /// the conforming message type. - static var _protobuf_nameMap: _NameMap { get } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift deleted file mode 100644 index eed776e..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift +++ /dev/null @@ -1,43 +0,0 @@ -// Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift - Version checking -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A scheme that ensures that generated protos cannot be compiled or linked -/// against a version of the runtime with which they are not compatible. -/// -/// In many cases, API changes themselves might introduce incompatibilities -/// between generated code and the runtime library, but we also want to protect -/// against cases where breaking behavioral changes (without affecting the API) -/// would cause generated code to be incompatible with a particular version of -/// the runtime. -/// -// ----------------------------------------------------------------------------- - - -/// An empty protocol that encodes the version of the runtime library. -/// -/// This protocol will be replaced with one containing a different version -/// number any time that breaking changes are made to the Swift Protobuf API. -/// Combined with the protocol below, this lets us verify that generated code is -/// never compiled against a version of the API with which it is incompatible. -/// -/// The version associated with a particular build of the compiler is defined as -/// `Version.compatibilityVersion` in `protoc-gen-swift`. That version and this -/// version must match for the generated protos to be compatible, so if you -/// update one, make sure to update it here and in the associated type below. -public protocol ProtobufAPIVersion_2 {} - -/// This protocol is expected to be implemented by a `fileprivate` type in each -/// source file emitted by `protoc-gen-swift`. It effectively creates a binding -/// between the version of the generated code and the version of this library, -/// causing a compile-time error (with reasonable diagnostics) if they are -/// incompatible. -public protocol ProtobufAPIVersionCheck { - associatedtype Version: ProtobufAPIVersion_2 -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift deleted file mode 100644 index 911ff8b..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ProtobufMap.swift +++ /dev/null @@ -1,39 +0,0 @@ -// Sources/SwiftProtobuf/ProtobufMap.swift - Map<> support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Generic type representing proto map<> fields. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// SwiftProtobuf Internal: Support for Encoding/Decoding. -public struct _ProtobufMap -{ - public typealias Key = KeyType.BaseType - public typealias Value = ValueType.BaseType - public typealias BaseType = Dictionary -} - -/// SwiftProtobuf Internal: Support for Encoding/Decoding. -public struct _ProtobufMessageMap -{ - public typealias Key = KeyType.BaseType - public typealias Value = ValueType - public typealias BaseType = Dictionary -} - -/// SwiftProtobuf Internal: Support for Encoding/Decoding. -public struct _ProtobufEnumMap -{ - public typealias Key = KeyType.BaseType - public typealias Value = ValueType - public typealias BaseType = Dictionary -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift deleted file mode 100644 index f6fc5d7..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SelectiveVisitor.swift +++ /dev/null @@ -1,268 +0,0 @@ -// Sources/SwiftProtobuf/SelectiveVisitor.swift - Base for custom Visitors -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A base for Visitors that only expect a subset of things to called. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// A base for Visitors that only expects a subset of things to called. -internal protocol SelectiveVisitor: Visitor { - // Adds nothing. -} - -/// Default impls for everything so things using this only have to write the -/// methods they expect. Asserts to catch developer errors, but becomes -/// nothing in release to keep code size small. -/// -/// NOTE: This is an impl for *everything*. This means the default impls -/// provided by Visitor to bridge packed->repeated, repeated->singular, etc -/// won't kick in. -extension SelectiveVisitor { - internal mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int) throws { - assert(false) - } - - internal mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int - ) throws where ValueType.RawValue == Int { - assert(false) - } - - internal mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int - ) throws { - assert(false) - } - - internal mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { - assert(false) - } - - internal mutating func visitExtensionFieldsAsMessageSet( - fields: ExtensionFieldValueSet, - start: Int, - end: Int - ) throws { - assert(false) - } - - internal mutating func visitUnknown(bytes: Data) throws { - assert(false) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift deleted file mode 100644 index 986a8c3..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/SimpleExtensionMap.swift +++ /dev/null @@ -1,112 +0,0 @@ -// Sources/SwiftProtobuf/SimpleExtensionMap.swift - Extension support -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A default implementation of ExtensionMap. -/// -// ----------------------------------------------------------------------------- - - -// Note: The generated code only relies on ExpressibleByArrayLiteral -public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral, CustomDebugStringConvertible { - public typealias Element = AnyMessageExtension - - // Since type objects aren't Hashable, we can't do much better than this... - internal var fields = [Int: Array]() - - public init() {} - - public init(arrayLiteral: Element...) { - insert(contentsOf: arrayLiteral) - } - - public init(_ others: SimpleExtensionMap...) { - for other in others { - formUnion(other) - } - } - - public subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { - get { - if let l = fields[fieldNumber] { - for e in l { - if messageType == e.messageType { - return e - } - } - } - return nil - } - } - - public func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? { - // TODO: Make this faster... - for (_, list) in fields { - for e in list { - if e.fieldName == protoFieldName && e.messageType == messageType { - return e.fieldNumber - } - } - } - return nil - } - - public mutating func insert(_ newValue: Element) { - let fieldNumber = newValue.fieldNumber - if let l = fields[fieldNumber] { - let messageType = newValue.messageType - var newL = l.filter { return $0.messageType != messageType } - newL.append(newValue) - fields[fieldNumber] = newL - } else { - fields[fieldNumber] = [newValue] - } - } - - public mutating func insert(contentsOf: [Element]) { - for e in contentsOf { - insert(e) - } - } - - public mutating func formUnion(_ other: SimpleExtensionMap) { - for (fieldNumber, otherList) in other.fields { - if let list = fields[fieldNumber] { - var newList = list.filter { - for o in otherList { - if $0.messageType == o.messageType { return false } - } - return true - } - newList.append(contentsOf: otherList) - fields[fieldNumber] = newList - } else { - fields[fieldNumber] = otherList - } - } - } - - public func union(_ other: SimpleExtensionMap) -> SimpleExtensionMap { - var out = self - out.formUnion(other) - return out - } - - public var debugDescription: String { - var names = [String]() - for (_, list) in fields { - for e in list { - names.append("\(e.fieldName):(\(e.fieldNumber))") - } - } - let d = names.joined(separator: ",") - return "SimpleExtensionMap(\(d))" - } - -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift deleted file mode 100644 index d799e72..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/StringUtils.swift +++ /dev/null @@ -1,73 +0,0 @@ -// Sources/SwiftProtobuf/StringUtils.swift - String utility functions -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Utility functions for converting UTF8 bytes into Strings. -/// These functions must: -/// * Accept any valid UTF8, including a zero byte (which is -/// a valid UTF8 encoding of U+0000) -/// * Return nil for any invalid UTF8 -/// * Be fast (since they're extensively used by all decoders -/// and even some of the encoders) -/// -// ----------------------------------------------------------------------------- - -import Foundation - -// Wrapper that takes a buffer and start/end offsets -internal func utf8ToString( - bytes: UnsafeBufferPointer, - start: UnsafeBufferPointer.Index, - end: UnsafeBufferPointer.Index -) -> String? { - return utf8ToString(bytes: bytes.baseAddress! + start, count: end - start) -} - - -// Swift 4 introduced new faster String facilities -// that seem to work consistently across all platforms. - -// Notes on performance: -// -// The pre-verification here only takes about 10% of -// the time needed for constructing the string. -// Eliminating it would provide only a very minor -// speed improvement. -// -// On macOS, this is only about 25% faster than -// the Foundation initializer used below for Swift 3. -// On Linux, the Foundation initializer is much -// slower than on macOS, so this is a much bigger -// win there. -internal func utf8ToString(bytes: UnsafePointer, count: Int) -> String? { - if count == 0 { - return String() - } - let codeUnits = UnsafeBufferPointer(start: bytes, count: count) - let sourceEncoding = Unicode.UTF8.self - - // Verify that the UTF-8 is valid. - var p = sourceEncoding.ForwardParser() - var i = codeUnits.makeIterator() - Loop: - while true { - switch p.parseScalar(from: &i) { - case .valid(_): - break - case .error: - return nil - case .emptyInput: - break Loop - } - } - - // This initializer is fast but does not reject broken - // UTF-8 (which is why we validate the UTF-8 above). - return String(decoding: codeUnits, as: sourceEncoding) - } diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift deleted file mode 100644 index bc8176a..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecoder.swift +++ /dev/null @@ -1,713 +0,0 @@ -// Sources/SwiftProtobuf/TextFormatDecoder.swift - Text format decoding -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Test format decoding engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// -/// Provides a higher-level interface to the token stream coming -/// from a TextFormatScanner. In particular, this provides -/// single-token pushback and convenience functions for iterating -/// over complex structures. -/// -internal struct TextFormatDecoder: Decoder { - internal var scanner: TextFormatScanner - private var fieldCount = 0 - private var terminator: UInt8? - private var fieldNameMap: _NameMap? - private var messageType: Message.Type? - - internal var complete: Bool { - mutating get { - return scanner.complete - } - } - - internal init(messageType: Message.Type, utf8Pointer: UnsafePointer, count: Int, extensions: ExtensionMap?) throws { - scanner = TextFormatScanner(utf8Pointer: utf8Pointer, count: count, extensions: extensions) - guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { - throw TextFormatDecodingError.missingFieldNames - } - fieldNameMap = nameProviding._protobuf_nameMap - self.messageType = messageType - } - - internal init(messageType: Message.Type, scanner: TextFormatScanner, terminator: UInt8?) throws { - self.scanner = scanner - self.terminator = terminator - guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { - throw TextFormatDecodingError.missingFieldNames - } - fieldNameMap = nameProviding._protobuf_nameMap - self.messageType = messageType - } - - - mutating func handleConflictingOneOf() throws { - throw TextFormatDecodingError.conflictingOneOf - } - - mutating func nextFieldNumber() throws -> Int? { - if let terminator = terminator { - if scanner.skipOptionalObjectEnd(terminator) { - return nil - } - } - if fieldCount > 0 { - scanner.skipOptionalSeparator() - } - if let key = try scanner.nextOptionalExtensionKey() { - // Extension key; look up in the extension registry - if let fieldNumber = scanner.extensions?.fieldNumberForProto(messageType: messageType!, protoFieldName: key) { - fieldCount += 1 - return fieldNumber - } else { - throw TextFormatDecodingError.unknownField - } - } else if let fieldNumber = try scanner.nextFieldNumber(names: fieldNameMap!) { - fieldCount += 1 - return fieldNumber - } else if terminator == nil { - return nil - } else { - throw TextFormatDecodingError.truncated - } - - } - - mutating func decodeSingularFloatField(value: inout Float) throws { - try scanner.skipRequiredColon() - value = try scanner.nextFloat() - } - mutating func decodeSingularFloatField(value: inout Float?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextFloat() - } - mutating func decodeRepeatedFloatField(value: inout [Float]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextFloat() - value.append(n) - } - } else { - let n = try scanner.nextFloat() - value.append(n) - } - } - mutating func decodeSingularDoubleField(value: inout Double) throws { - try scanner.skipRequiredColon() - value = try scanner.nextDouble() - } - mutating func decodeSingularDoubleField(value: inout Double?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextDouble() - } - mutating func decodeRepeatedDoubleField(value: inout [Double]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextDouble() - value.append(n) - } - } else { - let n = try scanner.nextDouble() - value.append(n) - } - } - mutating func decodeSingularInt32Field(value: inout Int32) throws { - try scanner.skipRequiredColon() - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw TextFormatDecodingError.malformedNumber - } - value = Int32(truncatingIfNeeded: n) - } - mutating func decodeSingularInt32Field(value: inout Int32?) throws { - try scanner.skipRequiredColon() - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw TextFormatDecodingError.malformedNumber - } - value = Int32(truncatingIfNeeded: n) - } - mutating func decodeRepeatedInt32Field(value: inout [Int32]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw TextFormatDecodingError.malformedNumber - } - value.append(Int32(truncatingIfNeeded: n)) - } - } else { - let n = try scanner.nextSInt() - if n > Int64(Int32.max) || n < Int64(Int32.min) { - throw TextFormatDecodingError.malformedNumber - } - value.append(Int32(truncatingIfNeeded: n)) - } - } - mutating func decodeSingularInt64Field(value: inout Int64) throws { - try scanner.skipRequiredColon() - value = try scanner.nextSInt() - } - mutating func decodeSingularInt64Field(value: inout Int64?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextSInt() - } - mutating func decodeRepeatedInt64Field(value: inout [Int64]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextSInt() - value.append(n) - } - } else { - let n = try scanner.nextSInt() - value.append(n) - } - } - mutating func decodeSingularUInt32Field(value: inout UInt32) throws { - try scanner.skipRequiredColon() - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw TextFormatDecodingError.malformedNumber - } - value = UInt32(truncatingIfNeeded: n) - } - mutating func decodeSingularUInt32Field(value: inout UInt32?) throws { - try scanner.skipRequiredColon() - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw TextFormatDecodingError.malformedNumber - } - value = UInt32(truncatingIfNeeded: n) - } - mutating func decodeRepeatedUInt32Field(value: inout [UInt32]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw TextFormatDecodingError.malformedNumber - } - value.append(UInt32(truncatingIfNeeded: n)) - } - } else { - let n = try scanner.nextUInt() - if n > UInt64(UInt32.max) { - throw TextFormatDecodingError.malformedNumber - } - value.append(UInt32(truncatingIfNeeded: n)) - } - } - mutating func decodeSingularUInt64Field(value: inout UInt64) throws { - try scanner.skipRequiredColon() - value = try scanner.nextUInt() - } - mutating func decodeSingularUInt64Field(value: inout UInt64?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextUInt() - } - mutating func decodeRepeatedUInt64Field(value: inout [UInt64]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextUInt() - value.append(n) - } - } else { - let n = try scanner.nextUInt() - value.append(n) - } - } - mutating func decodeSingularSInt32Field(value: inout Int32) throws { - try decodeSingularInt32Field(value: &value) - } - mutating func decodeSingularSInt32Field(value: inout Int32?) throws { - try decodeSingularInt32Field(value: &value) - } - mutating func decodeRepeatedSInt32Field(value: inout [Int32]) throws { - try decodeRepeatedInt32Field(value: &value) - } - mutating func decodeSingularSInt64Field(value: inout Int64) throws { - try decodeSingularInt64Field(value: &value) - } - mutating func decodeSingularSInt64Field(value: inout Int64?) throws { - try decodeSingularInt64Field(value: &value) - } - mutating func decodeRepeatedSInt64Field(value: inout [Int64]) throws { - try decodeRepeatedInt64Field(value: &value) - } - mutating func decodeSingularFixed32Field(value: inout UInt32) throws { - try decodeSingularUInt32Field(value: &value) - } - mutating func decodeSingularFixed32Field(value: inout UInt32?) throws { - try decodeSingularUInt32Field(value: &value) - } - mutating func decodeRepeatedFixed32Field(value: inout [UInt32]) throws { - try decodeRepeatedUInt32Field(value: &value) - } - mutating func decodeSingularFixed64Field(value: inout UInt64) throws { - try decodeSingularUInt64Field(value: &value) - } - mutating func decodeSingularFixed64Field(value: inout UInt64?) throws { - try decodeSingularUInt64Field(value: &value) - } - mutating func decodeRepeatedFixed64Field(value: inout [UInt64]) throws { - try decodeRepeatedUInt64Field(value: &value) - } - mutating func decodeSingularSFixed32Field(value: inout Int32) throws { - try decodeSingularInt32Field(value: &value) - } - mutating func decodeSingularSFixed32Field(value: inout Int32?) throws { - try decodeSingularInt32Field(value: &value) - } - mutating func decodeRepeatedSFixed32Field(value: inout [Int32]) throws { - try decodeRepeatedInt32Field(value: &value) - } - mutating func decodeSingularSFixed64Field(value: inout Int64) throws { - try decodeSingularInt64Field(value: &value) - } - mutating func decodeSingularSFixed64Field(value: inout Int64?) throws { - try decodeSingularInt64Field(value: &value) - } - mutating func decodeRepeatedSFixed64Field(value: inout [Int64]) throws { - try decodeRepeatedInt64Field(value: &value) - } - mutating func decodeSingularBoolField(value: inout Bool) throws { - try scanner.skipRequiredColon() - value = try scanner.nextBool() - } - mutating func decodeSingularBoolField(value: inout Bool?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextBool() - } - mutating func decodeRepeatedBoolField(value: inout [Bool]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextBool() - value.append(n) - } - } else { - let n = try scanner.nextBool() - value.append(n) - } - } - mutating func decodeSingularStringField(value: inout String) throws { - try scanner.skipRequiredColon() - value = try scanner.nextStringValue() - } - mutating func decodeSingularStringField(value: inout String?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextStringValue() - } - mutating func decodeRepeatedStringField(value: inout [String]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextStringValue() - value.append(n) - } - } else { - let n = try scanner.nextStringValue() - value.append(n) - } - } - mutating func decodeSingularBytesField(value: inout Data) throws { - try scanner.skipRequiredColon() - value = try scanner.nextBytesValue() - } - mutating func decodeSingularBytesField(value: inout Data?) throws { - try scanner.skipRequiredColon() - value = try scanner.nextBytesValue() - } - mutating func decodeRepeatedBytesField(value: inout [Data]) throws { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let n = try scanner.nextBytesValue() - value.append(n) - } - } else { - let n = try scanner.nextBytesValue() - value.append(n) - } - } - - private mutating func decodeEnum() throws -> E where E.RawValue == Int { - if let name = try scanner.nextOptionalEnumName() { - if let b = E(rawUTF8: name) { - return b - } else { - throw TextFormatDecodingError.unrecognizedEnumValue - } - } - let number = try scanner.nextSInt() - if number >= Int64(Int32.min) && number <= Int64(Int32.max) { - let n = Int32(truncatingIfNeeded: number) - if let e = E(rawValue: Int(n)) { - return e - } else { - throw TextFormatDecodingError.unrecognizedEnumValue - } - } - throw TextFormatDecodingError.malformedText - - } - - mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int { - try scanner.skipRequiredColon() - let e: E = try decodeEnum() - value = e - } - - mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int { - try scanner.skipRequiredColon() - let e: E = try decodeEnum() - value = e - } - - mutating func decodeRepeatedEnumField(value: inout [E]) throws where E.RawValue == Int { - try scanner.skipRequiredColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let e: E = try decodeEnum() - value.append(e) - } - } else { - let e: E = try decodeEnum() - value.append(e) - } - } - - mutating func decodeSingularMessageField(value: inout M?) throws { - _ = scanner.skipOptionalColon() - if value == nil { - value = M() - } - let terminator = try scanner.skipObjectStart() - var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) - if M.self == Google_Protobuf_Any.self { - var any = value as! Google_Protobuf_Any? - try any!.decodeTextFormat(decoder: &subDecoder) - value = any as! M? - } else { - try value!.decodeMessage(decoder: &subDecoder) - } - scanner = subDecoder.scanner - } - - mutating func decodeRepeatedMessageField(value: inout [M]) throws { - _ = scanner.skipOptionalColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - let terminator = try scanner.skipObjectStart() - var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) - if M.self == Google_Protobuf_Any.self { - var message = Google_Protobuf_Any() - try message.decodeTextFormat(decoder: &subDecoder) - value.append(message as! M) - } else { - var message = M() - try message.decodeMessage(decoder: &subDecoder) - value.append(message) - } - scanner = subDecoder.scanner - } - } else { - let terminator = try scanner.skipObjectStart() - var subDecoder = try TextFormatDecoder(messageType: M.self,scanner: scanner, terminator: terminator) - if M.self == Google_Protobuf_Any.self { - var message = Google_Protobuf_Any() - try message.decodeTextFormat(decoder: &subDecoder) - value.append(message as! M) - } else { - var message = M() - try message.decodeMessage(decoder: &subDecoder) - value.append(message) - } - scanner = subDecoder.scanner - } - } - - mutating func decodeSingularGroupField(value: inout G?) throws { - try decodeSingularMessageField(value: &value) - } - - mutating func decodeRepeatedGroupField(value: inout [G]) throws { - try decodeRepeatedMessageField(value: &value) - } - - private mutating func decodeMapEntry(mapType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { - var keyField: KeyType.BaseType? - var valueField: ValueType.BaseType? - let terminator = try scanner.skipObjectStart() - while true { - if scanner.skipOptionalObjectEnd(terminator) { - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - return - } else { - throw TextFormatDecodingError.malformedText - } - } - if let key = try scanner.nextKey() { - switch key { - case "key", "1": - try KeyType.decodeSingular(value: &keyField, from: &self) - case "value", "2": - try ValueType.decodeSingular(value: &valueField, from: &self) - default: - throw TextFormatDecodingError.unknownField - } - scanner.skipOptionalSeparator() - } - } - } - - mutating func decodeMapField(fieldType: _ProtobufMap.Type, value: inout _ProtobufMap.BaseType) throws { - _ = scanner.skipOptionalColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - try decodeMapEntry(mapType: fieldType, value: &value) - } - } else { - try decodeMapEntry(mapType: fieldType, value: &value) - } - } - - private mutating func decodeMapEntry(mapType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { - var keyField: KeyType.BaseType? - var valueField: ValueType? - let terminator = try scanner.skipObjectStart() - while true { - if scanner.skipOptionalObjectEnd(terminator) { - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - return - } else { - throw TextFormatDecodingError.malformedText - } - } - if let key = try scanner.nextKey() { - switch key { - case "key", "1": - try KeyType.decodeSingular(value: &keyField, from: &self) - case "value", "2": - try decodeSingularEnumField(value: &valueField) - default: - throw TextFormatDecodingError.unknownField - } - scanner.skipOptionalSeparator() - } - } - } - - mutating func decodeMapField(fieldType: _ProtobufEnumMap.Type, value: inout _ProtobufEnumMap.BaseType) throws where ValueType.RawValue == Int { - _ = scanner.skipOptionalColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - try decodeMapEntry(mapType: fieldType, value: &value) - } - } else { - try decodeMapEntry(mapType: fieldType, value: &value) - } - } - - private mutating func decodeMapEntry(mapType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { - var keyField: KeyType.BaseType? - var valueField: ValueType? - let terminator = try scanner.skipObjectStart() - while true { - if scanner.skipOptionalObjectEnd(terminator) { - if let keyField = keyField, let valueField = valueField { - value[keyField] = valueField - return - } else { - throw TextFormatDecodingError.malformedText - } - } - if let key = try scanner.nextKey() { - switch key { - case "key", "1": - try KeyType.decodeSingular(value: &keyField, from: &self) - case "value", "2": - try decodeSingularMessageField(value: &valueField) - default: - throw TextFormatDecodingError.unknownField - } - scanner.skipOptionalSeparator() - } - } - } - - mutating func decodeMapField(fieldType: _ProtobufMessageMap.Type, value: inout _ProtobufMessageMap.BaseType) throws { - _ = scanner.skipOptionalColon() - if scanner.skipOptionalBeginArray() { - var firstItem = true - while true { - if scanner.skipOptionalEndArray() { - return - } - if firstItem { - firstItem = false - } else { - try scanner.skipRequiredComma() - } - try decodeMapEntry(mapType: fieldType, value: &value) - } - } else { - try decodeMapEntry(mapType: fieldType, value: &value) - } - } - - mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws { - if let ext = scanner.extensions?[messageType, fieldNumber] { - var fieldValue = values[fieldNumber] - if fieldValue != nil { - try fieldValue!.decodeExtensionField(decoder: &self) - } else { - fieldValue = try ext._protobuf_newField(decoder: &self) - } - if fieldValue != nil { - values[fieldNumber] = fieldValue - } else { - // Really things should never get here, for TextFormat, decoding - // the value should always work or throw an error. This specific - // error result is to allow this to be more detectable. - throw TextFormatDecodingError.internalExtensionError - } - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift deleted file mode 100644 index 49047b2..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatDecodingError.swift +++ /dev/null @@ -1,40 +0,0 @@ -// Sources/SwiftProtobuf/TextFormatDecodingError.swift - Protobuf text format decoding errors -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Protobuf text format decoding errors -/// -// ----------------------------------------------------------------------------- - -public enum TextFormatDecodingError: Error { - /// Text data could not be parsed - case malformedText - /// A number could not be parsed - case malformedNumber - /// Extraneous data remained after decoding should have been complete - case trailingGarbage - /// The data stopped before we expected - case truncated - /// A string was not valid UTF8 - case invalidUTF8 - /// The data being parsed does not match the type specified in the proto file - case schemaMismatch - /// Field names were not compiled into the binary - case missingFieldNames - /// A field identifier (name or number) was not found on the message - case unknownField - /// The enum value was not recognized - case unrecognizedEnumValue - /// Text format rejects conflicting values for the same oneof field - case conflictingOneOf - /// An internal error happened while decoding. If this is ever encountered, - /// please file an issue with SwiftProtobuf with as much details as possible - /// for what happened (proto definitions, bytes being decoded (if possible)). - case internalExtensionError -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift deleted file mode 100644 index 8a7f9ce..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatEncoder.swift +++ /dev/null @@ -1,292 +0,0 @@ -// Sources/SwiftProtobuf/TextFormatEncoder.swift - Text format encoding support -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Text format serialization engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let asciiSpace = UInt8(ascii: " ") -private let asciiColon = UInt8(ascii: ":") -private let asciiComma = UInt8(ascii: ",") -private let asciiMinus = UInt8(ascii: "-") -private let asciiBackslash = UInt8(ascii: "\\") -private let asciiDoubleQuote = UInt8(ascii: "\"") -private let asciiZero = UInt8(ascii: "0") -private let asciiOpenCurlyBracket = UInt8(ascii: "{") -private let asciiCloseCurlyBracket = UInt8(ascii: "}") -private let asciiOpenSquareBracket = UInt8(ascii: "[") -private let asciiCloseSquareBracket = UInt8(ascii: "]") -private let asciiNewline = UInt8(ascii: "\n") -private let asciiUpperA = UInt8(ascii: "A") - -private let tabSize = 2 - -/// TextFormatEncoder has no public members. -internal struct TextFormatEncoder { - private var data = [UInt8]() - private var indentString: [UInt8] = [] - var stringResult: String { - get { - return String(bytes: data, encoding: String.Encoding.utf8)! - } - } - - internal mutating func append(staticText: StaticString) { - let buff = UnsafeBufferPointer(start: staticText.utf8Start, count: staticText.utf8CodeUnitCount) - data.append(contentsOf: buff) - } - - internal mutating func append(name: _NameMap.Name) { - data.append(contentsOf: name.utf8Buffer) - } - - private mutating func append(text: String) { - data.append(contentsOf: text.utf8) - } - - init() {} - - internal mutating func indent() { - data.append(contentsOf: indentString) - } - - mutating func emitFieldName(name: UnsafeBufferPointer) { - indent() - data.append(contentsOf: name) - } - - mutating func emitFieldName(name: StaticString) { - let buff = UnsafeBufferPointer(start: name.utf8Start, count: name.utf8CodeUnitCount) - emitFieldName(name: buff) - } - - mutating func emitExtensionFieldName(name: String) { - indent() - data.append(asciiOpenSquareBracket) - append(text: name) - data.append(asciiCloseSquareBracket) - } - - mutating func emitFieldNumber(number: Int) { - indent() - appendUInt(value: UInt64(number)) - } - - mutating func startRegularField() { - append(staticText: ": ") - } - mutating func endRegularField() { - data.append(asciiNewline) - } - - // In Text format, a message-valued field writes the name - // without a trailing colon: - // name_of_field {key: value key2: value2} - mutating func startMessageField() { - append(staticText: " {\n") - for _ in 1...tabSize { - indentString.append(asciiSpace) - } - } - - mutating func endMessageField() { - for _ in 1...tabSize { - indentString.remove(at: indentString.count - 1) - } - indent() - append(staticText: "}\n") - } - - mutating func startArray() { - data.append(asciiOpenSquareBracket) - } - - mutating func arraySeparator() { - append(staticText: ", ") - } - - mutating func endArray() { - data.append(asciiCloseSquareBracket) - } - - mutating func putEnumValue(value: E) { - if let name = value.name { - data.append(contentsOf: name.utf8Buffer) - } else { - appendInt(value: Int64(value.rawValue)) - } - } - - mutating func putFloatValue(value: Float) { - if value.isNaN { - append(staticText: "nan") - } else if !value.isFinite { - if value < 0 { - append(staticText: "-inf") - } else { - append(staticText: "inf") - } - } else { - data.append(contentsOf: value.debugDescription.utf8) - } - } - - mutating func putDoubleValue(value: Double) { - if value.isNaN { - append(staticText: "nan") - } else if !value.isFinite { - if value < 0 { - append(staticText: "-inf") - } else { - append(staticText: "inf") - } - } else { - data.append(contentsOf: value.debugDescription.utf8) - } - } - - private mutating func appendUInt(value: UInt64) { - if value >= 1000 { - appendUInt(value: value / 1000) - } - if value >= 100 { - data.append(asciiZero + UInt8((value / 100) % 10)) - } - if value >= 10 { - data.append(asciiZero + UInt8((value / 10) % 10)) - } - data.append(asciiZero + UInt8(value % 10)) - } - private mutating func appendInt(value: Int64) { - if value < 0 { - data.append(asciiMinus) - // This is the twos-complement negation of value, - // computed in a way that won't overflow a 64-bit - // signed integer. - appendUInt(value: 1 + ~UInt64(bitPattern: value)) - } else { - appendUInt(value: UInt64(bitPattern: value)) - } - } - - mutating func putInt64(value: Int64) { - appendInt(value: value) - } - - mutating func putUInt64(value: UInt64) { - appendUInt(value: value) - } - - mutating func appendUIntHex(value: UInt64, digits: Int) { - if digits == 0 { - append(staticText: "0x") - } else { - appendUIntHex(value: value >> 4, digits: digits - 1) - let d = UInt8(truncatingIfNeeded: value % 16) - data.append(d < 10 ? asciiZero + d : asciiUpperA + d - 10) - } - } - - mutating func putUInt64Hex(value: UInt64, digits: Int) { - appendUIntHex(value: value, digits: digits) - } - - mutating func putBoolValue(value: Bool) { - append(staticText: value ? "true" : "false") - } - - mutating func putStringValue(value: String) { - data.append(asciiDoubleQuote) - for c in value.unicodeScalars { - switch c.value { - // Special two-byte escapes - case 8: - append(staticText: "\\b") - case 9: - append(staticText: "\\t") - case 10: - append(staticText: "\\n") - case 11: - append(staticText: "\\v") - case 12: - append(staticText: "\\f") - case 13: - append(staticText: "\\r") - case 34: - append(staticText: "\\\"") - case 92: - append(staticText: "\\\\") - case 0...31, 127: // Octal form for C0 control chars - data.append(asciiBackslash) - data.append(asciiZero + UInt8(c.value / 64)) - data.append(asciiZero + UInt8(c.value / 8 % 8)) - data.append(asciiZero + UInt8(c.value % 8)) - case 0...127: // ASCII - data.append(UInt8(truncatingIfNeeded: c.value)) - case 0x80...0x7ff: - data.append(0xc0 + UInt8(c.value / 64)) - data.append(0x80 + UInt8(c.value % 64)) - case 0x800...0xffff: - data.append(0xe0 + UInt8(truncatingIfNeeded: c.value >> 12)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) - default: - data.append(0xf0 + UInt8(truncatingIfNeeded: c.value >> 18)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 12) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: (c.value >> 6) & 0x3f)) - data.append(0x80 + UInt8(truncatingIfNeeded: c.value & 0x3f)) - } - } - data.append(asciiDoubleQuote) - } - - mutating func putBytesValue(value: Data) { - data.append(asciiDoubleQuote) - value.withUnsafeBytes { (body: UnsafeRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - let p = baseAddress.assumingMemoryBound(to: UInt8.self) - - for i in 0.. () in - if let baseAddress = body.baseAddress, body.count > 0 { - let p = baseAddress.assumingMemoryBound(to: UInt8.self) - var decoder = BinaryDecoder(forReadingFrom: p, - count: body.count, - options: BinaryDecodingOptions()) - try visitUnknown(decoder: &decoder, groupFieldNumber: nil) - } - } - } - } - - private mutating func visitUnknown(decoder: inout BinaryDecoder, groupFieldNumber: Int?) throws { - while let tag = try decoder.getTag() { - switch tag.wireFormat { - case .varint: - encoder.emitFieldNumber(number: tag.fieldNumber) - var value: UInt64 = 0 - encoder.startRegularField() - try decoder.decodeSingularUInt64Field(value: &value) - encoder.putUInt64(value: value) - encoder.endRegularField() - case .fixed64: - encoder.emitFieldNumber(number: tag.fieldNumber) - var value: UInt64 = 0 - encoder.startRegularField() - try decoder.decodeSingularFixed64Field(value: &value) - encoder.putUInt64Hex(value: value, digits: 16) - encoder.endRegularField() - case .lengthDelimited: - encoder.emitFieldNumber(number: tag.fieldNumber) - var bytes = Internal.emptyData - try decoder.decodeSingularBytesField(value: &bytes) - bytes.withUnsafeBytes { (body: UnsafeRawBufferPointer) -> () in - if let baseAddress = body.baseAddress, body.count > 0 { - let p = baseAddress.assumingMemoryBound(to: UInt8.self) - - var testDecoder = BinaryDecoder(forReadingFrom: p, - count: body.count, - parent: decoder) - do { - // Skip all the fields to test if it looks like a message - while let _ = try testDecoder.nextFieldNumber() { - } - // No error? Output the message body. - var subDecoder = BinaryDecoder(forReadingFrom: p, - count: bytes.count, - parent: decoder) - encoder.startMessageField() - try visitUnknown(decoder: &subDecoder, groupFieldNumber: nil) - encoder.endMessageField() - } catch { - // Field scan threw an error, so just dump it as a string. - encoder.startRegularField() - encoder.putBytesValue(value: bytes) - encoder.endRegularField() - } - } - } - case .startGroup: - encoder.emitFieldNumber(number: tag.fieldNumber) - encoder.startMessageField() - try visitUnknown(decoder: &decoder, groupFieldNumber: tag.fieldNumber) - encoder.endMessageField() - case .endGroup: - // Unknown data is scanned and verified by the - // binary parser, so this can never fail. - assert(tag.fieldNumber == groupFieldNumber) - return - case .fixed32: - encoder.emitFieldNumber(number: tag.fieldNumber) - var value: UInt32 = 0 - encoder.startRegularField() - try decoder.decodeSingularFixed32Field(value: &value) - encoder.putUInt64Hex(value: UInt64(value), digits: 8) - encoder.endRegularField() - } - } - } - - // Visitor.swift defines default versions for other singular field types - // that simply widen and dispatch to one of the following. Since Text format - // does not distinguish e.g., Fixed64 vs. UInt64, this is sufficient. - - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putFloatValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putDoubleValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putInt64(value: value) - encoder.endRegularField() - } - - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putUInt64(value: value) - encoder.endRegularField() - } - - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putBoolValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putStringValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putBytesValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putEnumValue(value: value) - encoder.endRegularField() - } - - mutating func visitSingularMessageField(value: M, - fieldNumber: Int) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startMessageField() - var visitor = TextFormatEncodingVisitor(message: value, encoder: encoder, options: options) - if let any = value as? Google_Protobuf_Any { - any.textTraverse(visitor: &visitor) - } else { - try! value.traverse(visitor: &visitor) - } - encoder = visitor.encoder - encoder.endMessageField() - } - - // Emit the full "verbose" form of an Any. This writes the typeURL - // as a field name in `[...]` followed by the fields of the - // contained message. - internal mutating func visitAnyVerbose(value: Message, typeURL: String) { - encoder.emitExtensionFieldName(name: typeURL) - encoder.startMessageField() - var visitor = TextFormatEncodingVisitor(message: value, encoder: encoder, options: options) - if let any = value as? Google_Protobuf_Any { - any.textTraverse(visitor: &visitor) - } else { - try! value.traverse(visitor: &visitor) - } - encoder = visitor.encoder - encoder.endMessageField() - } - - // Write a single special field called "#json". This - // is used for Any objects with undecoded JSON contents. - internal mutating func visitAnyJSONDataField(value: Data) { - encoder.indent() - encoder.append(staticText: "#json: ") - encoder.putBytesValue(value: value) - encoder.append(staticText: "\n") - } - - // The default implementations in Visitor.swift provide the correct - // results, but we get significantly better performance by only doing - // the name lookup once for the array, rather than once for each element: - - mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putFloatValue(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putDoubleValue(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putInt64(value: Int64(v)) - encoder.endRegularField() - } - } - - mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putInt64(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putUInt64(value: UInt64(v)) - encoder.endRegularField() - } - } - - mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putUInt64(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { - try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { - try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) - } - mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) - } - mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putBoolValue(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putStringValue(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putBytesValue(value: v) - encoder.endRegularField() - } - } - - mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - encoder.putEnumValue(value: v) - encoder.endRegularField() - } - } - - // Messages and groups - mutating func visitRepeatedMessageField(value: [M], - fieldNumber: Int) throws { - for v in value { - emitFieldName(lookingUp: fieldNumber) - encoder.startMessageField() - var visitor = TextFormatEncodingVisitor(message: v, encoder: encoder, options: options) - if let any = v as? Google_Protobuf_Any { - any.textTraverse(visitor: &visitor) - } else { - try! v.traverse(visitor: &visitor) - } - encoder = visitor.encoder - encoder.endMessageField() - } - } - - // Google's C++ implementation of Text format supports two formats - // for repeated numeric fields: "short" format writes the list as a - // single field with values enclosed in `[...]`, "long" format - // writes a separate field name/value for each item. They provide - // an option for callers to select which output version they prefer. - - // Since this distinction mirrors the difference in Protobuf Binary - // between "packed" and "non-packed", I've chosen to use the short - // format for packed fields and the long version for repeated - // fields. This provides a clear visual distinction between these - // fields (including proto3's default use of packed) without - // introducing the baggage of a separate option. - - private mutating func _visitPacked( - value: [T], fieldNumber: Int, - encode: (T, inout TextFormatEncoder) -> () - ) throws { - emitFieldName(lookingUp: fieldNumber) - encoder.startRegularField() - var firstItem = true - encoder.startArray() - for v in value { - if !firstItem { - encoder.arraySeparator() - } - encode(v, &encoder) - firstItem = false - } - encoder.endArray() - encoder.endRegularField() - } - - mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: Float, encoder: inout TextFormatEncoder) in - encoder.putFloatValue(value: v) - } - } - - mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: Double, encoder: inout TextFormatEncoder) in - encoder.putDoubleValue(value: v) - } - } - - mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: Int32, encoder: inout TextFormatEncoder) in - encoder.putInt64(value: Int64(v)) - } - } - - mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: Int64, encoder: inout TextFormatEncoder) in - encoder.putInt64(value: v) - } - } - - mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: UInt32, encoder: inout TextFormatEncoder) in - encoder.putUInt64(value: UInt64(v)) - } - } - - mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: UInt64, encoder: inout TextFormatEncoder) in - encoder.putUInt64(value: v) - } - } - - mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { - try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { - try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - try visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - try visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) - } - - mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: Bool, encoder: inout TextFormatEncoder) in - encoder.putBoolValue(value: v) - } - } - - mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws { - try _visitPacked(value: value, fieldNumber: fieldNumber) { - (v: E, encoder: inout TextFormatEncoder) in - encoder.putEnumValue(value: v) - } - } - - /// Helper to encapsulate the common structure of iterating over a map - /// and encoding the keys and values. - private mutating func _visitMap( - map: Dictionary, - fieldNumber: Int, - coder: (inout TextFormatEncodingVisitor, K, V) throws -> () - ) throws { - for (k,v) in map { - emitFieldName(lookingUp: fieldNumber) - encoder.startMessageField() - var visitor = TextFormatEncodingVisitor(nameMap: nil, nameResolver: mapNameResolver, extensions: nil, encoder: encoder, options: options) - try coder(&visitor, k, v) - encoder = visitor.encoder - encoder.endMessageField() - } - } - - mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int - ) throws { - try _visitMap(map: value, fieldNumber: fieldNumber) { - (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in - try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) - try ValueType.visitSingular(value: value, fieldNumber: 2, with: &visitor) - } - } - - mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int - ) throws where ValueType.RawValue == Int { - try _visitMap(map: value, fieldNumber: fieldNumber) { - (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in - try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) - try visitor.visitSingularEnumField(value: value, fieldNumber: 2) - } - } - - mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int - ) throws { - try _visitMap(map: value, fieldNumber: fieldNumber) { - (visitor: inout TextFormatEncodingVisitor, key, value) throws -> () in - try KeyType.visitSingular(value: key, fieldNumber: 1, with: &visitor) - try visitor.visitSingularMessageField(value: value, fieldNumber: 2) - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift deleted file mode 100644 index 6e12ff8..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TextFormatScanner.swift +++ /dev/null @@ -1,1078 +0,0 @@ -// Sources/SwiftProtobuf/TextFormatScanner.swift - Text format decoding -// -// Copyright (c) 2014 - 2019 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Test format decoding engine. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -private let asciiBell = UInt8(7) -private let asciiBackspace = UInt8(8) -private let asciiTab = UInt8(9) -private let asciiNewLine = UInt8(10) -private let asciiVerticalTab = UInt8(11) -private let asciiFormFeed = UInt8(12) -private let asciiCarriageReturn = UInt8(13) -private let asciiZero = UInt8(ascii: "0") -private let asciiOne = UInt8(ascii: "1") -private let asciiThree = UInt8(ascii: "3") -private let asciiSeven = UInt8(ascii: "7") -private let asciiNine = UInt8(ascii: "9") -private let asciiColon = UInt8(ascii: ":") -private let asciiPeriod = UInt8(ascii: ".") -private let asciiPlus = UInt8(ascii: "+") -private let asciiComma = UInt8(ascii: ",") -private let asciiSemicolon = UInt8(ascii: ";") -private let asciiDoubleQuote = UInt8(ascii: "\"") -private let asciiSingleQuote = UInt8(ascii: "\'") -private let asciiBackslash = UInt8(ascii: "\\") -private let asciiForwardSlash = UInt8(ascii: "/") -private let asciiHash = UInt8(ascii: "#") -private let asciiUnderscore = UInt8(ascii: "_") -private let asciiQuestionMark = UInt8(ascii: "?") -private let asciiSpace = UInt8(ascii: " ") -private let asciiOpenSquareBracket = UInt8(ascii: "[") -private let asciiCloseSquareBracket = UInt8(ascii: "]") -private let asciiOpenCurlyBracket = UInt8(ascii: "{") -private let asciiCloseCurlyBracket = UInt8(ascii: "}") -private let asciiOpenAngleBracket = UInt8(ascii: "<") -private let asciiCloseAngleBracket = UInt8(ascii: ">") -private let asciiMinus = UInt8(ascii: "-") -private let asciiLowerA = UInt8(ascii: "a") -private let asciiUpperA = UInt8(ascii: "A") -private let asciiLowerB = UInt8(ascii: "b") -private let asciiLowerE = UInt8(ascii: "e") -private let asciiUpperE = UInt8(ascii: "E") -private let asciiLowerF = UInt8(ascii: "f") -private let asciiUpperF = UInt8(ascii: "F") -private let asciiLowerI = UInt8(ascii: "i") -private let asciiLowerL = UInt8(ascii: "l") -private let asciiLowerN = UInt8(ascii: "n") -private let asciiLowerR = UInt8(ascii: "r") -private let asciiLowerS = UInt8(ascii: "s") -private let asciiLowerT = UInt8(ascii: "t") -private let asciiUpperT = UInt8(ascii: "T") -private let asciiLowerU = UInt8(ascii: "u") -private let asciiLowerV = UInt8(ascii: "v") -private let asciiLowerX = UInt8(ascii: "x") -private let asciiLowerY = UInt8(ascii: "y") -private let asciiLowerZ = UInt8(ascii: "z") -private let asciiUpperZ = UInt8(ascii: "Z") - -private func fromHexDigit(_ c: UInt8) -> UInt8? { - if c >= asciiZero && c <= asciiNine { - return c - asciiZero - } - if c >= asciiUpperA && c <= asciiUpperF { - return c - asciiUpperA + UInt8(10) - } - if c >= asciiLowerA && c <= asciiLowerF { - return c - asciiLowerA + UInt8(10) - } - return nil -} - -// Protobuf Text encoding assumes that you're working directly -// in UTF-8. So this implementation converts the string to UTF8, -// then decodes it into a sequence of bytes, then converts -// it back into a string. -private func decodeString(_ s: String) -> String? { - var out = [UInt8]() - var bytes = s.utf8.makeIterator() - while let byte = bytes.next() { - switch byte { - case asciiBackslash: // backslash - if let escaped = bytes.next() { - switch escaped { - case asciiZero...asciiSeven: // 0...7 - // C standard allows 1, 2, or 3 octal digits. - let savedPosition = bytes - let digit1 = escaped - let digit1Value = digit1 - asciiZero - if let digit2 = bytes.next(), - digit2 >= asciiZero && digit2 <= asciiSeven { - let digit2Value = digit2 - asciiZero - let innerSavedPosition = bytes - if let digit3 = bytes.next(), - digit3 >= asciiZero && digit3 <= asciiSeven { - let digit3Value = digit3 - asciiZero - let n = digit1Value * 64 + digit2Value * 8 + digit3Value - out.append(n) - } else { - let n = digit1Value * 8 + digit2Value - out.append(n) - bytes = innerSavedPosition - } - } else { - let n = digit1Value - out.append(n) - bytes = savedPosition - } - case asciiLowerX: // "x" - // Unlike C/C++, protobuf only allows 1 or 2 digits here: - if let byte = bytes.next(), let digit = fromHexDigit(byte) { - var n = digit - let savedPosition = bytes - if let byte = bytes.next(), let digit = fromHexDigit(byte) { - n = n &* 16 + digit - } else { - // No second digit; reset the iterator - bytes = savedPosition - } - out.append(n) - } else { - return nil // Hex escape must have at least 1 digit - } - case asciiLowerA: // \a - out.append(asciiBell) - case asciiLowerB: // \b - out.append(asciiBackspace) - case asciiLowerF: // \f - out.append(asciiFormFeed) - case asciiLowerN: // \n - out.append(asciiNewLine) - case asciiLowerR: // \r - out.append(asciiCarriageReturn) - case asciiLowerT: // \t - out.append(asciiTab) - case asciiLowerV: // \v - out.append(asciiVerticalTab) - case asciiDoubleQuote, - asciiSingleQuote, - asciiQuestionMark, - asciiBackslash: // " ' ? \ - out.append(escaped) - default: - return nil // Unrecognized escape - } - } else { - return nil // Input ends with backslash - } - default: - out.append(byte) - } - } - // There has got to be an easier way to convert a [UInt8] into a String. - return out.withUnsafeBufferPointer { ptr in - if let addr = ptr.baseAddress { - return utf8ToString(bytes: addr, count: ptr.count) - } else { - return String() - } - } -} - -/// -/// TextFormatScanner has no public members. -/// -internal struct TextFormatScanner { - internal var extensions: ExtensionMap? - private var p: UnsafePointer - private var end: UnsafePointer - private var doubleParser = DoubleParser() - - internal var complete: Bool { - mutating get { - return p == end - } - } - - internal init(utf8Pointer: UnsafePointer, count: Int, extensions: ExtensionMap? = nil) { - p = utf8Pointer - end = p + count - self.extensions = extensions - skipWhitespace() - } - - /// Skip whitespace - private mutating func skipWhitespace() { - while p != end { - let u = p[0] - switch u { - case asciiSpace, - asciiTab, - asciiNewLine, - asciiCarriageReturn: // space, tab, NL, CR - p += 1 - case asciiHash: // # comment - p += 1 - while p != end { - // Skip until end of line - let c = p[0] - p += 1 - if c == asciiNewLine || c == asciiCarriageReturn { - break - } - } - default: - return - } - } - } - - /// Return a buffer containing the raw UTF8 for an identifier. - /// Assumes that you already know the current byte is a valid - /// start of identifier. - private mutating func parseUTF8Identifier() -> UnsafeBufferPointer { - let start = p - loop: while p != end { - let c = p[0] - switch c { - case asciiLowerA...asciiLowerZ, - asciiUpperA...asciiUpperZ, - asciiZero...asciiNine, - asciiUnderscore: - p += 1 - default: - break loop - } - } - let s = UnsafeBufferPointer(start: start, count: p - start) - skipWhitespace() - return s - } - - /// Return a String containing the next identifier. - private mutating func parseIdentifier() -> String { - let buff = parseUTF8Identifier() - let s = utf8ToString(bytes: buff.baseAddress!, count: buff.count) - // Force-unwrap is OK: we never have invalid UTF8 at this point. - return s! - } - - /// Parse the rest of an [extension_field_name] in the input, assuming the - /// initial "[" character has already been read (and is in the prefix) - /// This is also used for AnyURL, so we include "/", "." - private mutating func parseExtensionKey() -> String? { - let start = p - if p == end { - return nil - } - let c = p[0] - switch c { - case asciiLowerA...asciiLowerZ, asciiUpperA...asciiUpperZ: - p += 1 - default: - return nil - } - while p != end { - let c = p[0] - switch c { - case asciiLowerA...asciiLowerZ, - asciiUpperA...asciiUpperZ, - asciiZero...asciiNine, - asciiUnderscore, - asciiPeriod, - asciiForwardSlash: - p += 1 - case asciiCloseSquareBracket: // ] - return utf8ToString(bytes: start, count: p - start) - default: - return nil - } - } - return nil - } - - /// Scan a string that encodes a byte field, return a count of - /// the number of bytes that should be decoded from it - private mutating func validateAndCountBytesFromString(terminator: UInt8, sawBackslash: inout Bool) throws -> Int { - var count = 0 - let start = p - sawBackslash = false - while p != end { - let byte = p[0] - p += 1 - if byte == terminator { - p = start - return count - } - switch byte { - case asciiBackslash: // "\\" - sawBackslash = true - if p != end { - let escaped = p[0] - p += 1 - switch escaped { - case asciiZero...asciiSeven: // '0'...'7' - // C standard allows 1, 2, or 3 octal digits. - if p != end, p[0] >= asciiZero, p[0] <= asciiSeven { - p += 1 - if p != end, p[0] >= asciiZero, p[0] <= asciiSeven { - if escaped > asciiThree { - // Out of range octal: three digits and first digit is greater than 3 - throw TextFormatDecodingError.malformedText - } - p += 1 - } - } - count += 1 - case asciiLowerX: // 'x' hexadecimal escape - if p != end && fromHexDigit(p[0]) != nil { - p += 1 - if p != end && fromHexDigit(p[0]) != nil { - p += 1 - } - } else { - throw TextFormatDecodingError.malformedText // Hex escape must have at least 1 digit - } - count += 1 - case asciiLowerA, // \a ("alert") - asciiLowerB, // \b - asciiLowerF, // \f - asciiLowerN, // \n - asciiLowerR, // \r - asciiLowerT, // \t - asciiLowerV, // \v - asciiSingleQuote, // \' - asciiDoubleQuote, // \" - asciiQuestionMark, // \? - asciiBackslash: // \\ - count += 1 - default: - throw TextFormatDecodingError.malformedText // Unrecognized escape - } - } - default: - count += 1 - } - } - throw TextFormatDecodingError.malformedText - } - - /// Protobuf Text format uses C ASCII conventions for - /// encoding byte sequences, including the use of octal - /// and hexadecimal escapes. - /// - /// Assumes that validateAndCountBytesFromString() has already - /// verified the correctness. So we get to avoid error checks here. - private mutating func parseBytesFromString(terminator: UInt8, into data: inout Data) { - data.withUnsafeMutableBytes { - (body: UnsafeMutableRawBufferPointer) in - if let baseAddress = body.baseAddress, body.count > 0 { - var out = baseAddress.assumingMemoryBound(to: UInt8.self) - while p[0] != terminator { - let byte = p[0] - p += 1 - switch byte { - case asciiBackslash: // "\\" - let escaped = p[0] - p += 1 - switch escaped { - case asciiZero...asciiSeven: // '0'...'7' - // C standard allows 1, 2, or 3 octal digits. - let digit1Value = escaped - asciiZero - let digit2 = p[0] - if digit2 >= asciiZero, digit2 <= asciiSeven { - p += 1 - let digit2Value = digit2 - asciiZero - let digit3 = p[0] - if digit3 >= asciiZero, digit3 <= asciiSeven { - p += 1 - let digit3Value = digit3 - asciiZero - out[0] = digit1Value &* 64 + digit2Value * 8 + digit3Value - out += 1 - } else { - out[0] = digit1Value * 8 + digit2Value - out += 1 - } - } else { - out[0] = digit1Value - out += 1 - } - case asciiLowerX: // 'x' hexadecimal escape - // We already validated, so we know there's at least one digit: - var n = fromHexDigit(p[0])! - p += 1 - if let digit = fromHexDigit(p[0]) { - n = n &* 16 &+ digit - p += 1 - } - out[0] = n - out += 1 - case asciiLowerA: // \a ("alert") - out[0] = asciiBell - out += 1 - case asciiLowerB: // \b - out[0] = asciiBackspace - out += 1 - case asciiLowerF: // \f - out[0] = asciiFormFeed - out += 1 - case asciiLowerN: // \n - out[0] = asciiNewLine - out += 1 - case asciiLowerR: // \r - out[0] = asciiCarriageReturn - out += 1 - case asciiLowerT: // \t - out[0] = asciiTab - out += 1 - case asciiLowerV: // \v - out[0] = asciiVerticalTab - out += 1 - default: - out[0] = escaped - out += 1 - } - default: - out[0] = byte - out += 1 - } - } - p += 1 // Consume terminator - } - } - } - - /// Assumes the leading quote has already been consumed - private mutating func parseStringSegment(terminator: UInt8) -> String? { - let start = p - var sawBackslash = false - while p != end { - let c = p[0] - if c == terminator { - let s = utf8ToString(bytes: start, count: p - start) - p += 1 - skipWhitespace() - if let s = s, sawBackslash { - return decodeString(s) - } else { - return s - } - } - p += 1 - if c == asciiBackslash { // \ - if p == end { - return nil - } - sawBackslash = true - p += 1 - } - } - return nil // Unterminated quoted string - } - - internal mutating func nextUInt() throws -> UInt64 { - if p == end { - throw TextFormatDecodingError.malformedNumber - } - let c = p[0] - p += 1 - if c == asciiZero { // leading '0' precedes octal or hex - if p[0] == asciiLowerX { // 'x' => hex - p += 1 - var n: UInt64 = 0 - while p != end { - let digit = p[0] - let val: UInt64 - switch digit { - case asciiZero...asciiNine: // 0...9 - val = UInt64(digit - asciiZero) - case asciiLowerA...asciiLowerF: // a...f - val = UInt64(digit - asciiLowerA + 10) - case asciiUpperA...asciiUpperF: - val = UInt64(digit - asciiUpperA + 10) - case asciiLowerU: // trailing 'u' - p += 1 - skipWhitespace() - return n - default: - skipWhitespace() - return n - } - if n > UInt64.max / 16 { - throw TextFormatDecodingError.malformedNumber - } - p += 1 - n = n * 16 + val - } - skipWhitespace() - return n - } else { // octal - var n: UInt64 = 0 - while p != end { - let digit = p[0] - if digit == asciiLowerU { // trailing 'u' - p += 1 - skipWhitespace() - return n - } - if digit < asciiZero || digit > asciiSeven { - skipWhitespace() - return n // not octal digit - } - let val = UInt64(digit - asciiZero) - if n > UInt64.max / 8 { - throw TextFormatDecodingError.malformedNumber - } - p += 1 - n = n * 8 + val - } - skipWhitespace() - return n - } - } else if c > asciiZero && c <= asciiNine { // 1...9 - var n = UInt64(c - asciiZero) - while p != end { - let digit = p[0] - if digit == asciiLowerU { // trailing 'u' - p += 1 - skipWhitespace() - return n - } - if digit < asciiZero || digit > asciiNine { - skipWhitespace() - return n // not a digit - } - let val = UInt64(digit - asciiZero) - if n > UInt64.max / 10 || n * 10 > UInt64.max - val { - throw TextFormatDecodingError.malformedNumber - } - p += 1 - n = n * 10 + val - } - skipWhitespace() - return n - } - throw TextFormatDecodingError.malformedNumber - } - - internal mutating func nextSInt() throws -> Int64 { - if p == end { - throw TextFormatDecodingError.malformedNumber - } - let c = p[0] - if c == asciiMinus { // - - p += 1 - // character after '-' must be digit - let digit = p[0] - if digit < asciiZero || digit > asciiNine { - throw TextFormatDecodingError.malformedNumber - } - let n = try nextUInt() - let limit: UInt64 = 0x8000000000000000 // -Int64.min - if n >= limit { - if n > limit { - // Too large negative number - throw TextFormatDecodingError.malformedNumber - } else { - return Int64.min // Special case for Int64.min - } - } - return -Int64(bitPattern: n) - } else { - let n = try nextUInt() - if n > UInt64(bitPattern: Int64.max) { - throw TextFormatDecodingError.malformedNumber - } - return Int64(bitPattern: n) - } - } - - internal mutating func nextStringValue() throws -> String { - var result: String - skipWhitespace() - if p == end { - throw TextFormatDecodingError.malformedText - } - let c = p[0] - if c != asciiSingleQuote && c != asciiDoubleQuote { - throw TextFormatDecodingError.malformedText - } - p += 1 - if let s = parseStringSegment(terminator: c) { - result = s - } else { - throw TextFormatDecodingError.malformedText - } - - while true { - if p == end { - return result - } - let c = p[0] - if c != asciiSingleQuote && c != asciiDoubleQuote { - return result - } - p += 1 - if let s = parseStringSegment(terminator: c) { - result.append(s) - } else { - throw TextFormatDecodingError.malformedText - } - } - } - - /// Protobuf Text Format allows a single bytes field to - /// contain multiple quoted strings. The values - /// are separately decoded and then concatenated: - /// field1: "bytes" 'more bytes' - /// "and even more bytes" - internal mutating func nextBytesValue() throws -> Data { - // Get the first string's contents - var result: Data - skipWhitespace() - if p == end { - throw TextFormatDecodingError.malformedText - } - let c = p[0] - if c != asciiSingleQuote && c != asciiDoubleQuote { - throw TextFormatDecodingError.malformedText - } - p += 1 - var sawBackslash = false - let n = try validateAndCountBytesFromString(terminator: c, sawBackslash: &sawBackslash) - if sawBackslash { - result = Data(count: n) - parseBytesFromString(terminator: c, into: &result) - } else { - result = Data(bytes: p, count: n) - p += n + 1 // Skip string body + close quote - } - - // If there are more strings, decode them - // and append to the result: - while true { - skipWhitespace() - if p == end { - return result - } - let c = p[0] - if c != asciiSingleQuote && c != asciiDoubleQuote { - return result - } - p += 1 - var sawBackslash = false - let n = try validateAndCountBytesFromString(terminator: c, sawBackslash: &sawBackslash) - if sawBackslash { - var b = Data(count: n) - parseBytesFromString(terminator: c, into: &b) - result.append(b) - } else { - result.append(p, count: n) - p += n + 1 // Skip string body + close quote - } - } - } - - // Tries to identify a sequence of UTF8 characters - // that represent a numeric floating-point value. - private mutating func tryParseFloatString() -> Double? { - guard p != end else {return nil} - let start = p - var c = p[0] - if c == asciiMinus { - p += 1 - guard p != end else {p = start; return nil} - c = p[0] - } - switch c { - case asciiZero: // '0' as first character is not allowed followed by digit - p += 1 - guard p != end else {break} - c = p[0] - if c >= asciiZero && c <= asciiNine { - p = start - return nil - } - case asciiPeriod: // '.' as first char only if followed by digit - p += 1 - guard p != end else {p = start; return nil} - c = p[0] - if c < asciiZero || c > asciiNine { - p = start - return nil - } - case asciiOne...asciiNine: - break - default: - p = start - return nil - } - loop: while p != end { - let c = p[0] - switch c { - case asciiZero...asciiNine, - asciiPeriod, - asciiPlus, - asciiMinus, - asciiLowerE, - asciiUpperE: // 0...9, ., +, -, e, E - p += 1 - case asciiLowerF: // f - // proto1 allowed floats to be suffixed with 'f' - let d = doubleParser.utf8ToDouble(bytes: start, count: p - start) - // Just skip the 'f' - p += 1 - skipWhitespace() - return d - default: - break loop - } - } - let d = doubleParser.utf8ToDouble(bytes: start, count: p - start) - skipWhitespace() - return d - } - - // Skip specified characters if they all match - private mutating func skipOptionalCharacters(bytes: [UInt8]) { - let start = p - for b in bytes { - if p == end || p[0] != b { - p = start - return - } - p += 1 - } - } - - // Skip following keyword if it matches (case-insensitively) - // the given keyword (specified as a series of bytes). - private mutating func skipOptionalKeyword(bytes: [UInt8]) -> Bool { - let start = p - for b in bytes { - if p == end { - p = start - return false - } - var c = p[0] - if c >= asciiUpperA && c <= asciiUpperZ { - // Convert to lower case - // (Protobuf text keywords are case insensitive) - c += asciiLowerA - asciiUpperA - } - if c != b { - p = start - return false - } - p += 1 - } - if p == end { - return true - } - let c = p[0] - if ((c >= asciiUpperA && c <= asciiUpperZ) - || (c >= asciiLowerA && c <= asciiLowerZ)) { - p = start - return false - } - skipWhitespace() - return true - } - - // If the next token is the identifier "nan", return true. - private mutating func skipOptionalNaN() -> Bool { - return skipOptionalKeyword(bytes: - [asciiLowerN, asciiLowerA, asciiLowerN]) - } - - // If the next token is a recognized spelling of "infinity", - // return Float.infinity or -Float.infinity - private mutating func skipOptionalInfinity() -> Float? { - if p == end { - return nil - } - let c = p[0] - let negated: Bool - if c == asciiMinus { - negated = true - p += 1 - } else { - negated = false - } - let inf = [asciiLowerI, asciiLowerN, asciiLowerF] - let infinity = [asciiLowerI, asciiLowerN, asciiLowerF, asciiLowerI, - asciiLowerN, asciiLowerI, asciiLowerT, asciiLowerY] - if (skipOptionalKeyword(bytes: inf) - || skipOptionalKeyword(bytes: infinity)) { - return negated ? -Float.infinity : Float.infinity - } - return nil - } - - internal mutating func nextFloat() throws -> Float { - if let d = tryParseFloatString() { - return Float(d) - } - if skipOptionalNaN() { - return Float.nan - } - if let inf = skipOptionalInfinity() { - return inf - } - throw TextFormatDecodingError.malformedNumber - } - - internal mutating func nextDouble() throws -> Double { - if let d = tryParseFloatString() { - return d - } - if skipOptionalNaN() { - return Double.nan - } - if let inf = skipOptionalInfinity() { - return Double(inf) - } - throw TextFormatDecodingError.malformedNumber - } - - internal mutating func nextBool() throws -> Bool { - skipWhitespace() - if p == end { - throw TextFormatDecodingError.malformedText - } - let c = p[0] - p += 1 - let result: Bool - switch c { - case asciiZero: - result = false - case asciiOne: - result = true - case asciiLowerF, asciiUpperF: - if p != end { - let alse = [asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE] - skipOptionalCharacters(bytes: alse) - } - result = false - case asciiLowerT, asciiUpperT: - if p != end { - let rue = [asciiLowerR, asciiLowerU, asciiLowerE] - skipOptionalCharacters(bytes: rue) - } - result = true - default: - throw TextFormatDecodingError.malformedText - } - if p == end { - return result - } - switch p[0] { - case asciiSpace, - asciiTab, - asciiNewLine, - asciiCarriageReturn, - asciiHash, - asciiComma, - asciiSemicolon, - asciiCloseSquareBracket, - asciiCloseCurlyBracket, - asciiCloseAngleBracket: - skipWhitespace() - return result - default: - throw TextFormatDecodingError.malformedText - } - } - - internal mutating func nextOptionalEnumName() throws -> UnsafeBufferPointer? { - skipWhitespace() - if p == end { - throw TextFormatDecodingError.malformedText - } - switch p[0] { - case asciiLowerA...asciiLowerZ, asciiUpperA...asciiUpperZ: - return parseUTF8Identifier() - default: - return nil - } - } - - /// Any URLs are syntactically (almost) identical to extension - /// keys, so we share the code for those. - internal mutating func nextOptionalAnyURL() throws -> String? { - return try nextOptionalExtensionKey() - } - - /// Returns next extension key or nil if end-of-input or - /// if next token is not an extension key. - /// - /// Throws an error if the next token starts with '[' but - /// cannot be parsed as an extension key. - /// - /// Note: This accepts / characters to support Any URL parsing. - /// Technically, Any URLs can contain / characters and extension - /// key names cannot. But in practice, accepting / chracters for - /// extension keys works fine, since the result just gets rejected - /// when the key is looked up. - internal mutating func nextOptionalExtensionKey() throws -> String? { - skipWhitespace() - if p == end { - return nil - } - if p[0] == asciiOpenSquareBracket { // [ - p += 1 - if let s = parseExtensionKey() { - if p == end || p[0] != asciiCloseSquareBracket { - throw TextFormatDecodingError.malformedText - } - // Skip ] - p += 1 - skipWhitespace() - return s - } else { - throw TextFormatDecodingError.malformedText - } - } - return nil - } - - /// Returns text of next regular key or nil if end-of-input. - /// This considers an extension key [keyname] to be an - /// error, so call nextOptionalExtensionKey first if you - /// want to handle extension keys. - /// - /// This is only used by map parsing; we should be able to - /// rework that to use nextFieldNumber instead. - internal mutating func nextKey() throws -> String? { - skipWhitespace() - if p == end { - return nil - } - let c = p[0] - switch c { - case asciiOpenSquareBracket: // [ - throw TextFormatDecodingError.malformedText - case asciiLowerA...asciiLowerZ, - asciiUpperA...asciiUpperZ, - asciiOne...asciiNine: // a...z, A...Z, 1...9 - return parseIdentifier() - default: - throw TextFormatDecodingError.malformedText - } - } - - /// Parse a field name, look it up, and return the corresponding - /// field number. - /// - /// returns nil at end-of-input - /// - /// Throws if field name cannot be parsed or if field name is - /// unknown. - /// - /// This function accounts for as much as 2/3 of the total run - /// time of the entire parse. - internal mutating func nextFieldNumber(names: _NameMap) throws -> Int? { - if p == end { - return nil - } - let c = p[0] - switch c { - case asciiLowerA...asciiLowerZ, - asciiUpperA...asciiUpperZ: // a...z, A...Z - let key = parseUTF8Identifier() - if let fieldNumber = names.number(forProtoName: key) { - return fieldNumber - } else { - throw TextFormatDecodingError.unknownField - } - case asciiOne...asciiNine: // 1-9 (field numbers are 123, not 0123) - var fieldNum = Int(c) - Int(asciiZero) - p += 1 - while p != end { - let c = p[0] - if c >= asciiZero && c <= asciiNine { - fieldNum = fieldNum &* 10 &+ (Int(c) - Int(asciiZero)) - } else { - break - } - p += 1 - } - skipWhitespace() - if names.names(for: fieldNum) != nil { - return fieldNum - } else { - // It was a number that isn't a known field. - // The C++ version (TextFormat::Parser::ParserImpl::ConsumeField()), - // supports an option to file or skip the field's value (this is true - // of unknown names or numbers). - throw TextFormatDecodingError.unknownField - } - default: - break - } - throw TextFormatDecodingError.malformedText - } - - private mutating func skipRequiredCharacter(_ c: UInt8) throws { - skipWhitespace() - if p != end && p[0] == c { - p += 1 - skipWhitespace() - } else { - throw TextFormatDecodingError.malformedText - } - } - - internal mutating func skipRequiredComma() throws { - try skipRequiredCharacter(asciiComma) - } - - internal mutating func skipRequiredColon() throws { - try skipRequiredCharacter(asciiColon) - } - - private mutating func skipOptionalCharacter(_ c: UInt8) -> Bool { - if p != end && p[0] == c { - p += 1 - skipWhitespace() - return true - } - return false - } - - internal mutating func skipOptionalColon() -> Bool { - return skipOptionalCharacter(asciiColon) - } - - internal mutating func skipOptionalEndArray() -> Bool { - return skipOptionalCharacter(asciiCloseSquareBracket) - } - - internal mutating func skipOptionalBeginArray() -> Bool { - return skipOptionalCharacter(asciiOpenSquareBracket) - } - - internal mutating func skipOptionalObjectEnd(_ c: UInt8) -> Bool { - return skipOptionalCharacter(c) - } - - internal mutating func skipOptionalSeparator() { - if p != end { - let c = p[0] - if c == asciiComma || c == asciiSemicolon { // comma or semicolon - p += 1 - skipWhitespace() - } - } - } - - /// Returns the character that should end this field. - /// E.g., if object starts with "{", returns "}" - internal mutating func skipObjectStart() throws -> UInt8 { - if p != end { - let c = p[0] - p += 1 - skipWhitespace() - switch c { - case asciiOpenCurlyBracket: // { - return asciiCloseCurlyBracket // } - case asciiOpenAngleBracket: // < - return asciiCloseAngleBracket // > - default: - break - } - } - throw TextFormatDecodingError.malformedText - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift deleted file mode 100644 index 8ae3790..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/TimeUtils.swift +++ /dev/null @@ -1,53 +0,0 @@ -// Sources/SwiftProtobuf/TimeUtils.swift - Generally useful time/calendar functions -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Generally useful time/calendar functions and constants -/// -// ----------------------------------------------------------------------------- - -let minutesPerDay: Int32 = 1440 -let minutesPerHour: Int32 = 60 -let secondsPerDay: Int32 = 86400 -let secondsPerHour: Int32 = 3600 -let secondsPerMinute: Int32 = 60 -let nanosPerSecond: Int32 = 1000000000 - -internal func timeOfDayFromSecondsSince1970(seconds: Int64) -> (hh: Int32, mm: Int32, ss: Int32) { - let secondsSinceMidnight = Int32(mod(seconds, Int64(secondsPerDay))) - let ss = mod(secondsSinceMidnight, secondsPerMinute) - let mm = mod(div(secondsSinceMidnight, secondsPerMinute), minutesPerHour) - let hh = Int32(div(secondsSinceMidnight, secondsPerHour)) - - return (hh: hh, mm: mm, ss: ss) -} - -internal func julianDayNumberFromSecondsSince1970(seconds: Int64) -> Int64 { - // January 1, 1970 is Julian Day Number 2440588. - // See http://aa.usno.navy.mil/faq/docs/JD_Formula.php - return div(seconds + 2440588 * Int64(secondsPerDay), Int64(secondsPerDay)) -} - -internal func gregorianDateFromSecondsSince1970(seconds: Int64) -> (YY: Int32, MM: Int32, DD: Int32) { - // The following implements Richards' algorithm (see the Wikipedia article - // for "Julian day"). - // If you touch this code, please test it exhaustively by playing with - // Test_Timestamp.testJSON_range. - - let JJ = julianDayNumberFromSecondsSince1970(seconds: seconds) - let f = JJ + 1401 + div(div(4 * JJ + 274277, 146097) * 3, 4) - 38 - let e = 4 * f + 3 - let g = Int64(div(mod(e, 1461), 4)) - let h = 5 * g + 2 - let DD = div(mod(h, 153), 5) + 1 - let MM = mod(div(h, 153) + 2, 12) + 1 - let YY = div(e, 1461) - 4716 + div(12 + 2 - MM, 12) - - return (YY: Int32(YY), MM: Int32(MM), DD: Int32(DD)) -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift deleted file mode 100644 index 9501bc6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/UnknownStorage.swift +++ /dev/null @@ -1,46 +0,0 @@ -// Sources/SwiftProtobuf/UnknownStorage.swift - Handling unknown fields -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Proto2 binary coding requires storing and recoding of unknown fields. -/// This simple support class handles that requirement. A property of this type -/// is compiled into every proto2 message. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// Contains any unknown fields in a decoded message; that is, fields that were -/// sent on the wire but were not recognized by the generated message -/// implementation or were valid field numbers but with mismatching wire -/// formats (for example, a field encoded as a varint when a fixed32 integer -/// was expected). -public struct UnknownStorage: Equatable { - /// The raw protocol buffer binary-encoded bytes that represent the unknown - /// fields of a decoded message. - public private(set) var data = Internal.emptyData - -#if !swift(>=4.1) - public static func ==(lhs: UnknownStorage, rhs: UnknownStorage) -> Bool { - return lhs.data == rhs.data - } -#endif - - public init() {} - - internal mutating func append(protobufData: Data) { - data.append(protobufData) - } - - public func traverse(visitor: inout V) throws { - if !data.isEmpty { - try visitor.visitUnknown(bytes: data) - } - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift deleted file mode 100644 index 613a2d1..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Varint.swift +++ /dev/null @@ -1,108 +0,0 @@ -// Sources/SwiftProtobuf/Varint.swift - Varint encoding/decoding helpers -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Helper functions to varint-encode and decode integers. -/// -// ----------------------------------------------------------------------------- - - -/// Contains helper methods to varint-encode and decode integers. -internal enum Varint { - - /// Computes the number of bytes that would be needed to store a 32-bit varint. - /// - /// - Parameter value: The number whose varint size should be calculated. - /// - Returns: The size, in bytes, of the 32-bit varint. - static func encodedSize(of value: UInt32) -> Int { - if (value & (~0 << 7)) == 0 { - return 1 - } - if (value & (~0 << 14)) == 0 { - return 2 - } - if (value & (~0 << 21)) == 0 { - return 3 - } - if (value & (~0 << 28)) == 0 { - return 4 - } - return 5 - } - - /// Computes the number of bytes that would be needed to store a signed 32-bit varint, if it were - /// treated as an unsigned integer with the same bit pattern. - /// - /// - Parameter value: The number whose varint size should be calculated. - /// - Returns: The size, in bytes, of the 32-bit varint. - static func encodedSize(of value: Int32) -> Int { - if value >= 0 { - return encodedSize(of: UInt32(bitPattern: value)) - } else { - // Must sign-extend. - return encodedSize(of: Int64(value)) - } - } - - /// Computes the number of bytes that would be needed to store a 64-bit varint. - /// - /// - Parameter value: The number whose varint size should be calculated. - /// - Returns: The size, in bytes, of the 64-bit varint. - static func encodedSize(of value: Int64) -> Int { - // Handle two common special cases up front. - if (value & (~0 << 7)) == 0 { - return 1 - } - if value < 0 { - return 10 - } - - // Divide and conquer the remaining eight cases. - var value = value - var n = 2 - - if (value & (~0 << 35)) != 0 { - n += 4 - value >>= 28 - } - if (value & (~0 << 21)) != 0 { - n += 2 - value >>= 14 - } - if (value & (~0 << 14)) != 0 { - n += 1 - } - return n - } - - /// Computes the number of bytes that would be needed to store an unsigned 64-bit varint, if it - /// were treated as a signed integer witht he same bit pattern. - /// - /// - Parameter value: The number whose varint size should be calculated. - /// - Returns: The size, in bytes, of the 64-bit varint. - static func encodedSize(of value: UInt64) -> Int { - return encodedSize(of: Int64(bitPattern: value)) - } - - /// Counts the number of distinct varints in a packed byte buffer. - static func countVarintsInBuffer(start: UnsafePointer, count: Int) -> Int { - // We don't need to decode all the varints to count how many there - // are. Just observe that every varint has exactly one byte with - // value < 128. So we just count those... - var n = 0 - var ints = 0 - while n < count { - if start[n] < 128 { - ints += 1 - } - n += 1 - } - return ints - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift deleted file mode 100644 index 848e2e4..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Version.swift +++ /dev/null @@ -1,28 +0,0 @@ -// Sources/SwiftProtobuf/Version.swift - Runtime Version info -// -// Copyright (c) 2014 - 2017 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// A interface for exposing the version of the runtime. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -// Expose version information about the library. -public struct Version { - /// Major version. - public static let major = 1 - /// Minor version. - public static let minor = 6 - /// Revision number. - public static let revision = 0 - - /// String form of the version number. - public static let versionString = "\(major).\(minor).\(revision)" -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift deleted file mode 100644 index 0f28085..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/Visitor.swift +++ /dev/null @@ -1,693 +0,0 @@ -// Sources/SwiftProtobuf/Visitor.swift - Basic serialization machinery -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Protocol for traversing the object tree. -/// -/// This is used by: -/// = Protobuf serialization -/// = JSON serialization (with some twists to account for specialty JSON -/// encodings) -/// = Protobuf text serialization -/// = Hashable computation -/// -/// Conceptually, serializers create visitor objects that are -/// then passed recursively to every message and field via generated -/// 'traverse' methods. The details get a little involved due to -/// the need to allow particular messages to override particular -/// behaviors for specific encodings, but the general idea is quite simple. -/// -// ----------------------------------------------------------------------------- - -import Foundation - -/// This is the key interface used by the generated `traverse()` methods -/// used for serialization. It is implemented by each serialization protocol: -/// Protobuf Binary, Protobuf Text, JSON, and the Hash encoder. -public protocol Visitor { - - /// Called for each non-repeated float field - /// - /// A default implementation is provided that just widens the value - /// and calls `visitSingularDoubleField` - mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws - - /// Called for each non-repeated double field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws - - /// Called for each non-repeated int32 field - /// - /// A default implementation is provided that just widens the value - /// and calls `visitSingularInt64Field` - mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws - - /// Called for each non-repeated int64 field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws - - /// Called for each non-repeated uint32 field - /// - /// A default implementation is provided that just widens the value - /// and calls `visitSingularUInt64Field` - mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws - - /// Called for each non-repeated uint64 field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws - - /// Called for each non-repeated sint32 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularInt32Field` - mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws - - /// Called for each non-repeated sint64 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularInt64Field` - mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws - - /// Called for each non-repeated fixed32 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularUInt32Field` - mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws - - /// Called for each non-repeated fixed64 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularUInt64Field` - mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws - - /// Called for each non-repeated sfixed32 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularInt32Field` - mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws - - /// Called for each non-repeated sfixed64 field - /// - /// A default implementation is provided that just forwards to - /// `visitSingularInt64Field` - mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws - - /// Called for each non-repeated bool field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws - - /// Called for each non-repeated string field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularStringField(value: String, fieldNumber: Int) throws - - /// Called for each non-repeated bytes field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws - - /// Called for each non-repeated enum field - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws - - /// Called for each non-repeated nested message field. - /// - /// There is no default implementation. This must be implemented. - mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws - - /// Called for each non-repeated proto2 group field. - /// - /// A default implementation is provided that simply forwards to - /// `visitSingularMessageField`. Implementors who need to handle groups - /// differently than nested messages can override this and provide distinct - /// implementations. - mutating func visitSingularGroupField(value: G, fieldNumber: Int) throws - - // Called for each non-packed repeated float field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularFloatField` once for each item in the array. - mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws - - // Called for each non-packed repeated double field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularDoubleField` once for each item in the array. - mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws - - // Called for each non-packed repeated int32 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularInt32Field` once for each item in the array. - mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each non-packed repeated int64 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularInt64Field` once for each item in the array. - mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each non-packed repeated uint32 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularUInt32Field` once for each item in the array. - mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws - - // Called for each non-packed repeated uint64 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularUInt64Field` once for each item in the array. - mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws - - // Called for each non-packed repeated sint32 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularSInt32Field` once for each item in the array. - mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each non-packed repeated sint64 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularSInt64Field` once for each item in the array. - mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each non-packed repeated fixed32 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularFixed32Field` once for each item in the array. - mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws - - // Called for each non-packed repeated fixed64 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularFixed64Field` once for each item in the array. - mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws - - // Called for each non-packed repeated sfixed32 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularSFixed32Field` once for each item in the array. - mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each non-packed repeated sfixed64 field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularSFixed64Field` once for each item in the array. - mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each non-packed repeated bool field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularBoolField` once for each item in the array. - mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws - - // Called for each non-packed repeated string field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularStringField` once for each item in the array. - mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws - - // Called for each non-packed repeated bytes field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularBytesField` once for each item in the array. - mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws - - /// Called for each repeated, unpacked enum field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularEnumField` once for each item in the array. - mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws - - /// Called for each repeated nested message field. The method is called once - /// with the complete array of values for the field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularMessageField` once for each item in the array. - mutating func visitRepeatedMessageField(value: [M], - fieldNumber: Int) throws - - /// Called for each repeated proto2 group field. - /// - /// A default implementation is provided that simply calls - /// `visitSingularGroupField` once for each item in the array. - mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws - - // Called for each packed, repeated float field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws - - // Called for each packed, repeated double field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws - - // Called for each packed, repeated int32 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each packed, repeated int64 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each packed, repeated uint32 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws - - // Called for each packed, repeated uint64 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws - - // Called for each packed, repeated sint32 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each packed, repeated sint64 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each packed, repeated fixed32 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws - - // Called for each packed, repeated fixed64 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws - - // Called for each packed, repeated sfixed32 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws - - // Called for each packed, repeated sfixed64 field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws - - // Called for each packed, repeated bool field. - /// - /// This is called once with the complete array of values for - /// the field. - /// - /// There is a default implementation that forwards to the non-packed - /// function. - mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws - - /// Called for each repeated, packed enum field. - /// The method is called once with the complete array of values for - /// the field. - /// - /// A default implementation is provided that simply forwards to - /// `visitRepeatedEnumField`. Implementors who need to handle packed fields - /// differently than unpacked fields can override this and provide distinct - /// implementations. - mutating func visitPackedEnumField(value: [E], fieldNumber: Int) throws - - /// Called for each map field with primitive values. The method is - /// called once with the complete dictionary of keys/values for the - /// field. - /// - /// There is no default implementation. This must be implemented. - mutating func visitMapField( - fieldType: _ProtobufMap.Type, - value: _ProtobufMap.BaseType, - fieldNumber: Int) throws - - /// Called for each map field with enum values. The method is called - /// once with the complete dictionary of keys/values for the field. - /// - /// There is no default implementation. This must be implemented. - mutating func visitMapField( - fieldType: _ProtobufEnumMap.Type, - value: _ProtobufEnumMap.BaseType, - fieldNumber: Int) throws where ValueType.RawValue == Int - - /// Called for each map field with message values. The method is - /// called once with the complete dictionary of keys/values for the - /// field. - /// - /// There is no default implementation. This must be implemented. - mutating func visitMapField( - fieldType: _ProtobufMessageMap.Type, - value: _ProtobufMessageMap.BaseType, - fieldNumber: Int) throws - - /// Called for each extension range. - mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws - - /// Called for each extension range. - mutating func visitExtensionFieldsAsMessageSet( - fields: ExtensionFieldValueSet, - start: Int, - end: Int) throws - - /// Called with the raw bytes that represent any unknown fields. - mutating func visitUnknown(bytes: Data) throws -} - -/// Forwarding default implementations of some visitor methods, for convenience. -extension Visitor { - - // Default definitions of numeric serializations. - // - // The 32-bit versions widen and delegate to 64-bit versions. - // The specialized integer codings delegate to standard Int/UInt. - // - // These "just work" for Hash and Text formats. Most of these work - // for JSON (32-bit integers are overridden to suppress quoting), - // and a few even work for Protobuf Binary (thanks to varint coding - // which erases the size difference between 32-bit and 64-bit ints). - - public mutating func visitSingularFloatField(value: Float, fieldNumber: Int) throws { - try visitSingularDoubleField(value: Double(value), fieldNumber: fieldNumber) - } - public mutating func visitSingularInt32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt64Field(value: Int64(value), fieldNumber: fieldNumber) - } - public mutating func visitSingularUInt32Field(value: UInt32, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: UInt64(value), fieldNumber: fieldNumber) - } - public mutating func visitSingularSInt32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) - } - public mutating func visitSingularSInt64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) - } - public mutating func visitSingularFixed32Field(value: UInt32, fieldNumber: Int) throws { - try visitSingularUInt32Field(value: value, fieldNumber: fieldNumber) - } - public mutating func visitSingularFixed64Field(value: UInt64, fieldNumber: Int) throws { - try visitSingularUInt64Field(value: value, fieldNumber: fieldNumber) - } - public mutating func visitSingularSFixed32Field(value: Int32, fieldNumber: Int) throws { - try visitSingularInt32Field(value: value, fieldNumber: fieldNumber) - } - public mutating func visitSingularSFixed64Field(value: Int64, fieldNumber: Int) throws { - try visitSingularInt64Field(value: value, fieldNumber: fieldNumber) - } - - // Default definitions of repeated serializations that just iterate and - // invoke the singular encoding. These "just work" for Protobuf Binary (encoder - // and size visitor), Protobuf Text, and Hash visitors. JSON format stores - // repeated values differently from singular, so overrides these. - - public mutating func visitRepeatedFloatField(value: [Float], fieldNumber: Int) throws { - for v in value { - try visitSingularFloatField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedDoubleField(value: [Double], fieldNumber: Int) throws { - for v in value { - try visitSingularDoubleField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedInt32Field(value: [Int32], fieldNumber: Int) throws { - for v in value { - try visitSingularInt32Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedInt64Field(value: [Int64], fieldNumber: Int) throws { - for v in value { - try visitSingularInt64Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - for v in value { - try visitSingularUInt32Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - for v in value { - try visitSingularUInt64Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedSInt32Field(value: [Int32], fieldNumber: Int) throws { - for v in value { - try visitSingularSInt32Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedSInt64Field(value: [Int64], fieldNumber: Int) throws { - for v in value { - try visitSingularSInt64Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - for v in value { - try visitSingularFixed32Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - for v in value { - try visitSingularFixed64Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - for v in value { - try visitSingularSFixed32Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - for v in value { - try visitSingularSFixed64Field(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedBoolField(value: [Bool], fieldNumber: Int) throws { - for v in value { - try visitSingularBoolField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedStringField(value: [String], fieldNumber: Int) throws { - for v in value { - try visitSingularStringField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedBytesField(value: [Data], fieldNumber: Int) throws { - for v in value { - try visitSingularBytesField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - for v in value { - try visitSingularEnumField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedMessageField(value: [M], fieldNumber: Int) throws { - for v in value { - try visitSingularMessageField(value: v, fieldNumber: fieldNumber) - } - } - - public mutating func visitRepeatedGroupField(value: [G], fieldNumber: Int) throws { - for v in value { - try visitSingularGroupField(value: v, fieldNumber: fieldNumber) - } - } - - // Default definitions of packed serialization just defer to the - // repeated implementation. This works for Hash and JSON visitors - // (which do not distinguish packed vs. non-packed) but are - // overridden by Protobuf Binary and Text. - - public mutating func visitPackedFloatField(value: [Float], fieldNumber: Int) throws { - try visitRepeatedFloatField(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedDoubleField(value: [Double], fieldNumber: Int) throws { - try visitRepeatedDoubleField(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedInt32Field(value: [Int32], fieldNumber: Int) throws { - try visitRepeatedInt32Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedInt64Field(value: [Int64], fieldNumber: Int) throws { - try visitRepeatedInt64Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedUInt32Field(value: [UInt32], fieldNumber: Int) throws { - try visitRepeatedUInt32Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedUInt64Field(value: [UInt64], fieldNumber: Int) throws { - try visitRepeatedUInt64Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedSInt32Field(value: [Int32], fieldNumber: Int) throws { - try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedSInt64Field(value: [Int64], fieldNumber: Int) throws { - try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedFixed32Field(value: [UInt32], fieldNumber: Int) throws { - try visitPackedUInt32Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedFixed64Field(value: [UInt64], fieldNumber: Int) throws { - try visitPackedUInt64Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedSFixed32Field(value: [Int32], fieldNumber: Int) throws { - try visitPackedInt32Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedSFixed64Field(value: [Int64], fieldNumber: Int) throws { - try visitPackedInt64Field(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedBoolField(value: [Bool], fieldNumber: Int) throws { - try visitRepeatedBoolField(value: value, fieldNumber: fieldNumber) - } - - public mutating func visitPackedEnumField(value: [E], - fieldNumber: Int) throws { - try visitRepeatedEnumField(value: value, fieldNumber: fieldNumber) - } - - // Default handling for Groups is to treat them just like messages. - // This works for Text and Hash, but is overridden by Protobuf Binary - // format (which has a different encoding for groups) and JSON - // (which explicitly ignores all groups). - - public mutating func visitSingularGroupField(value: G, - fieldNumber: Int) throws { - try visitSingularMessageField(value: value, fieldNumber: fieldNumber) - } - - // Default handling of Extensions as a MessageSet to handing them just - // as plain extensions. Formats that what custom behavior can override - // it. - - public mutating func visitExtensionFieldsAsMessageSet( - fields: ExtensionFieldValueSet, - start: Int, - end: Int) throws { - try visitExtensionFields(fields: fields, start: start, end: end) - } - - // Default handling for Extensions is to forward the traverse to - // the ExtensionFieldValueSet. Formats that don't care about extensions - // can override to avoid it. - - /// Called for each extension range. - public mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws { - try fields.traverse(visitor: &self, start: start, end: end) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift deleted file mode 100644 index ea28c40..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/WireFormat.swift +++ /dev/null @@ -1,70 +0,0 @@ -// Sources/SwiftProtobuf/WireFormat.swift - Describes proto wire formats -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Types related to binary wire formats of encoded values. -/// -// ----------------------------------------------------------------------------- - -/// Denotes the wire format by which a value is encoded in binary form. -internal enum WireFormat: UInt8 { - case varint = 0 - case fixed64 = 1 - case lengthDelimited = 2 - case startGroup = 3 - case endGroup = 4 - case fixed32 = 5 -} - -extension WireFormat { - /// Information about the "MessageSet" format. Used when a Message has - /// the message_set_wire_format option enabled. - /// - /// Writing in MessageSet form means instead of writing the Extesions - /// normally as a simple fields, each gets written wrapped in a group: - /// repeated group Item = 1 { - /// required int32 type_id = 2; - /// required bytes message = 3; - /// } - /// Where the field number is the type_id, and the message is serilaized - /// into the bytes. - /// - /// The handling of unknown fields is ill defined. In proto1, they were - /// dropped. In the C++ for proto2, since it stores them in the unknowns - /// storage, if preserves any that are length delimited data (since that's - /// how the message also goes out). While the C++ is parsing, where the - /// unknowns fall in the flow of the group, sorta decides what happens. - /// Since it is ill defined, currently SwiftProtobuf will reflect out - /// anything set in the unknownStorage. During parsing, unknowns on the - /// message are preserved, but unknowns within the group are dropped (like - /// map items). Any extension in the MessageSet that isn't in the Regisry - /// being used at parse time will remain in a group and go into the - /// Messages's unknown fields (this way it reflects back out correctly). - internal enum MessageSet { - - enum FieldNumbers { - static let item = 1; - static let typeId = 2; - static let message = 3; - } - - enum Tags { - static let itemStart = FieldTag(fieldNumber: FieldNumbers.item, wireFormat: .startGroup) - static let itemEnd = FieldTag(fieldNumber: FieldNumbers.item, wireFormat: .endGroup) - static let typeId = FieldTag(fieldNumber: FieldNumbers.typeId, wireFormat: .varint) - static let message = FieldTag(fieldNumber: FieldNumbers.message, wireFormat: .lengthDelimited) - } - - // The size of all the tags needed to write out an Extension in MessageSet format. - static let itemTagsEncodedSize = - Tags.itemStart.encodedSize + Tags.itemEnd.encodedSize + - Tags.typeId.encodedSize + - Tags.message.encodedSize - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift deleted file mode 100644 index f838ac6..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/ZigZag.swift +++ /dev/null @@ -1,66 +0,0 @@ -// Sources/SwiftProtobuf/ZigZag.swift - ZigZag encoding/decoding helpers -// -// Copyright (c) 2014 - 2016 Apple Inc. and the project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See LICENSE.txt for license information: -// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt -// -// ----------------------------------------------------------------------------- -/// -/// Helper functions to ZigZag encode and decode signed integers. -/// -// ----------------------------------------------------------------------------- - - -/// Contains helper methods to ZigZag encode and decode signed integers. -internal enum ZigZag { - - /// Return a 32-bit ZigZag-encoded value. - /// - /// ZigZag encodes signed integers into values that can be efficiently encoded with varint. - /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always - /// taking 10 bytes on the wire.) - /// - /// - Parameter value: A signed 32-bit integer. - /// - Returns: An unsigned 32-bit integer representing the ZigZag-encoded value. - static func encoded(_ value: Int32) -> UInt32 { - return UInt32(bitPattern: (value << 1) ^ (value >> 31)) - } - - /// Return a 64-bit ZigZag-encoded value. - /// - /// ZigZag encodes signed integers into values that can be efficiently encoded with varint. - /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always - /// taking 10 bytes on the wire.) - /// - /// - Parameter value: A signed 64-bit integer. - /// - Returns: An unsigned 64-bit integer representing the ZigZag-encoded value. - static func encoded(_ value: Int64) -> UInt64 { - return UInt64(bitPattern: (value << 1) ^ (value >> 63)) - } - - /// Return a 32-bit ZigZag-decoded value. - /// - /// ZigZag enocdes signed integers into values that can be efficiently encoded with varint. - /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always - /// taking 10 bytes on the wire.) - /// - /// - Parameter value: An unsigned 32-bit ZagZag-encoded integer. - /// - Returns: The signed 32-bit decoded value. - static func decoded(_ value: UInt32) -> Int32 { - return Int32(value >> 1) ^ -Int32(value & 1) - } - - /// Return a 64-bit ZigZag-decoded value. - /// - /// ZigZag enocdes signed integers into values that can be efficiently encoded with varint. - /// (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, always - /// taking 10 bytes on the wire.) - /// - /// - Parameter value: An unsigned 64-bit ZigZag-encoded integer. - /// - Returns: The signed 64-bit decoded value. - static func decoded(_ value: UInt64) -> Int64 { - return Int64(value >> 1) ^ -Int64(value & 1) - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift deleted file mode 100644 index 3f56e2f..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/any.pb.swift +++ /dev/null @@ -1,234 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/any.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// `Any` contains an arbitrary serialized protocol buffer message along with a -/// URL that describes the type of the serialized message. -/// -/// Protobuf library provides support to pack/unpack Any values in the form -/// of utility functions or additional generated methods of the Any type. -/// -/// Example 1: Pack and unpack a message in C++. -/// -/// Foo foo = ...; -/// Any any; -/// any.PackFrom(foo); -/// ... -/// if (any.UnpackTo(&foo)) { -/// ... -/// } -/// -/// Example 2: Pack and unpack a message in Java. -/// -/// Foo foo = ...; -/// Any any = Any.pack(foo); -/// ... -/// if (any.is(Foo.class)) { -/// foo = any.unpack(Foo.class); -/// } -/// -/// Example 3: Pack and unpack a message in Python. -/// -/// foo = Foo(...) -/// any = Any() -/// any.Pack(foo) -/// ... -/// if any.Is(Foo.DESCRIPTOR): -/// any.Unpack(foo) -/// ... -/// -/// Example 4: Pack and unpack a message in Go -/// -/// foo := &pb.Foo{...} -/// any, err := ptypes.MarshalAny(foo) -/// ... -/// foo := &pb.Foo{} -/// if err := ptypes.UnmarshalAny(any, foo); err != nil { -/// ... -/// } -/// -/// The pack methods provided by protobuf library will by default use -/// 'type.googleapis.com/full.type.name' as the type URL and the unpack -/// methods only use the fully qualified type name after the last '/' -/// in the type URL, for example "foo.bar.com/x/y.z" will yield type -/// name "y.z". -/// -/// -/// JSON -/// ==== -/// The JSON representation of an `Any` value uses the regular -/// representation of the deserialized, embedded message, with an -/// additional field `@type` which contains the type URL. Example: -/// -/// package google.profile; -/// message Person { -/// string first_name = 1; -/// string last_name = 2; -/// } -/// -/// { -/// "@type": "type.googleapis.com/google.profile.Person", -/// "firstName": , -/// "lastName": -/// } -/// -/// If the embedded message type is well-known and has a custom JSON -/// representation, that representation will be embedded adding a field -/// `value` which holds the custom JSON in addition to the `@type` -/// field. Example (for message [google.protobuf.Duration][]): -/// -/// { -/// "@type": "type.googleapis.com/google.protobuf.Duration", -/// "value": "1.212s" -/// } -public struct Google_Protobuf_Any { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// A URL/resource name that uniquely identifies the type of the serialized - /// protocol buffer message. This string must contain at least - /// one "/" character. The last segment of the URL's path must represent - /// the fully qualified name of the type (as in - /// `path/google.protobuf.Duration`). The name should be in a canonical form - /// (e.g., leading "." is not accepted). - /// - /// In practice, teams usually precompile into the binary all types that they - /// expect it to use in the context of Any. However, for URLs which use the - /// scheme `http`, `https`, or no scheme, one can optionally set up a type - /// server that maps type URLs to message definitions as follows: - /// - /// * If no scheme is provided, `https` is assumed. - /// * An HTTP GET on the URL must yield a [google.protobuf.Type][] - /// value in binary format, or produce an error. - /// * Applications are allowed to cache lookup results based on the - /// URL, or have them precompiled into a binary to avoid any - /// lookup. Therefore, binary compatibility needs to be preserved - /// on changes to types. (Use versioned type names to manage - /// breaking changes.) - /// - /// Note: this functionality is not currently available in the official - /// protobuf release, and it is not used for type URLs beginning with - /// type.googleapis.com. - /// - /// Schemes other than `http`, `https` (or the empty scheme) might be - /// used with implementation specific semantics. - public var typeURL: String { - get {return _storage._typeURL} - set {_uniqueStorage()._typeURL = newValue} - } - - /// Must be a valid serialized protocol buffer of the above specified type. - public var value: Data { - get {return _storage._value} - set {_uniqueStorage()._value = newValue} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - internal var _storage = _StorageClass.defaultInstance -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Any: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Any" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "type_url"), - 2: .same(proto: "value"), - ] - - typealias _StorageClass = AnyMessageStorage - - internal mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &_storage._typeURL) - case 2: try decoder.decodeSingularBytesField(value: &_storage._value) - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - try _storage.preTraverse() - if !_storage._typeURL.isEmpty { - try visitor.visitSingularStringField(value: _storage._typeURL, fieldNumber: 1) - } - if !_storage._value.isEmpty { - try visitor.visitSingularBytesField(value: _storage._value, fieldNumber: 2) - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Any, rhs: Google_Protobuf_Any) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = lhs._storage.isEqualTo(other: rhs._storage) - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift deleted file mode 100644 index 268c436..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/api.pb.swift +++ /dev/null @@ -1,476 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/api.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// Api is a light-weight descriptor for an API Interface. -/// -/// Interfaces are also described as "protocol buffer services" in some contexts, -/// such as by the "service" keyword in a .proto file, but they are different -/// from API Services, which represent a concrete implementation of an interface -/// as opposed to simply a description of methods and bindings. They are also -/// sometimes simply referred to as "APIs" in other contexts, such as the name of -/// this message itself. See https://cloud.google.com/apis/design/glossary for -/// detailed terminology. -public struct Google_Protobuf_Api { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The fully qualified name of this interface, including package name - /// followed by the interface's simple name. - public var name: String { - get {return _storage._name} - set {_uniqueStorage()._name = newValue} - } - - /// The methods of this interface, in unspecified order. - public var methods: [Google_Protobuf_Method] { - get {return _storage._methods} - set {_uniqueStorage()._methods = newValue} - } - - /// Any metadata attached to the interface. - public var options: [Google_Protobuf_Option] { - get {return _storage._options} - set {_uniqueStorage()._options = newValue} - } - - /// A version string for this interface. If specified, must have the form - /// `major-version.minor-version`, as in `1.10`. If the minor version is - /// omitted, it defaults to zero. If the entire version field is empty, the - /// major version is derived from the package name, as outlined below. If the - /// field is not empty, the version in the package name will be verified to be - /// consistent with what is provided here. - /// - /// The versioning schema uses [semantic - /// versioning](http://semver.org) where the major version number - /// indicates a breaking change and the minor version an additive, - /// non-breaking change. Both version numbers are signals to users - /// what to expect from different versions, and should be carefully - /// chosen based on the product plan. - /// - /// The major version is also reflected in the package name of the - /// interface, which must end in `v`, as in - /// `google.feature.v1`. For major versions 0 and 1, the suffix can - /// be omitted. Zero major versions must only be used for - /// experimental, non-GA interfaces. - public var version: String { - get {return _storage._version} - set {_uniqueStorage()._version = newValue} - } - - /// Source context for the protocol buffer service represented by this - /// message. - public var sourceContext: Google_Protobuf_SourceContext { - get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} - set {_uniqueStorage()._sourceContext = newValue} - } - /// Returns true if `sourceContext` has been explicitly set. - public var hasSourceContext: Bool {return _storage._sourceContext != nil} - /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. - public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} - - /// Included interfaces. See [Mixin][]. - public var mixins: [Google_Protobuf_Mixin] { - get {return _storage._mixins} - set {_uniqueStorage()._mixins = newValue} - } - - /// The source syntax of the service. - public var syntax: Google_Protobuf_Syntax { - get {return _storage._syntax} - set {_uniqueStorage()._syntax = newValue} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _storage = _StorageClass.defaultInstance -} - -/// Method represents a method of an API interface. -public struct Google_Protobuf_Method { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The simple name of this method. - public var name: String = String() - - /// A URL of the input message type. - public var requestTypeURL: String = String() - - /// If true, the request is streamed. - public var requestStreaming: Bool = false - - /// The URL of the output message type. - public var responseTypeURL: String = String() - - /// If true, the response is streamed. - public var responseStreaming: Bool = false - - /// Any metadata attached to the method. - public var options: [Google_Protobuf_Option] = [] - - /// The source syntax of this method. - public var syntax: Google_Protobuf_Syntax = .proto2 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Declares an API Interface to be included in this interface. The including -/// interface must redeclare all the methods from the included interface, but -/// documentation and options are inherited as follows: -/// -/// - If after comment and whitespace stripping, the documentation -/// string of the redeclared method is empty, it will be inherited -/// from the original method. -/// -/// - Each annotation belonging to the service config (http, -/// visibility) which is not set in the redeclared method will be -/// inherited. -/// -/// - If an http annotation is inherited, the path pattern will be -/// modified as follows. Any version prefix will be replaced by the -/// version of the including interface plus the [root][] path if -/// specified. -/// -/// Example of a simple mixin: -/// -/// package google.acl.v1; -/// service AccessControl { -/// // Get the underlying ACL object. -/// rpc GetAcl(GetAclRequest) returns (Acl) { -/// option (google.api.http).get = "/v1/{resource=**}:getAcl"; -/// } -/// } -/// -/// package google.storage.v2; -/// service Storage { -/// rpc GetAcl(GetAclRequest) returns (Acl); -/// -/// // Get a data record. -/// rpc GetData(GetDataRequest) returns (Data) { -/// option (google.api.http).get = "/v2/{resource=**}"; -/// } -/// } -/// -/// Example of a mixin configuration: -/// -/// apis: -/// - name: google.storage.v2.Storage -/// mixins: -/// - name: google.acl.v1.AccessControl -/// -/// The mixin construct implies that all methods in `AccessControl` are -/// also declared with same name and request/response types in -/// `Storage`. A documentation generator or annotation processor will -/// see the effective `Storage.GetAcl` method after inherting -/// documentation and annotations as follows: -/// -/// service Storage { -/// // Get the underlying ACL object. -/// rpc GetAcl(GetAclRequest) returns (Acl) { -/// option (google.api.http).get = "/v2/{resource=**}:getAcl"; -/// } -/// ... -/// } -/// -/// Note how the version in the path pattern changed from `v1` to `v2`. -/// -/// If the `root` field in the mixin is specified, it should be a -/// relative path under which inherited HTTP paths are placed. Example: -/// -/// apis: -/// - name: google.storage.v2.Storage -/// mixins: -/// - name: google.acl.v1.AccessControl -/// root: acls -/// -/// This implies the following inherited HTTP annotation: -/// -/// service Storage { -/// // Get the underlying ACL object. -/// rpc GetAcl(GetAclRequest) returns (Acl) { -/// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; -/// } -/// ... -/// } -public struct Google_Protobuf_Mixin { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The fully qualified name of the interface which is included. - public var name: String = String() - - /// If non-empty specifies a path under which inherited HTTP paths - /// are rooted. - public var root: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Api: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Api" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "methods"), - 3: .same(proto: "options"), - 4: .same(proto: "version"), - 5: .standard(proto: "source_context"), - 6: .same(proto: "mixins"), - 7: .same(proto: "syntax"), - ] - - fileprivate class _StorageClass { - var _name: String = String() - var _methods: [Google_Protobuf_Method] = [] - var _options: [Google_Protobuf_Option] = [] - var _version: String = String() - var _sourceContext: Google_Protobuf_SourceContext? = nil - var _mixins: [Google_Protobuf_Mixin] = [] - var _syntax: Google_Protobuf_Syntax = .proto2 - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _name = source._name - _methods = source._methods - _options = source._options - _version = source._version - _sourceContext = source._sourceContext - _mixins = source._mixins - _syntax = source._syntax - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &_storage._name) - case 2: try decoder.decodeRepeatedMessageField(value: &_storage._methods) - case 3: try decoder.decodeRepeatedMessageField(value: &_storage._options) - case 4: try decoder.decodeSingularStringField(value: &_storage._version) - case 5: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) - case 6: try decoder.decodeRepeatedMessageField(value: &_storage._mixins) - case 7: try decoder.decodeSingularEnumField(value: &_storage._syntax) - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - if !_storage._name.isEmpty { - try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) - } - if !_storage._methods.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._methods, fieldNumber: 2) - } - if !_storage._options.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 3) - } - if !_storage._version.isEmpty { - try visitor.visitSingularStringField(value: _storage._version, fieldNumber: 4) - } - if let v = _storage._sourceContext { - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - } - if !_storage._mixins.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._mixins, fieldNumber: 6) - } - if _storage._syntax != .proto2 { - try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 7) - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Api, rhs: Google_Protobuf_Api) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._name != rhs_storage._name {return false} - if _storage._methods != rhs_storage._methods {return false} - if _storage._options != rhs_storage._options {return false} - if _storage._version != rhs_storage._version {return false} - if _storage._sourceContext != rhs_storage._sourceContext {return false} - if _storage._mixins != rhs_storage._mixins {return false} - if _storage._syntax != rhs_storage._syntax {return false} - return true - } - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Method: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Method" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .standard(proto: "request_type_url"), - 3: .standard(proto: "request_streaming"), - 4: .standard(proto: "response_type_url"), - 5: .standard(proto: "response_streaming"), - 6: .same(proto: "options"), - 7: .same(proto: "syntax"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &self.name) - case 2: try decoder.decodeSingularStringField(value: &self.requestTypeURL) - case 3: try decoder.decodeSingularBoolField(value: &self.requestStreaming) - case 4: try decoder.decodeSingularStringField(value: &self.responseTypeURL) - case 5: try decoder.decodeSingularBoolField(value: &self.responseStreaming) - case 6: try decoder.decodeRepeatedMessageField(value: &self.options) - case 7: try decoder.decodeSingularEnumField(value: &self.syntax) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - if !self.requestTypeURL.isEmpty { - try visitor.visitSingularStringField(value: self.requestTypeURL, fieldNumber: 2) - } - if self.requestStreaming != false { - try visitor.visitSingularBoolField(value: self.requestStreaming, fieldNumber: 3) - } - if !self.responseTypeURL.isEmpty { - try visitor.visitSingularStringField(value: self.responseTypeURL, fieldNumber: 4) - } - if self.responseStreaming != false { - try visitor.visitSingularBoolField(value: self.responseStreaming, fieldNumber: 5) - } - if !self.options.isEmpty { - try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 6) - } - if self.syntax != .proto2 { - try visitor.visitSingularEnumField(value: self.syntax, fieldNumber: 7) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Method, rhs: Google_Protobuf_Method) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.requestTypeURL != rhs.requestTypeURL {return false} - if lhs.requestStreaming != rhs.requestStreaming {return false} - if lhs.responseTypeURL != rhs.responseTypeURL {return false} - if lhs.responseStreaming != rhs.responseStreaming {return false} - if lhs.options != rhs.options {return false} - if lhs.syntax != rhs.syntax {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Mixin: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Mixin" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "root"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &self.name) - case 2: try decoder.decodeSingularStringField(value: &self.root) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - if !self.root.isEmpty { - try visitor.visitSingularStringField(value: self.root, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Mixin, rhs: Google_Protobuf_Mixin) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.root != rhs.root {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift deleted file mode 100644 index 86db1a0..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/duration.pb.swift +++ /dev/null @@ -1,169 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/duration.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// A Duration represents a signed, fixed-length span of time represented -/// as a count of seconds and fractions of seconds at nanosecond -/// resolution. It is independent of any calendar and concepts like "day" -/// or "month". It is related to Timestamp in that the difference between -/// two Timestamp values is a Duration and it can be added or subtracted -/// from a Timestamp. Range is approximately +-10,000 years. -/// -/// # Examples -/// -/// Example 1: Compute Duration from two Timestamps in pseudo code. -/// -/// Timestamp start = ...; -/// Timestamp end = ...; -/// Duration duration = ...; -/// -/// duration.seconds = end.seconds - start.seconds; -/// duration.nanos = end.nanos - start.nanos; -/// -/// if (duration.seconds < 0 && duration.nanos > 0) { -/// duration.seconds += 1; -/// duration.nanos -= 1000000000; -/// } else if (durations.seconds > 0 && duration.nanos < 0) { -/// duration.seconds -= 1; -/// duration.nanos += 1000000000; -/// } -/// -/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. -/// -/// Timestamp start = ...; -/// Duration duration = ...; -/// Timestamp end = ...; -/// -/// end.seconds = start.seconds + duration.seconds; -/// end.nanos = start.nanos + duration.nanos; -/// -/// if (end.nanos < 0) { -/// end.seconds -= 1; -/// end.nanos += 1000000000; -/// } else if (end.nanos >= 1000000000) { -/// end.seconds += 1; -/// end.nanos -= 1000000000; -/// } -/// -/// Example 3: Compute Duration from datetime.timedelta in Python. -/// -/// td = datetime.timedelta(days=3, minutes=10) -/// duration = Duration() -/// duration.FromTimedelta(td) -/// -/// # JSON Mapping -/// -/// In JSON format, the Duration type is encoded as a string rather than an -/// object, where the string ends in the suffix "s" (indicating seconds) and -/// is preceded by the number of seconds, with nanoseconds expressed as -/// fractional seconds. For example, 3 seconds with 0 nanoseconds should be -/// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should -/// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 -/// microsecond should be expressed in JSON format as "3.000001s". -public struct Google_Protobuf_Duration { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Signed seconds of the span of time. Must be from -315,576,000,000 - /// to +315,576,000,000 inclusive. Note: these bounds are computed from: - /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years - public var seconds: Int64 = 0 - - /// Signed fractions of a second at nanosecond resolution of the span - /// of time. Durations less than one second are represented with a 0 - /// `seconds` field and a positive or negative `nanos` field. For durations - /// of one second or more, a non-zero value for the `nanos` field must be - /// of the same sign as the `seconds` field. Must be from -999,999,999 - /// to +999,999,999 inclusive. - public var nanos: Int32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Duration: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Duration" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "seconds"), - 2: .same(proto: "nanos"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularInt64Field(value: &self.seconds) - case 2: try decoder.decodeSingularInt32Field(value: &self.nanos) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.seconds != 0 { - try visitor.visitSingularInt64Field(value: self.seconds, fieldNumber: 1) - } - if self.nanos != 0 { - try visitor.visitSingularInt32Field(value: self.nanos, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Duration, rhs: Google_Protobuf_Duration) -> Bool { - if lhs.seconds != rhs.seconds {return false} - if lhs.nanos != rhs.nanos {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift deleted file mode 100644 index a951fc5..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/empty.pb.swift +++ /dev/null @@ -1,91 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/empty.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// A generic empty message that you can re-use to avoid defining duplicated -/// empty messages in your APIs. A typical example is to use it as the request -/// or the response type of an API method. For instance: -/// -/// service Foo { -/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); -/// } -/// -/// The JSON representation for `Empty` is empty JSON object `{}`. -public struct Google_Protobuf_Empty { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Empty: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Empty" - public static let _protobuf_nameMap = SwiftProtobuf._NameMap() - - public mutating func decodeMessage(decoder: inout D) throws { - while let _ = try decoder.nextFieldNumber() { - } - } - - public func traverse(visitor: inout V) throws { - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Empty, rhs: Google_Protobuf_Empty) -> Bool { - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift deleted file mode 100644 index bea1b11..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/field_mask.pb.swift +++ /dev/null @@ -1,294 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/field_mask.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// `FieldMask` represents a set of symbolic field paths, for example: -/// -/// paths: "f.a" -/// paths: "f.b.d" -/// -/// Here `f` represents a field in some root message, `a` and `b` -/// fields in the message found in `f`, and `d` a field found in the -/// message in `f.b`. -/// -/// Field masks are used to specify a subset of fields that should be -/// returned by a get operation or modified by an update operation. -/// Field masks also have a custom JSON encoding (see below). -/// -/// # Field Masks in Projections -/// -/// When used in the context of a projection, a response message or -/// sub-message is filtered by the API to only contain those fields as -/// specified in the mask. For example, if the mask in the previous -/// example is applied to a response message as follows: -/// -/// f { -/// a : 22 -/// b { -/// d : 1 -/// x : 2 -/// } -/// y : 13 -/// } -/// z: 8 -/// -/// The result will not contain specific values for fields x,y and z -/// (their value will be set to the default, and omitted in proto text -/// output): -/// -/// -/// f { -/// a : 22 -/// b { -/// d : 1 -/// } -/// } -/// -/// A repeated field is not allowed except at the last position of a -/// paths string. -/// -/// If a FieldMask object is not present in a get operation, the -/// operation applies to all fields (as if a FieldMask of all fields -/// had been specified). -/// -/// Note that a field mask does not necessarily apply to the -/// top-level response message. In case of a REST get operation, the -/// field mask applies directly to the response, but in case of a REST -/// list operation, the mask instead applies to each individual message -/// in the returned resource list. In case of a REST custom method, -/// other definitions may be used. Where the mask applies will be -/// clearly documented together with its declaration in the API. In -/// any case, the effect on the returned resource/resources is required -/// behavior for APIs. -/// -/// # Field Masks in Update Operations -/// -/// A field mask in update operations specifies which fields of the -/// targeted resource are going to be updated. The API is required -/// to only change the values of the fields as specified in the mask -/// and leave the others untouched. If a resource is passed in to -/// describe the updated values, the API ignores the values of all -/// fields not covered by the mask. -/// -/// If a repeated field is specified for an update operation, new values will -/// be appended to the existing repeated field in the target resource. Note that -/// a repeated field is only allowed in the last position of a `paths` string. -/// -/// If a sub-message is specified in the last position of the field mask for an -/// update operation, then new value will be merged into the existing sub-message -/// in the target resource. -/// -/// For example, given the target message: -/// -/// f { -/// b { -/// d: 1 -/// x: 2 -/// } -/// c: [1] -/// } -/// -/// And an update message: -/// -/// f { -/// b { -/// d: 10 -/// } -/// c: [2] -/// } -/// -/// then if the field mask is: -/// -/// paths: ["f.b", "f.c"] -/// -/// then the result will be: -/// -/// f { -/// b { -/// d: 10 -/// x: 2 -/// } -/// c: [1, 2] -/// } -/// -/// An implementation may provide options to override this default behavior for -/// repeated and message fields. -/// -/// In order to reset a field's value to the default, the field must -/// be in the mask and set to the default value in the provided resource. -/// Hence, in order to reset all fields of a resource, provide a default -/// instance of the resource and set all fields in the mask, or do -/// not provide a mask as described below. -/// -/// If a field mask is not present on update, the operation applies to -/// all fields (as if a field mask of all fields has been specified). -/// Note that in the presence of schema evolution, this may mean that -/// fields the client does not know and has therefore not filled into -/// the request will be reset to their default. If this is unwanted -/// behavior, a specific service may require a client to always specify -/// a field mask, producing an error if not. -/// -/// As with get operations, the location of the resource which -/// describes the updated values in the request message depends on the -/// operation kind. In any case, the effect of the field mask is -/// required to be honored by the API. -/// -/// ## Considerations for HTTP REST -/// -/// The HTTP kind of an update operation which uses a field mask must -/// be set to PATCH instead of PUT in order to satisfy HTTP semantics -/// (PUT must only be used for full updates). -/// -/// # JSON Encoding of Field Masks -/// -/// In JSON, a field mask is encoded as a single string where paths are -/// separated by a comma. Fields name in each path are converted -/// to/from lower-camel naming conventions. -/// -/// As an example, consider the following message declarations: -/// -/// message Profile { -/// User user = 1; -/// Photo photo = 2; -/// } -/// message User { -/// string display_name = 1; -/// string address = 2; -/// } -/// -/// In proto a field mask for `Profile` may look as such: -/// -/// mask { -/// paths: "user.display_name" -/// paths: "photo" -/// } -/// -/// In JSON, the same mask is represented as below: -/// -/// { -/// mask: "user.displayName,photo" -/// } -/// -/// # Field Masks and Oneof Fields -/// -/// Field masks treat fields in oneofs just as regular fields. Consider the -/// following message: -/// -/// message SampleMessage { -/// oneof test_oneof { -/// string name = 4; -/// SubMessage sub_message = 9; -/// } -/// } -/// -/// The field mask can be: -/// -/// mask { -/// paths: "name" -/// } -/// -/// Or: -/// -/// mask { -/// paths: "sub_message" -/// } -/// -/// Note that oneof type names ("test_oneof" in this case) cannot be used in -/// paths. -/// -/// ## Field Mask Verification -/// -/// The implementation of any API method which has a FieldMask type field in the -/// request should verify the included field paths, and return an -/// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. -public struct Google_Protobuf_FieldMask { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The set of field mask paths. - public var paths: [String] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_FieldMask: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".FieldMask" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "paths"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeRepeatedStringField(value: &self.paths) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.paths.isEmpty { - try visitor.visitRepeatedStringField(value: self.paths, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_FieldMask, rhs: Google_Protobuf_FieldMask) -> Bool { - if lhs.paths != rhs.paths {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift deleted file mode 100644 index b9c7627..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/source_context.pb.swift +++ /dev/null @@ -1,98 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/source_context.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// `SourceContext` represents information about the source of a -/// protobuf element, like the file in which it is defined. -public struct Google_Protobuf_SourceContext { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The path-qualified name of the .proto file that contained the associated - /// protobuf element. For example: `"google/protobuf/source_context.proto"`. - public var fileName: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_SourceContext: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".SourceContext" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "file_name"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &self.fileName) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.fileName.isEmpty { - try visitor.visitSingularStringField(value: self.fileName, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_SourceContext, rhs: Google_Protobuf_SourceContext) -> Bool { - if lhs.fileName != rhs.fileName {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift deleted file mode 100644 index eceb43c..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/struct.pb.swift +++ /dev/null @@ -1,417 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/struct.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// `NullValue` is a singleton enumeration to represent the null value for the -/// `Value` type union. -/// -/// The JSON representation for `NullValue` is JSON `null`. -public enum Google_Protobuf_NullValue: SwiftProtobuf.Enum { - public typealias RawValue = Int - - /// Null value. - case nullValue // = 0 - case UNRECOGNIZED(Int) - - public init() { - self = .nullValue - } - - public init?(rawValue: Int) { - switch rawValue { - case 0: self = .nullValue - default: self = .UNRECOGNIZED(rawValue) - } - } - - public var rawValue: Int { - switch self { - case .nullValue: return 0 - case .UNRECOGNIZED(let i): return i - } - } - -} - -#if swift(>=4.2) - -extension Google_Protobuf_NullValue: CaseIterable { - // The compiler won't synthesize support with the UNRECOGNIZED case. - public static var allCases: [Google_Protobuf_NullValue] = [ - .nullValue, - ] -} - -#endif // swift(>=4.2) - -/// `Struct` represents a structured data value, consisting of fields -/// which map to dynamically typed values. In some languages, `Struct` -/// might be supported by a native representation. For example, in -/// scripting languages like JS a struct is represented as an -/// object. The details of that representation are described together -/// with the proto support for the language. -/// -/// The JSON representation for `Struct` is JSON object. -public struct Google_Protobuf_Struct { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Unordered map of dynamically typed values. - public var fields: Dictionary = [:] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// `Value` represents a dynamically typed value which can be either -/// null, a number, a string, a boolean, a recursive struct value, or a -/// list of values. A producer of value is expected to set one of that -/// variants, absence of any variant indicates an error. -/// -/// The JSON representation for `Value` is JSON value. -public struct Google_Protobuf_Value { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The kind of value. - public var kind: OneOf_Kind? { - get {return _storage._kind} - set {_uniqueStorage()._kind = newValue} - } - - /// Represents a null value. - public var nullValue: Google_Protobuf_NullValue { - get { - if case .nullValue(let v)? = _storage._kind {return v} - return .nullValue - } - set {_uniqueStorage()._kind = .nullValue(newValue)} - } - - /// Represents a double value. - public var numberValue: Double { - get { - if case .numberValue(let v)? = _storage._kind {return v} - return 0 - } - set {_uniqueStorage()._kind = .numberValue(newValue)} - } - - /// Represents a string value. - public var stringValue: String { - get { - if case .stringValue(let v)? = _storage._kind {return v} - return String() - } - set {_uniqueStorage()._kind = .stringValue(newValue)} - } - - /// Represents a boolean value. - public var boolValue: Bool { - get { - if case .boolValue(let v)? = _storage._kind {return v} - return false - } - set {_uniqueStorage()._kind = .boolValue(newValue)} - } - - /// Represents a structured value. - public var structValue: Google_Protobuf_Struct { - get { - if case .structValue(let v)? = _storage._kind {return v} - return Google_Protobuf_Struct() - } - set {_uniqueStorage()._kind = .structValue(newValue)} - } - - /// Represents a repeated `Value`. - public var listValue: Google_Protobuf_ListValue { - get { - if case .listValue(let v)? = _storage._kind {return v} - return Google_Protobuf_ListValue() - } - set {_uniqueStorage()._kind = .listValue(newValue)} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// The kind of value. - public enum OneOf_Kind: Equatable { - /// Represents a null value. - case nullValue(Google_Protobuf_NullValue) - /// Represents a double value. - case numberValue(Double) - /// Represents a string value. - case stringValue(String) - /// Represents a boolean value. - case boolValue(Bool) - /// Represents a structured value. - case structValue(Google_Protobuf_Struct) - /// Represents a repeated `Value`. - case listValue(Google_Protobuf_ListValue) - - #if !swift(>=4.1) - public static func ==(lhs: Google_Protobuf_Value.OneOf_Kind, rhs: Google_Protobuf_Value.OneOf_Kind) -> Bool { - switch (lhs, rhs) { - case (.nullValue(let l), .nullValue(let r)): return l == r - case (.numberValue(let l), .numberValue(let r)): return l == r - case (.stringValue(let l), .stringValue(let r)): return l == r - case (.boolValue(let l), .boolValue(let r)): return l == r - case (.structValue(let l), .structValue(let r)): return l == r - case (.listValue(let l), .listValue(let r)): return l == r - default: return false - } - } - #endif - } - - public init() {} - - fileprivate var _storage = _StorageClass.defaultInstance -} - -/// `ListValue` is a wrapper around a repeated field of values. -/// -/// The JSON representation for `ListValue` is JSON array. -public struct Google_Protobuf_ListValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Repeated field of dynamically typed values. - public var values: [Google_Protobuf_Value] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_NullValue: SwiftProtobuf._ProtoNameProviding { - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "NULL_VALUE"), - ] -} - -extension Google_Protobuf_Struct: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Struct" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "fields"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: &self.fields) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.fields.isEmpty { - try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: self.fields, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Struct, rhs: Google_Protobuf_Struct) -> Bool { - if lhs.fields != rhs.fields {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Value" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .standard(proto: "null_value"), - 2: .standard(proto: "number_value"), - 3: .standard(proto: "string_value"), - 4: .standard(proto: "bool_value"), - 5: .standard(proto: "struct_value"), - 6: .standard(proto: "list_value"), - ] - - fileprivate class _StorageClass { - var _kind: Google_Protobuf_Value.OneOf_Kind? - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _kind = source._kind - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: - if _storage._kind != nil {try decoder.handleConflictingOneOf()} - var v: Google_Protobuf_NullValue? - try decoder.decodeSingularEnumField(value: &v) - if let v = v {_storage._kind = .nullValue(v)} - case 2: - if _storage._kind != nil {try decoder.handleConflictingOneOf()} - var v: Double? - try decoder.decodeSingularDoubleField(value: &v) - if let v = v {_storage._kind = .numberValue(v)} - case 3: - if _storage._kind != nil {try decoder.handleConflictingOneOf()} - var v: String? - try decoder.decodeSingularStringField(value: &v) - if let v = v {_storage._kind = .stringValue(v)} - case 4: - if _storage._kind != nil {try decoder.handleConflictingOneOf()} - var v: Bool? - try decoder.decodeSingularBoolField(value: &v) - if let v = v {_storage._kind = .boolValue(v)} - case 5: - var v: Google_Protobuf_Struct? - if let current = _storage._kind { - try decoder.handleConflictingOneOf() - if case .structValue(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v {_storage._kind = .structValue(v)} - case 6: - var v: Google_Protobuf_ListValue? - if let current = _storage._kind { - try decoder.handleConflictingOneOf() - if case .listValue(let m) = current {v = m} - } - try decoder.decodeSingularMessageField(value: &v) - if let v = v {_storage._kind = .listValue(v)} - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - switch _storage._kind { - case .nullValue(let v)?: - try visitor.visitSingularEnumField(value: v, fieldNumber: 1) - case .numberValue(let v)?: - try visitor.visitSingularDoubleField(value: v, fieldNumber: 2) - case .stringValue(let v)?: - try visitor.visitSingularStringField(value: v, fieldNumber: 3) - case .boolValue(let v)?: - try visitor.visitSingularBoolField(value: v, fieldNumber: 4) - case .structValue(let v)?: - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - case .listValue(let v)?: - try visitor.visitSingularMessageField(value: v, fieldNumber: 6) - case nil: break - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Value, rhs: Google_Protobuf_Value) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._kind != rhs_storage._kind {return false} - return true - } - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_ListValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".ListValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "values"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeRepeatedMessageField(value: &self.values) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.values.isEmpty { - try visitor.visitRepeatedMessageField(value: self.values, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_ListValue, rhs: Google_Protobuf_ListValue) -> Bool { - if lhs.values != rhs.values {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift deleted file mode 100644 index a9d40de..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/timestamp.pb.swift +++ /dev/null @@ -1,189 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/timestamp.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// A Timestamp represents a point in time independent of any time zone or local -/// calendar, encoded as a count of seconds and fractions of seconds at -/// nanosecond resolution. The count is relative to an epoch at UTC midnight on -/// January 1, 1970, in the proleptic Gregorian calendar which extends the -/// Gregorian calendar backwards to year one. -/// -/// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap -/// second table is needed for interpretation, using a [24-hour linear -/// smear](https://developers.google.com/time/smear). -/// -/// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By -/// restricting to that range, we ensure that we can convert to and from [RFC -/// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. -/// -/// # Examples -/// -/// Example 1: Compute Timestamp from POSIX `time()`. -/// -/// Timestamp timestamp; -/// timestamp.set_seconds(time(NULL)); -/// timestamp.set_nanos(0); -/// -/// Example 2: Compute Timestamp from POSIX `gettimeofday()`. -/// -/// struct timeval tv; -/// gettimeofday(&tv, NULL); -/// -/// Timestamp timestamp; -/// timestamp.set_seconds(tv.tv_sec); -/// timestamp.set_nanos(tv.tv_usec * 1000); -/// -/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. -/// -/// FILETIME ft; -/// GetSystemTimeAsFileTime(&ft); -/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; -/// -/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z -/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. -/// Timestamp timestamp; -/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); -/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); -/// -/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. -/// -/// long millis = System.currentTimeMillis(); -/// -/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) -/// .setNanos((int) ((millis % 1000) * 1000000)).build(); -/// -/// -/// Example 5: Compute Timestamp from current time in Python. -/// -/// timestamp = Timestamp() -/// timestamp.GetCurrentTime() -/// -/// # JSON Mapping -/// -/// In JSON format, the Timestamp type is encoded as a string in the -/// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the -/// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" -/// where {year} is always expressed using four digits while {month}, {day}, -/// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional -/// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), -/// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone -/// is required. A proto3 JSON serializer should always use UTC (as indicated by -/// "Z") when printing the Timestamp type and a proto3 JSON parser should be -/// able to accept both UTC and other timezones (as indicated by an offset). -/// -/// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past -/// 01:30 UTC on January 15, 2017. -/// -/// In JavaScript, one can convert a Date object to this format using the -/// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) -/// method. In Python, a standard `datetime.datetime` object can be converted -/// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) -/// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one -/// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( -/// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D -/// ) to obtain a formatter capable of generating timestamps in this format. -public struct Google_Protobuf_Timestamp { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Represents seconds of UTC time since Unix epoch - /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to - /// 9999-12-31T23:59:59Z inclusive. - public var seconds: Int64 = 0 - - /// Non-negative fractions of a second at nanosecond resolution. Negative - /// second values with fractions must still have non-negative nanos values - /// that count forward in time. Must be from 0 to 999,999,999 - /// inclusive. - public var nanos: Int32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Timestamp: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Timestamp" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "seconds"), - 2: .same(proto: "nanos"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularInt64Field(value: &self.seconds) - case 2: try decoder.decodeSingularInt32Field(value: &self.nanos) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.seconds != 0 { - try visitor.visitSingularInt64Field(value: self.seconds, fieldNumber: 1) - } - if self.nanos != 0 { - try visitor.visitSingularInt32Field(value: self.nanos, fieldNumber: 2) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Timestamp, rhs: Google_Protobuf_Timestamp) -> Bool { - if lhs.seconds != rhs.seconds {return false} - if lhs.nanos != rhs.nanos {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift deleted file mode 100644 index aedf640..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/type.pb.swift +++ /dev/null @@ -1,924 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/type.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// The syntax in which a protocol buffer element is defined. -public enum Google_Protobuf_Syntax: SwiftProtobuf.Enum { - public typealias RawValue = Int - - /// Syntax `proto2`. - case proto2 // = 0 - - /// Syntax `proto3`. - case proto3 // = 1 - case UNRECOGNIZED(Int) - - public init() { - self = .proto2 - } - - public init?(rawValue: Int) { - switch rawValue { - case 0: self = .proto2 - case 1: self = .proto3 - default: self = .UNRECOGNIZED(rawValue) - } - } - - public var rawValue: Int { - switch self { - case .proto2: return 0 - case .proto3: return 1 - case .UNRECOGNIZED(let i): return i - } - } - -} - -#if swift(>=4.2) - -extension Google_Protobuf_Syntax: CaseIterable { - // The compiler won't synthesize support with the UNRECOGNIZED case. - public static var allCases: [Google_Protobuf_Syntax] = [ - .proto2, - .proto3, - ] -} - -#endif // swift(>=4.2) - -/// A protocol buffer message type. -public struct Google_Protobuf_Type { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The fully qualified message name. - public var name: String { - get {return _storage._name} - set {_uniqueStorage()._name = newValue} - } - - /// The list of fields. - public var fields: [Google_Protobuf_Field] { - get {return _storage._fields} - set {_uniqueStorage()._fields = newValue} - } - - /// The list of types appearing in `oneof` definitions in this type. - public var oneofs: [String] { - get {return _storage._oneofs} - set {_uniqueStorage()._oneofs = newValue} - } - - /// The protocol buffer options. - public var options: [Google_Protobuf_Option] { - get {return _storage._options} - set {_uniqueStorage()._options = newValue} - } - - /// The source context. - public var sourceContext: Google_Protobuf_SourceContext { - get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} - set {_uniqueStorage()._sourceContext = newValue} - } - /// Returns true if `sourceContext` has been explicitly set. - public var hasSourceContext: Bool {return _storage._sourceContext != nil} - /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. - public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} - - /// The source syntax. - public var syntax: Google_Protobuf_Syntax { - get {return _storage._syntax} - set {_uniqueStorage()._syntax = newValue} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _storage = _StorageClass.defaultInstance -} - -/// A single field of a message type. -public struct Google_Protobuf_Field { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The field type. - public var kind: Google_Protobuf_Field.Kind = .typeUnknown - - /// The field cardinality. - public var cardinality: Google_Protobuf_Field.Cardinality = .unknown - - /// The field number. - public var number: Int32 = 0 - - /// The field name. - public var name: String = String() - - /// The field type URL, without the scheme, for message or enumeration - /// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. - public var typeURL: String = String() - - /// The index of the field type in `Type.oneofs`, for message or enumeration - /// types. The first type has index 1; zero means the type is not in the list. - public var oneofIndex: Int32 = 0 - - /// Whether to use alternative packed wire representation. - public var packed: Bool = false - - /// The protocol buffer options. - public var options: [Google_Protobuf_Option] = [] - - /// The field JSON name. - public var jsonName: String = String() - - /// The string value of the default value of this field. Proto2 syntax only. - public var defaultValue: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - /// Basic field types. - public enum Kind: SwiftProtobuf.Enum { - public typealias RawValue = Int - - /// Field type unknown. - case typeUnknown // = 0 - - /// Field type double. - case typeDouble // = 1 - - /// Field type float. - case typeFloat // = 2 - - /// Field type int64. - case typeInt64 // = 3 - - /// Field type uint64. - case typeUint64 // = 4 - - /// Field type int32. - case typeInt32 // = 5 - - /// Field type fixed64. - case typeFixed64 // = 6 - - /// Field type fixed32. - case typeFixed32 // = 7 - - /// Field type bool. - case typeBool // = 8 - - /// Field type string. - case typeString // = 9 - - /// Field type group. Proto2 syntax only, and deprecated. - case typeGroup // = 10 - - /// Field type message. - case typeMessage // = 11 - - /// Field type bytes. - case typeBytes // = 12 - - /// Field type uint32. - case typeUint32 // = 13 - - /// Field type enum. - case typeEnum // = 14 - - /// Field type sfixed32. - case typeSfixed32 // = 15 - - /// Field type sfixed64. - case typeSfixed64 // = 16 - - /// Field type sint32. - case typeSint32 // = 17 - - /// Field type sint64. - case typeSint64 // = 18 - case UNRECOGNIZED(Int) - - public init() { - self = .typeUnknown - } - - public init?(rawValue: Int) { - switch rawValue { - case 0: self = .typeUnknown - case 1: self = .typeDouble - case 2: self = .typeFloat - case 3: self = .typeInt64 - case 4: self = .typeUint64 - case 5: self = .typeInt32 - case 6: self = .typeFixed64 - case 7: self = .typeFixed32 - case 8: self = .typeBool - case 9: self = .typeString - case 10: self = .typeGroup - case 11: self = .typeMessage - case 12: self = .typeBytes - case 13: self = .typeUint32 - case 14: self = .typeEnum - case 15: self = .typeSfixed32 - case 16: self = .typeSfixed64 - case 17: self = .typeSint32 - case 18: self = .typeSint64 - default: self = .UNRECOGNIZED(rawValue) - } - } - - public var rawValue: Int { - switch self { - case .typeUnknown: return 0 - case .typeDouble: return 1 - case .typeFloat: return 2 - case .typeInt64: return 3 - case .typeUint64: return 4 - case .typeInt32: return 5 - case .typeFixed64: return 6 - case .typeFixed32: return 7 - case .typeBool: return 8 - case .typeString: return 9 - case .typeGroup: return 10 - case .typeMessage: return 11 - case .typeBytes: return 12 - case .typeUint32: return 13 - case .typeEnum: return 14 - case .typeSfixed32: return 15 - case .typeSfixed64: return 16 - case .typeSint32: return 17 - case .typeSint64: return 18 - case .UNRECOGNIZED(let i): return i - } - } - - } - - /// Whether a field is optional, required, or repeated. - public enum Cardinality: SwiftProtobuf.Enum { - public typealias RawValue = Int - - /// For fields with unknown cardinality. - case unknown // = 0 - - /// For optional fields. - case `optional` // = 1 - - /// For required fields. Proto2 syntax only. - case `required` // = 2 - - /// For repeated fields. - case repeated // = 3 - case UNRECOGNIZED(Int) - - public init() { - self = .unknown - } - - public init?(rawValue: Int) { - switch rawValue { - case 0: self = .unknown - case 1: self = .optional - case 2: self = .required - case 3: self = .repeated - default: self = .UNRECOGNIZED(rawValue) - } - } - - public var rawValue: Int { - switch self { - case .unknown: return 0 - case .optional: return 1 - case .required: return 2 - case .repeated: return 3 - case .UNRECOGNIZED(let i): return i - } - } - - } - - public init() {} -} - -#if swift(>=4.2) - -extension Google_Protobuf_Field.Kind: CaseIterable { - // The compiler won't synthesize support with the UNRECOGNIZED case. - public static var allCases: [Google_Protobuf_Field.Kind] = [ - .typeUnknown, - .typeDouble, - .typeFloat, - .typeInt64, - .typeUint64, - .typeInt32, - .typeFixed64, - .typeFixed32, - .typeBool, - .typeString, - .typeGroup, - .typeMessage, - .typeBytes, - .typeUint32, - .typeEnum, - .typeSfixed32, - .typeSfixed64, - .typeSint32, - .typeSint64, - ] -} - -extension Google_Protobuf_Field.Cardinality: CaseIterable { - // The compiler won't synthesize support with the UNRECOGNIZED case. - public static var allCases: [Google_Protobuf_Field.Cardinality] = [ - .unknown, - .optional, - .required, - .repeated, - ] -} - -#endif // swift(>=4.2) - -/// Enum type definition. -public struct Google_Protobuf_Enum { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Enum type name. - public var name: String { - get {return _storage._name} - set {_uniqueStorage()._name = newValue} - } - - /// Enum value definitions. - public var enumvalue: [Google_Protobuf_EnumValue] { - get {return _storage._enumvalue} - set {_uniqueStorage()._enumvalue = newValue} - } - - /// Protocol buffer options. - public var options: [Google_Protobuf_Option] { - get {return _storage._options} - set {_uniqueStorage()._options = newValue} - } - - /// The source context. - public var sourceContext: Google_Protobuf_SourceContext { - get {return _storage._sourceContext ?? Google_Protobuf_SourceContext()} - set {_uniqueStorage()._sourceContext = newValue} - } - /// Returns true if `sourceContext` has been explicitly set. - public var hasSourceContext: Bool {return _storage._sourceContext != nil} - /// Clears the value of `sourceContext`. Subsequent reads from it will return its default value. - public mutating func clearSourceContext() {_uniqueStorage()._sourceContext = nil} - - /// The source syntax. - public var syntax: Google_Protobuf_Syntax { - get {return _storage._syntax} - set {_uniqueStorage()._syntax = newValue} - } - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _storage = _StorageClass.defaultInstance -} - -/// Enum value definition. -public struct Google_Protobuf_EnumValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// Enum value name. - public var name: String = String() - - /// Enum value number. - public var number: Int32 = 0 - - /// Protocol buffer options. - public var options: [Google_Protobuf_Option] = [] - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// A protocol buffer option, which can be attached to a message, field, -/// enumeration, etc. -public struct Google_Protobuf_Option { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The option's name. For protobuf built-in options (options defined in - /// descriptor.proto), this is the short name. For example, `"map_entry"`. - /// For custom options, it should be the fully-qualified name. For example, - /// `"google.api.http"`. - public var name: String { - get {return _storage._name} - set {_uniqueStorage()._name = newValue} - } - - /// The option's value packed in an Any message. If the value is a primitive, - /// the corresponding wrapper type defined in google/protobuf/wrappers.proto - /// should be used. If the value is an enum, it should be stored as an int32 - /// value using the google.protobuf.Int32Value type. - public var value: Google_Protobuf_Any { - get {return _storage._value ?? Google_Protobuf_Any()} - set {_uniqueStorage()._value = newValue} - } - /// Returns true if `value` has been explicitly set. - public var hasValue: Bool {return _storage._value != nil} - /// Clears the value of `value`. Subsequent reads from it will return its default value. - public mutating func clearValue() {_uniqueStorage()._value = nil} - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} - - fileprivate var _storage = _StorageClass.defaultInstance -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_Syntax: SwiftProtobuf._ProtoNameProviding { - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "SYNTAX_PROTO2"), - 1: .same(proto: "SYNTAX_PROTO3"), - ] -} - -extension Google_Protobuf_Type: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Type" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "fields"), - 3: .same(proto: "oneofs"), - 4: .same(proto: "options"), - 5: .standard(proto: "source_context"), - 6: .same(proto: "syntax"), - ] - - fileprivate class _StorageClass { - var _name: String = String() - var _fields: [Google_Protobuf_Field] = [] - var _oneofs: [String] = [] - var _options: [Google_Protobuf_Option] = [] - var _sourceContext: Google_Protobuf_SourceContext? = nil - var _syntax: Google_Protobuf_Syntax = .proto2 - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _name = source._name - _fields = source._fields - _oneofs = source._oneofs - _options = source._options - _sourceContext = source._sourceContext - _syntax = source._syntax - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &_storage._name) - case 2: try decoder.decodeRepeatedMessageField(value: &_storage._fields) - case 3: try decoder.decodeRepeatedStringField(value: &_storage._oneofs) - case 4: try decoder.decodeRepeatedMessageField(value: &_storage._options) - case 5: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) - case 6: try decoder.decodeSingularEnumField(value: &_storage._syntax) - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - if !_storage._name.isEmpty { - try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) - } - if !_storage._fields.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._fields, fieldNumber: 2) - } - if !_storage._oneofs.isEmpty { - try visitor.visitRepeatedStringField(value: _storage._oneofs, fieldNumber: 3) - } - if !_storage._options.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 4) - } - if let v = _storage._sourceContext { - try visitor.visitSingularMessageField(value: v, fieldNumber: 5) - } - if _storage._syntax != .proto2 { - try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 6) - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Type, rhs: Google_Protobuf_Type) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._name != rhs_storage._name {return false} - if _storage._fields != rhs_storage._fields {return false} - if _storage._oneofs != rhs_storage._oneofs {return false} - if _storage._options != rhs_storage._options {return false} - if _storage._sourceContext != rhs_storage._sourceContext {return false} - if _storage._syntax != rhs_storage._syntax {return false} - return true - } - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Field: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Field" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "kind"), - 2: .same(proto: "cardinality"), - 3: .same(proto: "number"), - 4: .same(proto: "name"), - 6: .standard(proto: "type_url"), - 7: .standard(proto: "oneof_index"), - 8: .same(proto: "packed"), - 9: .same(proto: "options"), - 10: .standard(proto: "json_name"), - 11: .standard(proto: "default_value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularEnumField(value: &self.kind) - case 2: try decoder.decodeSingularEnumField(value: &self.cardinality) - case 3: try decoder.decodeSingularInt32Field(value: &self.number) - case 4: try decoder.decodeSingularStringField(value: &self.name) - case 6: try decoder.decodeSingularStringField(value: &self.typeURL) - case 7: try decoder.decodeSingularInt32Field(value: &self.oneofIndex) - case 8: try decoder.decodeSingularBoolField(value: &self.packed) - case 9: try decoder.decodeRepeatedMessageField(value: &self.options) - case 10: try decoder.decodeSingularStringField(value: &self.jsonName) - case 11: try decoder.decodeSingularStringField(value: &self.defaultValue) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.kind != .typeUnknown { - try visitor.visitSingularEnumField(value: self.kind, fieldNumber: 1) - } - if self.cardinality != .unknown { - try visitor.visitSingularEnumField(value: self.cardinality, fieldNumber: 2) - } - if self.number != 0 { - try visitor.visitSingularInt32Field(value: self.number, fieldNumber: 3) - } - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 4) - } - if !self.typeURL.isEmpty { - try visitor.visitSingularStringField(value: self.typeURL, fieldNumber: 6) - } - if self.oneofIndex != 0 { - try visitor.visitSingularInt32Field(value: self.oneofIndex, fieldNumber: 7) - } - if self.packed != false { - try visitor.visitSingularBoolField(value: self.packed, fieldNumber: 8) - } - if !self.options.isEmpty { - try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 9) - } - if !self.jsonName.isEmpty { - try visitor.visitSingularStringField(value: self.jsonName, fieldNumber: 10) - } - if !self.defaultValue.isEmpty { - try visitor.visitSingularStringField(value: self.defaultValue, fieldNumber: 11) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Field, rhs: Google_Protobuf_Field) -> Bool { - if lhs.kind != rhs.kind {return false} - if lhs.cardinality != rhs.cardinality {return false} - if lhs.number != rhs.number {return false} - if lhs.name != rhs.name {return false} - if lhs.typeURL != rhs.typeURL {return false} - if lhs.oneofIndex != rhs.oneofIndex {return false} - if lhs.packed != rhs.packed {return false} - if lhs.options != rhs.options {return false} - if lhs.jsonName != rhs.jsonName {return false} - if lhs.defaultValue != rhs.defaultValue {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Field.Kind: SwiftProtobuf._ProtoNameProviding { - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "TYPE_UNKNOWN"), - 1: .same(proto: "TYPE_DOUBLE"), - 2: .same(proto: "TYPE_FLOAT"), - 3: .same(proto: "TYPE_INT64"), - 4: .same(proto: "TYPE_UINT64"), - 5: .same(proto: "TYPE_INT32"), - 6: .same(proto: "TYPE_FIXED64"), - 7: .same(proto: "TYPE_FIXED32"), - 8: .same(proto: "TYPE_BOOL"), - 9: .same(proto: "TYPE_STRING"), - 10: .same(proto: "TYPE_GROUP"), - 11: .same(proto: "TYPE_MESSAGE"), - 12: .same(proto: "TYPE_BYTES"), - 13: .same(proto: "TYPE_UINT32"), - 14: .same(proto: "TYPE_ENUM"), - 15: .same(proto: "TYPE_SFIXED32"), - 16: .same(proto: "TYPE_SFIXED64"), - 17: .same(proto: "TYPE_SINT32"), - 18: .same(proto: "TYPE_SINT64"), - ] -} - -extension Google_Protobuf_Field.Cardinality: SwiftProtobuf._ProtoNameProviding { - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 0: .same(proto: "CARDINALITY_UNKNOWN"), - 1: .same(proto: "CARDINALITY_OPTIONAL"), - 2: .same(proto: "CARDINALITY_REQUIRED"), - 3: .same(proto: "CARDINALITY_REPEATED"), - ] -} - -extension Google_Protobuf_Enum: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Enum" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "enumvalue"), - 3: .same(proto: "options"), - 4: .standard(proto: "source_context"), - 5: .same(proto: "syntax"), - ] - - fileprivate class _StorageClass { - var _name: String = String() - var _enumvalue: [Google_Protobuf_EnumValue] = [] - var _options: [Google_Protobuf_Option] = [] - var _sourceContext: Google_Protobuf_SourceContext? = nil - var _syntax: Google_Protobuf_Syntax = .proto2 - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _name = source._name - _enumvalue = source._enumvalue - _options = source._options - _sourceContext = source._sourceContext - _syntax = source._syntax - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &_storage._name) - case 2: try decoder.decodeRepeatedMessageField(value: &_storage._enumvalue) - case 3: try decoder.decodeRepeatedMessageField(value: &_storage._options) - case 4: try decoder.decodeSingularMessageField(value: &_storage._sourceContext) - case 5: try decoder.decodeSingularEnumField(value: &_storage._syntax) - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - if !_storage._name.isEmpty { - try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) - } - if !_storage._enumvalue.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._enumvalue, fieldNumber: 2) - } - if !_storage._options.isEmpty { - try visitor.visitRepeatedMessageField(value: _storage._options, fieldNumber: 3) - } - if let v = _storage._sourceContext { - try visitor.visitSingularMessageField(value: v, fieldNumber: 4) - } - if _storage._syntax != .proto2 { - try visitor.visitSingularEnumField(value: _storage._syntax, fieldNumber: 5) - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Enum, rhs: Google_Protobuf_Enum) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._name != rhs_storage._name {return false} - if _storage._enumvalue != rhs_storage._enumvalue {return false} - if _storage._options != rhs_storage._options {return false} - if _storage._sourceContext != rhs_storage._sourceContext {return false} - if _storage._syntax != rhs_storage._syntax {return false} - return true - } - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_EnumValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".EnumValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "number"), - 3: .same(proto: "options"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &self.name) - case 2: try decoder.decodeSingularInt32Field(value: &self.number) - case 3: try decoder.decodeRepeatedMessageField(value: &self.options) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.name.isEmpty { - try visitor.visitSingularStringField(value: self.name, fieldNumber: 1) - } - if self.number != 0 { - try visitor.visitSingularInt32Field(value: self.number, fieldNumber: 2) - } - if !self.options.isEmpty { - try visitor.visitRepeatedMessageField(value: self.options, fieldNumber: 3) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_EnumValue, rhs: Google_Protobuf_EnumValue) -> Bool { - if lhs.name != rhs.name {return false} - if lhs.number != rhs.number {return false} - if lhs.options != rhs.options {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Option: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Option" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "name"), - 2: .same(proto: "value"), - ] - - fileprivate class _StorageClass { - var _name: String = String() - var _value: Google_Protobuf_Any? = nil - - static let defaultInstance = _StorageClass() - - private init() {} - - init(copying source: _StorageClass) { - _name = source._name - _value = source._value - } - } - - fileprivate mutating func _uniqueStorage() -> _StorageClass { - if !isKnownUniquelyReferenced(&_storage) { - _storage = _StorageClass(copying: _storage) - } - return _storage - } - - public mutating func decodeMessage(decoder: inout D) throws { - _ = _uniqueStorage() - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &_storage._name) - case 2: try decoder.decodeSingularMessageField(value: &_storage._value) - default: break - } - } - } - } - - public func traverse(visitor: inout V) throws { - try withExtendedLifetime(_storage) { (_storage: _StorageClass) in - if !_storage._name.isEmpty { - try visitor.visitSingularStringField(value: _storage._name, fieldNumber: 1) - } - if let v = _storage._value { - try visitor.visitSingularMessageField(value: v, fieldNumber: 2) - } - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Option, rhs: Google_Protobuf_Option) -> Bool { - if lhs._storage !== rhs._storage { - let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in - let _storage = _args.0 - let rhs_storage = _args.1 - if _storage._name != rhs_storage._name {return false} - if _storage._value != rhs_storage._value {return false} - return true - } - if !storagesAreEqual {return false} - } - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift b/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift deleted file mode 100644 index 58f4bf9..0000000 --- a/Pods/SwiftProtobuf/Sources/SwiftProtobuf/wrappers.pb.swift +++ /dev/null @@ -1,468 +0,0 @@ -// DO NOT EDIT. -// -// Generated by the Swift generator plugin for the protocol buffer compiler. -// Source: google/protobuf/wrappers.proto -// -// For information on using the generated types, please see the documenation: -// https://github.com/apple/swift-protobuf/ - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Wrappers for primitive (non-message) types. These types are useful -// for embedding primitives in the `google.protobuf.Any` type and for places -// where we need to distinguish between the absence of a primitive -// typed field and its default value. -// -// These wrappers have no meaningful use within repeated fields as they lack -// the ability to detect presence on individual elements. -// These wrappers have no meaningful use within a map or a oneof since -// individual entries of a map or fields of a oneof can already detect presence. - -import Foundation - -// If the compiler emits an error on this type, it is because this file -// was generated by a version of the `protoc` Swift plug-in that is -// incompatible with the version of SwiftProtobuf to which you are linking. -// Please ensure that your are building against the same version of the API -// that was used to generate this file. -fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { - struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} - typealias Version = _2 -} - -/// Wrapper message for `double`. -/// -/// The JSON representation for `DoubleValue` is JSON number. -public struct Google_Protobuf_DoubleValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The double value. - public var value: Double = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `float`. -/// -/// The JSON representation for `FloatValue` is JSON number. -public struct Google_Protobuf_FloatValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The float value. - public var value: Float = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `int64`. -/// -/// The JSON representation for `Int64Value` is JSON string. -public struct Google_Protobuf_Int64Value { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The int64 value. - public var value: Int64 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `uint64`. -/// -/// The JSON representation for `UInt64Value` is JSON string. -public struct Google_Protobuf_UInt64Value { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The uint64 value. - public var value: UInt64 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `int32`. -/// -/// The JSON representation for `Int32Value` is JSON number. -public struct Google_Protobuf_Int32Value { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The int32 value. - public var value: Int32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `uint32`. -/// -/// The JSON representation for `UInt32Value` is JSON number. -public struct Google_Protobuf_UInt32Value { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The uint32 value. - public var value: UInt32 = 0 - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `bool`. -/// -/// The JSON representation for `BoolValue` is JSON `true` and `false`. -public struct Google_Protobuf_BoolValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The bool value. - public var value: Bool = false - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `string`. -/// -/// The JSON representation for `StringValue` is JSON string. -public struct Google_Protobuf_StringValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The string value. - public var value: String = String() - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -/// Wrapper message for `bytes`. -/// -/// The JSON representation for `BytesValue` is JSON string. -public struct Google_Protobuf_BytesValue { - // SwiftProtobuf.Message conformance is added in an extension below. See the - // `Message` and `Message+*Additions` files in the SwiftProtobuf library for - // methods supported on all messages. - - /// The bytes value. - public var value: Data = SwiftProtobuf.Internal.emptyData - - public var unknownFields = SwiftProtobuf.UnknownStorage() - - public init() {} -} - -// MARK: - Code below here is support for the SwiftProtobuf runtime. - -fileprivate let _protobuf_package = "google.protobuf" - -extension Google_Protobuf_DoubleValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".DoubleValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularDoubleField(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularDoubleField(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_DoubleValue, rhs: Google_Protobuf_DoubleValue) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_FloatValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".FloatValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularFloatField(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularFloatField(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_FloatValue, rhs: Google_Protobuf_FloatValue) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Int64Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Int64Value" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularInt64Field(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularInt64Field(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Int64Value, rhs: Google_Protobuf_Int64Value) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_UInt64Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".UInt64Value" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularUInt64Field(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularUInt64Field(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_UInt64Value, rhs: Google_Protobuf_UInt64Value) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_Int32Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".Int32Value" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularInt32Field(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularInt32Field(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_Int32Value, rhs: Google_Protobuf_Int32Value) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_UInt32Value: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".UInt32Value" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularUInt32Field(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != 0 { - try visitor.visitSingularUInt32Field(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_UInt32Value, rhs: Google_Protobuf_UInt32Value) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_BoolValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".BoolValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularBoolField(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if self.value != false { - try visitor.visitSingularBoolField(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_BoolValue, rhs: Google_Protobuf_BoolValue) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_StringValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".StringValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularStringField(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.value.isEmpty { - try visitor.visitSingularStringField(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_StringValue, rhs: Google_Protobuf_StringValue) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} - -extension Google_Protobuf_BytesValue: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { - public static let protoMessageName: String = _protobuf_package + ".BytesValue" - public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ - 1: .same(proto: "value"), - ] - - public mutating func decodeMessage(decoder: inout D) throws { - while let fieldNumber = try decoder.nextFieldNumber() { - switch fieldNumber { - case 1: try decoder.decodeSingularBytesField(value: &self.value) - default: break - } - } - } - - public func traverse(visitor: inout V) throws { - if !self.value.isEmpty { - try visitor.visitSingularBytesField(value: self.value, fieldNumber: 1) - } - try unknownFields.traverse(visitor: &visitor) - } - - public static func ==(lhs: Google_Protobuf_BytesValue, rhs: Google_Protobuf_BytesValue) -> Bool { - if lhs.value != rhs.value {return false} - if lhs.unknownFields != rhs.unknownFields {return false} - return true - } -} diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist b/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist deleted file mode 100644 index 2243fe6..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB-Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - ${PRODUCT_BUNDLE_IDENTIFIER} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0.0 - CFBundleSignature - ???? - CFBundleVersion - ${CURRENT_PROJECT_VERSION} - NSPrincipalClass - - - diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown deleted file mode 100644 index c14e6c3..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.markdown +++ /dev/null @@ -1,218 +0,0 @@ -# Acknowledgements -This application makes use of the following third party libraries: - -## SwiftProtobuf - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -## Runtime Library Exception to the Apache 2.0 License: ## - - - As an exception, if you use this Software to compile your source code and - portions of this Software are embedded into the binary product as a result, - you may redistribute such product without providing attribution as would - otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. - -Generated by CocoaPods - https://cocoapods.org diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist b/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist deleted file mode 100644 index 7b9559f..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB-acknowledgements.plist +++ /dev/null @@ -1,250 +0,0 @@ - - - - - PreferenceSpecifiers - - - FooterText - This application makes use of the following third party libraries: - Title - Acknowledgements - Type - PSGroupSpecifier - - - FooterText - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -## Runtime Library Exception to the Apache 2.0 License: ## - - - As an exception, if you use this Software to compile your source code and - portions of this Software are embedded into the binary product as a result, - you may redistribute such product without providing attribution as would - otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. - - License - Apache 2.0 - Title - SwiftProtobuf - Type - PSGroupSpecifier - - - FooterText - Generated by CocoaPods - https://cocoapods.org - Title - - Type - PSGroupSpecifier - - - StringsTable - Acknowledgements - Title - Acknowledgements - - diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m b/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m deleted file mode 100644 index 9775501..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB-dummy.m +++ /dev/null @@ -1,5 +0,0 @@ -#import -@interface PodsDummy_Pods_UB : NSObject -@end -@implementation PodsDummy_Pods_UB -@end diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h b/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h deleted file mode 100644 index 5672be2..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB-umbrella.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __OBJC__ -#import -#else -#ifndef FOUNDATION_EXPORT -#if defined(__cplusplus) -#define FOUNDATION_EXPORT extern "C" -#else -#define FOUNDATION_EXPORT extern -#endif -#endif -#endif - - -FOUNDATION_EXPORT double Pods_UBVersionNumber; -FOUNDATION_EXPORT const unsigned char Pods_UBVersionString[]; - diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig b/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig deleted file mode 100644 index cafce36..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB.debug.xcconfig +++ /dev/null @@ -1,10 +0,0 @@ -FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" -GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 -HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" -LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' -OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" -OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -PODS_BUILD_DIR = ${BUILD_DIR} -PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) -PODS_PODFILE_DIR_PATH = ${SRCROOT}/. -PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap b/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap deleted file mode 100644 index 9447309..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -framework module Pods_UB { - umbrella header "Pods-UB-umbrella.h" - - export * - module * { export * } -} diff --git a/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig b/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig deleted file mode 100644 index cafce36..0000000 --- a/Pods/Target Support Files/Pods-UB/Pods-UB.release.xcconfig +++ /dev/null @@ -1,10 +0,0 @@ -FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" -GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 -HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" -LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' -OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" -OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -PODS_BUILD_DIR = ${BUILD_DIR} -PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) -PODS_PODFILE_DIR_PATH = ${SRCROOT}/. -PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist deleted file mode 100644 index 2243fe6..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - ${PRODUCT_BUNDLE_IDENTIFIER} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0.0 - CFBundleSignature - ???? - CFBundleVersion - ${CURRENT_PROJECT_VERSION} - NSPrincipalClass - - - diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown deleted file mode 100644 index c14e6c3..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.markdown +++ /dev/null @@ -1,218 +0,0 @@ -# Acknowledgements -This application makes use of the following third party libraries: - -## SwiftProtobuf - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -## Runtime Library Exception to the Apache 2.0 License: ## - - - As an exception, if you use this Software to compile your source code and - portions of this Software are embedded into the binary product as a result, - you may redistribute such product without providing attribution as would - otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. - -Generated by CocoaPods - https://cocoapods.org diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist deleted file mode 100644 index 7b9559f..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-acknowledgements.plist +++ /dev/null @@ -1,250 +0,0 @@ - - - - - PreferenceSpecifiers - - - FooterText - This application makes use of the following third party libraries: - Title - Acknowledgements - Type - PSGroupSpecifier - - - FooterText - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - -## Runtime Library Exception to the Apache 2.0 License: ## - - - As an exception, if you use this Software to compile your source code and - portions of this Software are embedded into the binary product as a result, - you may redistribute such product without providing attribution as would - otherwise be required by Sections 4(a), 4(b) and 4(d) of the License. - - License - Apache 2.0 - Title - SwiftProtobuf - Type - PSGroupSpecifier - - - FooterText - Generated by CocoaPods - https://cocoapods.org - Title - - Type - PSGroupSpecifier - - - StringsTable - Acknowledgements - Title - Acknowledgements - - diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m deleted file mode 100644 index f7d2f4a..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-dummy.m +++ /dev/null @@ -1,5 +0,0 @@ -#import -@interface PodsDummy_Pods_UBTests : NSObject -@end -@implementation PodsDummy_Pods_UBTests -@end diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh deleted file mode 100755 index b035e1c..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-frameworks.sh +++ /dev/null @@ -1,171 +0,0 @@ -#!/bin/sh -set -e -set -u -set -o pipefail - -function on_error { - echo "$(realpath -mq "${0}"):$1: error: Unexpected failure" -} -trap 'on_error $LINENO' ERR - -if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then - # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy - # frameworks to, so exit 0 (signalling the script phase was successful). - exit 0 -fi - -echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" -mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" - -COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}" -SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" - -# Used as a return value for each invocation of `strip_invalid_archs` function. -STRIP_BINARY_RETVAL=0 - -# This protects against multiple targets copying the same framework dependency at the same time. The solution -# was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html -RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") - -# Copies and strips a vendored framework -install_framework() -{ - if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then - local source="${BUILT_PRODUCTS_DIR}/$1" - elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then - local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" - elif [ -r "$1" ]; then - local source="$1" - fi - - local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" - - if [ -L "${source}" ]; then - echo "Symlinked..." - source="$(readlink "${source}")" - fi - - # Use filter instead of exclude so missing patterns don't throw errors. - echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" - rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" - - local basename - basename="$(basename -s .framework "$1")" - binary="${destination}/${basename}.framework/${basename}" - - if ! [ -r "$binary" ]; then - binary="${destination}/${basename}" - elif [ -L "${binary}" ]; then - echo "Destination binary is symlinked..." - dirname="$(dirname "${binary}")" - binary="${dirname}/$(readlink "${binary}")" - fi - - # Strip invalid architectures so "fat" simulator / device frameworks work on device - if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then - strip_invalid_archs "$binary" - fi - - # Resign the code if required by the build settings to avoid unstable apps - code_sign_if_enabled "${destination}/$(basename "$1")" - - # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. - if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then - local swift_runtime_libs - swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u) - for lib in $swift_runtime_libs; do - echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" - rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" - code_sign_if_enabled "${destination}/${lib}" - done - fi -} - -# Copies and strips a vendored dSYM -install_dsym() { - local source="$1" - if [ -r "$source" ]; then - # Copy the dSYM into a the targets temp dir. - echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" - rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" - - local basename - basename="$(basename -s .framework.dSYM "$source")" - binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}" - - # Strip invalid architectures so "fat" simulator / device frameworks work on device - if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then - strip_invalid_archs "$binary" - fi - - if [[ $STRIP_BINARY_RETVAL == 1 ]]; then - # Move the stripped file into its final destination. - echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" - rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}" - else - # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. - touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM" - fi - fi -} - -# Copies the bcsymbolmap files of a vendored framework -install_bcsymbolmap() { - local bcsymbolmap_path="$1" - local destination="${BUILT_PRODUCTS_DIR}" - echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"" - rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}" -} - -# Signs a framework with the provided identity -code_sign_if_enabled() { - if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then - # Use the current code_sign_identity - echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" - local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'" - - if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then - code_sign_cmd="$code_sign_cmd &" - fi - echo "$code_sign_cmd" - eval "$code_sign_cmd" - fi -} - -# Strip invalid architectures -strip_invalid_archs() { - binary="$1" - # Get architectures for current target binary - binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" - # Intersect them with the architectures we are building for - intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" - # If there are no archs supported by this binary then warn the user - if [[ -z "$intersected_archs" ]]; then - echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." - STRIP_BINARY_RETVAL=0 - return - fi - stripped="" - for arch in $binary_archs; do - if ! [[ "${ARCHS}" == *"$arch"* ]]; then - # Strip non-valid architectures in-place - lipo -remove "$arch" -output "$binary" "$binary" - stripped="$stripped $arch" - fi - done - if [[ "$stripped" ]]; then - echo "Stripped $binary of architectures:$stripped" - fi - STRIP_BINARY_RETVAL=1 -} - - -if [[ "$CONFIGURATION" == "Debug" ]]; then - install_framework "${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework" -fi -if [[ "$CONFIGURATION" == "Release" ]]; then - install_framework "${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework" -fi -if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then - wait -fi diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h deleted file mode 100644 index 99ffa46..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests-umbrella.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __OBJC__ -#import -#else -#ifndef FOUNDATION_EXPORT -#if defined(__cplusplus) -#define FOUNDATION_EXPORT extern "C" -#else -#define FOUNDATION_EXPORT extern -#endif -#endif -#endif - - -FOUNDATION_EXPORT double Pods_UBTestsVersionNumber; -FOUNDATION_EXPORT const unsigned char Pods_UBTestsVersionString[]; - diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig deleted file mode 100644 index e945731..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.debug.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES -FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" -GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 -HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" -LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks' -OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" -OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -PODS_BUILD_DIR = ${BUILD_DIR} -PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) -PODS_PODFILE_DIR_PATH = ${SRCROOT}/. -PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap deleted file mode 100644 index bcd72b7..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -framework module Pods_UBTests { - umbrella header "Pods-UBTests-umbrella.h" - - export * - module * { export * } -} diff --git a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig b/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig deleted file mode 100644 index e945731..0000000 --- a/Pods/Target Support Files/Pods-UBTests/Pods-UBTests.release.xcconfig +++ /dev/null @@ -1,11 +0,0 @@ -ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES -FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf" -GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 -HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf/SwiftProtobuf.framework/Headers" -LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks' -OTHER_LDFLAGS = $(inherited) -framework "SwiftProtobuf" -OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -PODS_BUILD_DIR = ${BUILD_DIR} -PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) -PODS_PODFILE_DIR_PATH = ${SRCROOT}/. -PODS_ROOT = ${SRCROOT}/Pods diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist deleted file mode 100644 index 2f66809..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - ${PRODUCT_BUNDLE_IDENTIFIER} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.6.0 - CFBundleSignature - ???? - CFBundleVersion - ${CURRENT_PROJECT_VERSION} - NSPrincipalClass - - - diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m deleted file mode 100644 index 95f025a..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-dummy.m +++ /dev/null @@ -1,5 +0,0 @@ -#import -@interface PodsDummy_SwiftProtobuf : NSObject -@end -@implementation PodsDummy_SwiftProtobuf -@end diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch deleted file mode 100644 index 082f8af..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-prefix.pch +++ /dev/null @@ -1,12 +0,0 @@ -#ifdef __OBJC__ -#import -#else -#ifndef FOUNDATION_EXPORT -#if defined(__cplusplus) -#define FOUNDATION_EXPORT extern "C" -#else -#define FOUNDATION_EXPORT extern -#endif -#endif -#endif - diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h deleted file mode 100644 index d03d03b..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf-umbrella.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __OBJC__ -#import -#else -#ifndef FOUNDATION_EXPORT -#if defined(__cplusplus) -#define FOUNDATION_EXPORT extern "C" -#else -#define FOUNDATION_EXPORT extern -#endif -#endif -#endif - - -FOUNDATION_EXPORT double SwiftProtobufVersionNumber; -FOUNDATION_EXPORT const unsigned char SwiftProtobufVersionString[]; - diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap deleted file mode 100644 index a88eceb..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -framework module SwiftProtobuf { - umbrella header "SwiftProtobuf-umbrella.h" - - export * - module * { export * } -} diff --git a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig b/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig deleted file mode 100644 index 271c7f5..0000000 --- a/Pods/Target Support Files/SwiftProtobuf/SwiftProtobuf.xcconfig +++ /dev/null @@ -1,10 +0,0 @@ -CODE_SIGN_IDENTITY = -CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SwiftProtobuf -GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 -OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -PODS_BUILD_DIR = ${BUILD_DIR} -PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) -PODS_ROOT = ${SRCROOT} -PODS_TARGET_SRCROOT = ${PODS_ROOT}/SwiftProtobuf -PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} -SKIP_INSTALL = YES diff --git a/UB.xcworkspace/contents.xcworkspacedata b/UB.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 70e8acb..0000000 --- a/UB.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - From a4a9f73f0bd67a4c31ddd392ce72e4950ce662a0 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 21:56:00 -0400 Subject: [PATCH 17/54] format --- Sources/Main/main.swift | 17 +++++++---------- Sources/UB/Extensions/UUID+Bytes.swift | 10 +++------- Sources/UB/Message.swift | 6 +++--- .../UB/Transports/CoreBluetoothTransport.swift | 6 ++---- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index 91fd624..ec94a5b 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -2,9 +2,9 @@ import Foundation import UB let UBBT = CoreBluetoothTransport() -//var msgs: [Message] = [] +// var msgs: [Message] = [] // -//for i in UInt8(0)...6 { +// for i in UInt8(0)...6 { // let message = Message( // proto: UBID(repeating: 1, count: 1), // recipient: Addr(repeating: 4, count: 4), @@ -14,10 +14,9 @@ let UBBT = CoreBluetoothTransport() // ) // UBBT.send(message: message, to: message.recipient) // sleep() -//} - -//let iphoneUUID = UUID(uuidString: "71150DB7-F394-44C6-B161-FD116855E05D") +// } +// let iphoneUUID = UUID(uuidString: "71150DB7-F394-44C6-B161-FD116855E05D") let iphoneUUID = "0BCD7956-7E10-4562-B5AF-D25F5D8D86AF".utf8 @@ -29,18 +28,16 @@ let message = Message( message: Data(repeating: 7, count: 3) ) // -//let data = withUnsafePointer(to: iphoneUUID!.uuid) { +// let data = withUnsafePointer(to: iphoneUUID!.uuid) { // Data(bytes: $0, count: MemoryLayout.size(ofValue: iphoneUUID!.uuid)) -//} - +// } if #available(OSX 10.12, *) { - let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) {_ in + let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { _ in UBBT.send(message: message, to: Addr(iphoneUUID)) } } else { // Fallback on earlier versions } - RunLoop.current.run() diff --git a/Sources/UB/Extensions/UUID+Bytes.swift b/Sources/UB/Extensions/UUID+Bytes.swift index 3347478..83a3065 100644 --- a/Sources/UB/Extensions/UUID+Bytes.swift +++ b/Sources/UB/Extensions/UUID+Bytes.swift @@ -1,13 +1,9 @@ import Foundation extension UUID { - public var bytes: Data { - get { - return withUnsafePointer(to: self) { - Data(bytes: $0, count: MemoryLayout.size(ofValue: self)) - } + return withUnsafePointer(to: self) { + Data(bytes: $0, count: MemoryLayout.size(ofValue: self)) } } - -} \ No newline at end of file +} diff --git a/Sources/UB/Message.swift b/Sources/UB/Message.swift index 3c85ea8..ad754be 100644 --- a/Sources/UB/Message.swift +++ b/Sources/UB/Message.swift @@ -17,13 +17,13 @@ public struct Message: Equatable { /// The raw message data. public let message: Data - - public init (proto: UBID, recipient: Addr, from: Addr, origin: Addr, message: Data) { + + public init(proto: UBID, recipient: Addr, from: Addr, origin: Addr, message: Data) { self.proto = proto self.recipient = recipient self.from = from self.origin = origin - self.message = message + self.message = message } } diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index fc317e7..24930f1 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -3,7 +3,6 @@ import Foundation /// CoreBluetoothTransport is used to send and receieve message over Bluetooth public class CoreBluetoothTransport: NSObject { - private let centralManager: CBCentralManager private let peripheralManager: CBPeripheralManager @@ -37,7 +36,7 @@ public class CoreBluetoothTransport: NSObject { extension CoreBluetoothTransport: Transport { public var peers: [Peer] { - return []//centralManager.retrieveConnectedPeripherals(withServices: [testServiceID, testServiceID2]) + return [] // centralManager.retrieveConnectedPeripherals(withServices: [testServiceID, testServiceID2]) } /// Send implements a function to send messages between nodes using Bluetooth @@ -46,7 +45,7 @@ extension CoreBluetoothTransport: Transport { /// - message: The message to send. public func send(message: Message, to: Addr) { // check bluetooth is running - + // guard let uuid = String(bytes: to, encoding: .utf8) else { // print("Error: not a valid Byte sequence") // return @@ -72,7 +71,6 @@ extension CoreBluetoothTransport: Transport { print("Error: peripheral with uuid \(to) not found") // @todo error } - } /// Listen implements a function to receive messages being sent to a node. From 29a441b28446db0d1d2dc050333163ada4265037 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 22:40:17 -0400 Subject: [PATCH 18/54] cleanup --- Sources/Main/main.swift | 27 ++++-------------- .../Transports/CoreBluetoothTransport.swift | 28 ++++++++----------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index ec94a5b..7397138 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -2,23 +2,6 @@ import Foundation import UB let UBBT = CoreBluetoothTransport() -// var msgs: [Message] = [] -// -// for i in UInt8(0)...6 { -// let message = Message( -// proto: UBID(repeating: 1, count: 1), -// recipient: Addr(repeating: 4, count: 4), -// from: Addr(repeating: 2, count: 3), -// origin: Addr(repeating: 2, count: 3), -// message: Data(repeating: i, count: 3) -// ) -// UBBT.send(message: message, to: message.recipient) -// sleep() -// } - -// let iphoneUUID = UUID(uuidString: "71150DB7-F394-44C6-B161-FD116855E05D") - -let iphoneUUID = "0BCD7956-7E10-4562-B5AF-D25F5D8D86AF".utf8 let message = Message( proto: UBID(repeating: 1, count: 1), @@ -27,14 +10,14 @@ let message = Message( origin: Addr(repeating: 2, count: 3), message: Data(repeating: 7, count: 3) ) -// -// let data = withUnsafePointer(to: iphoneUUID!.uuid) { -// Data(bytes: $0, count: MemoryLayout.size(ofValue: iphoneUUID!.uuid)) -// } if #available(OSX 10.12, *) { let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { _ in - UBBT.send(message: message, to: Addr(iphoneUUID)) + + print(UBBT.peripherals.count) + if UBBT.peripherals.count == 1 { + UBBT.send(message: message, to: Array(UBBT.peripherals.keys)[0]) + } } } else { // Fallback on earlier versions diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 24930f1..13dd732 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -6,17 +6,13 @@ public class CoreBluetoothTransport: NSObject { private let centralManager: CBCentralManager private let peripheralManager: CBPeripheralManager - static let ubServiceUUID = CBUUID(string: "0xAAAA") + static let ubServiceUUID = CBUUID(string: "AAAA") static let receiveCharacteristicUUID = CBUUID(string: "0002") - let receiveCharacteristic = CBMutableCharacteristic( - type: receiveCharacteristicUUID, - properties: CBCharacteristicProperties.writeWithoutResponse, - value: nil, - permissions: CBAttributePermissions.writeable - ) + // make this nicer, we need this cause we need a reference to the peripheral? + var perp: CBPeripheral? - private var peripherals = [Addr: CBPeripheral]() + public private(set) var peripherals = [Addr: (CBPeripheral, CBCharacteristic)]() public convenience override init() { self.init( @@ -66,7 +62,7 @@ extension CoreBluetoothTransport: Transport { // print("NAME : \(peripheral)") if let peripheral = peripherals[to] { - peripheral.writeValue(message.message, for: receiveCharacteristic, type: CBCharacteristicWriteType.withoutResponse) + peripheral.0.writeValue(message.message, for: peripheral.1, type: CBCharacteristicWriteType.withoutResponse) } else { print("Error: peripheral with uuid \(to) not found") // @todo error @@ -147,6 +143,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { advertisementData _: [String: Any], rssi _: NSNumber ) { + perp = peripheral peripheral.delegate = self decodePeripheralState(peripheralState: peripheral.state, peripheral: peripheral) centralManager.connect(peripheral) @@ -154,7 +151,8 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { // When connected to a devices, ask for the Services public func centralManager(_: CBCentralManager, didConnect peripheral: CBPeripheral) { - peripheral.discoverServices([CoreBluetoothTransport.receiveCharacteristicUUID]) + perp = peripheral + peripheral.discoverServices([CoreBluetoothTransport.ubServiceUUID]) } public func centralManager(_: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error _: Error?) { @@ -167,11 +165,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { print("Peripheral state: disconnected") case .connected: print("Peripheral state: connected") - if #available(OSX 10.13, *) { - print("UUID: \(peripheral.identifier)") - } else { - // Fallback on earlier versions - } + print("UUID: \(peripheral.identifier)") case .connecting: print("Peripheral state: connecting") case .disconnecting: @@ -194,8 +188,8 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { didDiscoverCharacteristicsFor service: CBService, error _: Error? ) { - if service.characteristics?.contains(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) ?? false { - peripherals[Addr(peripheral.identifier.bytes)] = peripheral + if let characteristic = service.characteristics?.first(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) { + peripherals[Addr(peripheral.identifier.bytes)] = (peripheral, characteristic) } } } From e7b25abcbfcbd4c34fbda3e6f57c3df4ed6be02e Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 22:41:35 -0400 Subject: [PATCH 19/54] delete --- .../Transports/CoreBluetoothTransport.swift | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 13dd732..bba3d9b 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -40,27 +40,6 @@ extension CoreBluetoothTransport: Transport { /// - Parameters: /// - message: The message to send. public func send(message: Message, to: Addr) { - // check bluetooth is running - -// guard let uuid = String(bytes: to, encoding: .utf8) else { -// print("Error: not a valid Byte sequence") -// return -// } -// guard let toUUID = UUID(uuidString: uuid) else { -// print("Error: not a valid UUID sequence") -// return -// } -// -// -// let peripherals = centralManager.retrievePeripherals(withIdentifiers: [toUUID]) -// if peripherals.count == 0 { -// print("Error: peripheral with uuid \(to) not found") -// return -// } -// -// let peripheral = peripherals[0] -// print("NAME : \(peripheral)") - if let peripheral = peripherals[to] { peripheral.0.writeValue(message.message, for: peripheral.1, type: CBCharacteristicWriteType.withoutResponse) } else { From f368dc3d57b9ee6eb3cb7e7fc9a6b8f7fb92bc9f Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:07:40 -0400 Subject: [PATCH 20/54] refactor --- Package.swift | 3 +++ Sources/UB/Transports/CoreBluetoothTransport.swift | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 8b1008c..1d62ff2 100644 --- a/Package.swift +++ b/Package.swift @@ -4,6 +4,9 @@ import PackageDescription let package = Package( name: "UB", + platforms: [ + .macOS(.v10_13), + ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index bba3d9b..286be35 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -155,11 +155,9 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { extension CoreBluetoothTransport: CBPeripheralDelegate { public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices _: Error?) { - guard let service = peripheral.services?.first(where: { $0.uuid == CoreBluetoothTransport.ubServiceUUID }) else { - return + if let service = peripheral.services?.first(where: { $0.uuid == CoreBluetoothTransport.ubServiceUUID }) { + peripheral.discoverCharacteristics([CoreBluetoothTransport.receiveCharacteristicUUID], for: service) } - - peripheral.discoverCharacteristics([CoreBluetoothTransport.receiveCharacteristicUUID], for: service) } public func peripheral( From 0b171d8fbe498dcb5a43a7c8786c76fd0b87b357 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:12:36 -0400 Subject: [PATCH 21/54] fixed --- Sources/Main/main.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index 7397138..7a1546d 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -8,19 +8,14 @@ let message = Message( recipient: Addr(repeating: 4, count: 4), from: Addr(repeating: 2, count: 3), origin: Addr(repeating: 2, count: 3), - message: Data(repeating: 7, count: 3) + message: Data(repeating: 8, count: 3) ) -if #available(OSX 10.12, *) { - let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { _ in - - print(UBBT.peripherals.count) - if UBBT.peripherals.count == 1 { - UBBT.send(message: message, to: Array(UBBT.peripherals.keys)[0]) - } +let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { _ in + print(UBBT.peripherals.count) + if UBBT.peripherals.count == 1 { + UBBT.send(message: message, to: Array(UBBT.peripherals.keys)[0]) } -} else { - // Fallback on earlier versions } RunLoop.current.run() From ca9034617ff8ae99c2305407bb9ed40617707fe1 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:25:23 -0400 Subject: [PATCH 22/54] refactor --- .../Transports/CoreBluetoothTransport.swift | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 286be35..18e9d12 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -61,20 +61,22 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { if peripheral.state == .poweredOn { - let WR_UUID = CBUUID(string: "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") - let WR_PROPERTIES: CBCharacteristicProperties = .write - let WR_PERMISSIONS: CBAttributePermissions = .writeable - let serialService = CBMutableService(type: CoreBluetoothTransport.ubServiceUUID, primary: true) - - let writeCharacteristics = CBMutableCharacteristic(type: WR_UUID, - properties: WR_PROPERTIES, value: nil, - permissions: WR_PERMISSIONS) - serialService.characteristics = [writeCharacteristics] - peripheral.add(serialService) - - peripheral.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], - CBAdvertisementDataLocalNameKey: nil]) + let service = CBMutableService(type: CoreBluetoothTransport.ubServiceUUID, primary: true) + + let characteristic = CBMutableCharacteristic( + type: CoreBluetoothTransport.receiveCharacteristicUUID, + properties: .writeWithoutResponse, value: nil, + permissions: .writeable + ) + + service.characteristics = [characteristic] + peripheral.add(service) + + peripheral.startAdvertising([ + CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], + CBAdvertisementDataLocalNameKey: nil + ]) } } From 93d66bd317e0153e97d97426ec620fad9570f6f2 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:25:41 -0400 Subject: [PATCH 23/54] removed eol --- Sources/UB/Transports/CoreBluetoothTransport.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 18e9d12..19b8140 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -61,7 +61,6 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { if peripheral.state == .poweredOn { - let service = CBMutableService(type: CoreBluetoothTransport.ubServiceUUID, primary: true) let characteristic = CBMutableCharacteristic( From 0c9c0301671dd0c277c82ec83d6eb581fdc712bc Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:36:09 -0400 Subject: [PATCH 24/54] major cleanup --- Sources/Main/main.swift | 6 +- .../Transports/CoreBluetoothTransport.swift | 60 +++++++------------ 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/Sources/Main/main.swift b/Sources/Main/main.swift index 7a1546d..e688f4d 100644 --- a/Sources/Main/main.swift +++ b/Sources/Main/main.swift @@ -12,9 +12,9 @@ let message = Message( ) let timer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { _ in - print(UBBT.peripherals.count) - if UBBT.peripherals.count == 1 { - UBBT.send(message: message, to: Array(UBBT.peripherals.keys)[0]) + print(UBBT.peers.count) + if UBBT.peers.count == 1 { + UBBT.send(message: message, to: UBBT.peers[0].id) } } diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 19b8140..753744f 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -2,7 +2,7 @@ import CoreBluetooth import Foundation /// CoreBluetoothTransport is used to send and receieve message over Bluetooth -public class CoreBluetoothTransport: NSObject { +public class CoreBluetoothTransport: NSObject, Transport { private let centralManager: CBCentralManager private let peripheralManager: CBPeripheralManager @@ -11,9 +11,12 @@ public class CoreBluetoothTransport: NSObject { // make this nicer, we need this cause we need a reference to the peripheral? var perp: CBPeripheral? + + public fileprivate(set) var peers = [Peer]() - public private(set) var peripherals = [Addr: (CBPeripheral, CBCharacteristic)]() + private var peripherals = [Addr: (CBPeripheral, CBCharacteristic)]() + /// Initializes a CoreBluetoothTransport with a new CBCentralManager and CBPeripheralManager. public convenience override init() { self.init( centralManager: CBCentralManager(delegate: nil, queue: nil), @@ -21,6 +24,11 @@ public class CoreBluetoothTransport: NSObject { ) } + /// Initializes a CoreBluetoothTransport. + /// + /// - Parameters: + /// - centralManager: The CoreBluetooth Central Manager to use. + /// - peripheralManager: The CoreBluetooth Peripheral Manager to use. public init(centralManager: CBCentralManager, peripheralManager: CBPeripheralManager) { self.centralManager = centralManager self.peripheralManager = peripheralManager @@ -28,13 +36,7 @@ public class CoreBluetoothTransport: NSObject { self.centralManager.delegate = self self.peripheralManager.delegate = self } -} - -extension CoreBluetoothTransport: Transport { - public var peers: [Peer] { - return [] // centralManager.retrieveConnectedPeripherals(withServices: [testServiceID, testServiceID2]) - } - + /// Send implements a function to send messages between nodes using Bluetooth /// /// - Parameters: @@ -99,21 +101,11 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { extension CoreBluetoothTransport: CBCentralManagerDelegate { /// Lets us know if Bluetooth is in correct state to start. public func centralManagerDidUpdateState(_ central: CBCentralManager) { - switch central.state { - case .unknown: - print("Bluetooth status is UNKNOWN") - case .resetting: - print("Bluetooth status is RESETTING") - case .unsupported: - print("Bluetooth status is UNSUPPORTED") - case .unauthorized: - print("Bluetooth status is UNAUTHORIZED") - case .poweredOff: - print("Bluetooth status is POWERED OFF") - case .poweredOn: - print("Bluetooth status is POWERED ON") + if central.state == .poweredOn { centralManager.scanForPeripherals(withServices: [CoreBluetoothTransport.ubServiceUUID]) } + + // @todo handling for other states } // Try to connect to discovered devices @@ -125,7 +117,6 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { ) { perp = peripheral peripheral.delegate = self - decodePeripheralState(peripheralState: peripheral.state, peripheral: peripheral) centralManager.connect(peripheral) } @@ -136,21 +127,10 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { } public func centralManager(_: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error _: Error?) { - peripherals.removeValue(forKey: Addr(peripheral.identifier.bytes)) - } - - func decodePeripheralState(peripheralState: CBPeripheralState, peripheral: CBPeripheral) { - switch peripheralState { - case .disconnected: - print("Peripheral state: disconnected") - case .connected: - print("Peripheral state: connected") - print("UUID: \(peripheral.identifier)") - case .connecting: - print("Peripheral state: connecting") - case .disconnecting: - print("Peripheral state: disconnecting") - } + let peer = Addr(peripheral.identifier.bytes) + + peripherals.removeValue(forKey: peer) + peers.removeAll(where: { $0.id == peer }) } } @@ -167,7 +147,9 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { error _: Error? ) { if let characteristic = service.characteristics?.first(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) { - peripherals[Addr(peripheral.identifier.bytes)] = (peripheral, characteristic) + let id = Addr(peripheral.identifier.bytes) + peripherals[id] = (peripheral, characteristic) + peers.append(Peer(id: id, services: [UBID]())) // @TODO SERVICES } } } From c70f416fb8ae6b4ebdbcf243c36741f858af3309 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:37:02 -0400 Subject: [PATCH 25/54] format --- Sources/UB/Transports/CoreBluetoothTransport.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 753744f..a7b02a2 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -11,7 +11,7 @@ public class CoreBluetoothTransport: NSObject, Transport { // make this nicer, we need this cause we need a reference to the peripheral? var perp: CBPeripheral? - + public fileprivate(set) var peers = [Peer]() private var peripherals = [Addr: (CBPeripheral, CBCharacteristic)]() @@ -36,7 +36,7 @@ public class CoreBluetoothTransport: NSObject, Transport { self.centralManager.delegate = self self.peripheralManager.delegate = self } - + /// Send implements a function to send messages between nodes using Bluetooth /// /// - Parameters: @@ -70,13 +70,13 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { properties: .writeWithoutResponse, value: nil, permissions: .writeable ) - + service.characteristics = [characteristic] peripheral.add(service) peripheral.startAdvertising([ CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], - CBAdvertisementDataLocalNameKey: nil + CBAdvertisementDataLocalNameKey: nil, ]) } } @@ -104,7 +104,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { if central.state == .poweredOn { centralManager.scanForPeripherals(withServices: [CoreBluetoothTransport.ubServiceUUID]) } - + // @todo handling for other states } @@ -128,7 +128,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { public func centralManager(_: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error _: Error?) { let peer = Addr(peripheral.identifier.bytes) - + peripherals.removeValue(forKey: peer) peers.removeAll(where: { $0.id == peer }) } From d4675af99225ba986d734d9505510c150ffb6d4e Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:45:54 -0400 Subject: [PATCH 26/54] fixed lint issues --- Sources/UB/Transports/CoreBluetoothTransport.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index a7b02a2..f0333e8 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -76,7 +76,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { peripheral.startAdvertising([ CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], - CBAdvertisementDataLocalNameKey: nil, + CBAdvertisementDataLocalNameKey: nil ]) } } @@ -122,7 +122,6 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { // When connected to a devices, ask for the Services public func centralManager(_: CBCentralManager, didConnect peripheral: CBPeripheral) { - perp = peripheral peripheral.discoverServices([CoreBluetoothTransport.ubServiceUUID]) } @@ -146,9 +145,14 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { didDiscoverCharacteristicsFor service: CBService, error _: Error? ) { - if let characteristic = service.characteristics?.first(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) { - let id = Addr(peripheral.identifier.bytes) - peripherals[id] = (peripheral, characteristic) + let id = Addr(peripheral.identifier.bytes) + if peripherals[id] != nil { + return + } + + let characteristics = service.characteristics + if let char = characteristics?.first(where: { $0.uuid == CoreBluetoothTransport.receiveCharacteristicUUID }) { + peripherals[id] = (peripheral, char) peers.append(Peer(id: id, services: [UBID]())) // @TODO SERVICES } } From cfa405545e1c2fb998cfa0423d4901ffcb965253 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:46:09 -0400 Subject: [PATCH 27/54] fixed --- Sources/UB/Transports/CoreBluetoothTransport.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index f0333e8..6d05c0d 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -76,7 +76,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { peripheral.startAdvertising([ CBAdvertisementDataServiceUUIDsKey: [CoreBluetoothTransport.ubServiceUUID], - CBAdvertisementDataLocalNameKey: nil + CBAdvertisementDataLocalNameKey: nil, ]) } } From 77908506a59c13877950fad45ff93336224629f4 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:48:49 -0400 Subject: [PATCH 28/54] disable rule --- .swiftlint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.swiftlint.yml b/.swiftlint.yml index c4e7e51..190dddd 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -10,3 +10,5 @@ identifier_name: excluded: - id - to +disabled_rules: + - trailing_comma From 81a5973a3cf5b1aa2a69788976b14ae05087ca73 Mon Sep 17 00:00:00 2001 From: decanus Date: Thu, 5 Sep 2019 23:54:56 -0400 Subject: [PATCH 29/54] done --- Sources/UB/Transports/CoreBluetoothTransport.swift | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 6d05c0d..1ea15a0 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -85,15 +85,8 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { print("Got a message! Ding!") for request in requests { if let value = request.value { - if let messageText = String(data: value, encoding: String.Encoding.utf8) as! String? { - print("GOOOOTEEMMM \(messageText)") - - } else { - print("failed to decode string of \(value.hexEncodedString())") - } - // appendMessageToChat(message: Message(text: messageText!, isSent: false)) + print(value) } - peripheral.respond(to: request, withResult: .success) } } } From 8f659a87715d73cafe0ff2a10e61d8ff2fca8ace Mon Sep 17 00:00:00 2001 From: decanus Date: Fri, 6 Sep 2019 00:17:20 -0400 Subject: [PATCH 30/54] minor --- Sources/UB/Transports/CoreBluetoothTransport.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 1ea15a0..66ac6af 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -81,7 +81,7 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { } } - public func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { + public func peripheralManager(_: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { print("Got a message! Ding!") for request in requests { if let value = request.value { @@ -149,4 +149,13 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { peers.append(Peer(id: id, services: [UBID]())) // @TODO SERVICES } } + + public func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) { + if invalidatedServices.contains(where: { $0.uuid == CoreBluetoothTransport.ubServiceUUID }) { + let peer = Addr(peripheral.identifier.bytes) + + peripherals.removeValue(forKey: peer) + peers.removeAll(where: { $0.id == peer }) + } + } } From 34ecca72f8445533078d9be827324f1257f841e8 Mon Sep 17 00:00:00 2001 From: decanus Date: Fri, 6 Sep 2019 07:33:01 -0400 Subject: [PATCH 31/54] removed comments --- Sources/UB/Transports/CoreBluetoothTransport.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 66ac6af..8465aa2 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -60,7 +60,6 @@ public class CoreBluetoothTransport: NSObject, Transport { } extension CoreBluetoothTransport: CBPeripheralManagerDelegate { - // Start Advertisement public func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { if peripheral.state == .poweredOn { let service = CBMutableService(type: CoreBluetoothTransport.ubServiceUUID, primary: true) @@ -86,13 +85,13 @@ extension CoreBluetoothTransport: CBPeripheralManagerDelegate { for request in requests { if let value = request.value { print(value) + } } } } extension CoreBluetoothTransport: CBCentralManagerDelegate { - /// Lets us know if Bluetooth is in correct state to start. public func centralManagerDidUpdateState(_ central: CBCentralManager) { if central.state == .poweredOn { centralManager.scanForPeripherals(withServices: [CoreBluetoothTransport.ubServiceUUID]) @@ -101,7 +100,6 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { // @todo handling for other states } - // Try to connect to discovered devices public func centralManager( _ central: CBCentralManager, didDiscover peripheral: CBPeripheral, @@ -113,7 +111,6 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { centralManager.connect(peripheral) } - // When connected to a devices, ask for the Services public func centralManager(_: CBCentralManager, didConnect peripheral: CBPeripheral) { peripheral.discoverServices([CoreBluetoothTransport.ubServiceUUID]) } From a325ff09689479499cfd31a34238f3440c4a24f4 Mon Sep 17 00:00:00 2001 From: decanus Date: Fri, 6 Sep 2019 07:43:30 -0400 Subject: [PATCH 32/54] minor --- .../Transports/CoreBluetoothTransport.swift | 15 +- docs/Classes.html | 47 +- docs/Classes/CoreBluetoothTransport.html | 583 ++++++++++++++++++ docs/Classes/Node.html | 15 +- docs/Classes/Peer.html | 15 +- docs/Extensions.html | 138 +++++ docs/Extensions/UUID.html | 143 +++++ docs/Protocols.html | 15 +- docs/Protocols/NodeDelegate.html | 15 +- docs/Protocols/Transport.html | 15 +- docs/Structs.html | 15 +- docs/Structs/Message.html | 42 +- docs/Typealiases.html | 15 +- docs/badge.svg | 6 +- .../Contents/Resources/Documents/Classes.html | 47 +- .../Classes/CoreBluetoothTransport.html | 583 ++++++++++++++++++ .../Resources/Documents/Classes/Node.html | 15 +- .../Resources/Documents/Classes/Peer.html | 15 +- .../Resources/Documents/Extensions.html | 138 +++++ .../Resources/Documents/Extensions/UUID.html | 143 +++++ .../Resources/Documents/Protocols.html | 15 +- .../Documents/Protocols/NodeDelegate.html | 15 +- .../Documents/Protocols/Transport.html | 15 +- .../Contents/Resources/Documents/Structs.html | 15 +- .../Resources/Documents/Structs/Message.html | 42 +- .../Resources/Documents/Typealiases.html | 15 +- .../Contents/Resources/Documents/index.html | 15 +- .../Contents/Resources/Documents/search.json | 2 +- .../UB.docset/Contents/Resources/docSet.dsidx | Bin 12288 -> 28672 bytes docs/docsets/UB.tgz | Bin 46591 -> 50405 bytes docs/index.html | 15 +- docs/search.json | 2 +- docs/undocumented.json | 81 ++- 33 files changed, 2197 insertions(+), 55 deletions(-) create mode 100644 docs/Classes/CoreBluetoothTransport.html create mode 100644 docs/Extensions.html create mode 100644 docs/Extensions/UUID.html create mode 100644 docs/docsets/UB.docset/Contents/Resources/Documents/Classes/CoreBluetoothTransport.html create mode 100644 docs/docsets/UB.docset/Contents/Resources/Documents/Extensions.html create mode 100644 docs/docsets/UB.docset/Contents/Resources/Documents/Extensions/UUID.html diff --git a/Sources/UB/Transports/CoreBluetoothTransport.swift b/Sources/UB/Transports/CoreBluetoothTransport.swift index 8465aa2..810d71b 100644 --- a/Sources/UB/Transports/CoreBluetoothTransport.swift +++ b/Sources/UB/Transports/CoreBluetoothTransport.swift @@ -57,6 +57,11 @@ public class CoreBluetoothTransport: NSObject, Transport { public func listen(_: (Message) -> Void) { print("B") } + + fileprivate func remove(peer: Addr) { + peripherals.removeValue(forKey: peer) + peers.removeAll(where: { $0.id == peer }) + } } extension CoreBluetoothTransport: CBPeripheralManagerDelegate { @@ -116,10 +121,7 @@ extension CoreBluetoothTransport: CBCentralManagerDelegate { } public func centralManager(_: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error _: Error?) { - let peer = Addr(peripheral.identifier.bytes) - - peripherals.removeValue(forKey: peer) - peers.removeAll(where: { $0.id == peer }) + remove(peer: Addr(peripheral.identifier.bytes)) } } @@ -149,10 +151,7 @@ extension CoreBluetoothTransport: CBPeripheralDelegate { public func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) { if invalidatedServices.contains(where: { $0.uuid == CoreBluetoothTransport.ubServiceUUID }) { - let peer = Addr(peripheral.identifier.bytes) - - peripherals.removeValue(forKey: peer) - peers.removeAll(where: { $0.id == peer }) + remove(peer: Addr(peripheral.identifier.bytes)) } } } diff --git a/docs/Classes.html b/docs/Classes.html index 351dd3c..5b722c2 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -14,7 +14,7 @@
-

UB Docs (96% documented)

+

UB Docs (73% documented)

View on GitHub

@@ -31,6 +31,9 @@ + +