-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from king129/feature/ProtobufSupport
Feature/protobuf support
- Loading branch information
Showing
150 changed files
with
21,732 additions
and
2,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// AlamofireProtobuf.swift | ||
// Pods | ||
// | ||
// Created by sun on 2018/2/27. | ||
// | ||
|
||
import Alamofire | ||
import SwiftProtobuf | ||
|
||
extension DataRequest { | ||
|
||
enum AlamofireProtobufErrorCode: Int { | ||
case noData = 1 | ||
case dataSerializationFailed = 2 | ||
} | ||
|
||
internal static func newError(_ code: AlamofireProtobufErrorCode, failureReason: String) -> NSError { | ||
let errorDomain = "com.alamofireProtobuf.error" | ||
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason] | ||
let returnError = NSError(domain: errorDomain, code: code.rawValue, userInfo: userInfo) | ||
return returnError | ||
} | ||
|
||
/// Utility function for checking for errors in response | ||
internal static func checkResponseForError(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) -> Error? { | ||
if let error = error { | ||
return error | ||
} | ||
guard let _ = data else { | ||
let failureReason = "Data could not be serialized. Input data was nil." | ||
let error = newError(.noData, failureReason: failureReason) | ||
return error | ||
} | ||
return nil | ||
} | ||
|
||
public static func ObjectSerializerPB<T: SwiftProtobuf.Message>(extensions: ExtensionMap?, partial: Bool, options: BinaryDecodingOptions) -> DataResponseSerializer<T> { | ||
return DataResponseSerializer { request, response, data, error in | ||
if let error = checkResponseForError(request: request, response: response, data: data, error: error) { | ||
return .failure(error) | ||
} | ||
do { | ||
let object = try T(serializedData: data!, extensions: extensions, partial: partial, options: options) | ||
return .success(object) | ||
} catch let error { | ||
return .failure(error) | ||
} | ||
} | ||
} | ||
|
||
@discardableResult | ||
public func responsePBObject<T: SwiftProtobuf.Message>(queue: DispatchQueue? = nil, keyPath: String? = nil, extensions: ExtensionMap? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions(), completionHandler: @escaping (DataResponse<T>) -> Void) -> Self { | ||
return response(queue: queue, responseSerializer: DataRequest.ObjectSerializerPB(extensions: extensions, partial: partial, options: options), completionHandler: completionHandler) | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Example/Bamboots.xcodeproj/xcshareddata/xcschemes/Bamboots_ExampleTests.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "0920" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
language = "" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A4AF31DD2045045B009BCAF6" | ||
BuildableName = "Bamboots_ExampleTests.xctest" | ||
BlueprintName = "Bamboots_ExampleTests" | ||
ReferencedContainer = "container:Bamboots.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
language = "" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
Oops, something went wrong.