Skip to content

Commit

Permalink
添加 Protobuf 解码 可选参数
Browse files Browse the repository at this point in the history
  • Loading branch information
king committed Mar 22, 2018
1 parent 4b65fa9 commit 94c3490
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 285 deletions.
8 changes: 4 additions & 4 deletions Bamboots/Classes/Protobuf/AlamofireProtobuf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ extension DataRequest {
return nil
}

public static func ObjectSerializerPB<T: SwiftProtobuf.Message>() -> DataResponseSerializer<T> {
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!)
let object = try T(serializedData: data!, extensions: extensions, partial: partial, options: options)
return .success(object)
} catch let error {
return .failure(error)
Expand All @@ -50,7 +50,7 @@ extension DataRequest {
}

@discardableResult
public func responsePBObject<T: SwiftProtobuf.Message>(queue: DispatchQueue? = nil, keyPath: String? = nil, completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectSerializerPB(), completionHandler: completionHandler)
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)
}
}
30 changes: 18 additions & 12 deletions Example/Bamboots.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
177E2875D463FAD4770A5F19 /* Pods_Bamboots_Example_Bamboots_ExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B3E973EA00BF9D7F3CEECE9 /* Pods_Bamboots_Example_Bamboots_ExampleTests.framework */; };
1F54ECE6103F557E53676698 /* Pods_Bamboots_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 004F09D44F2FC12978146DFE /* Pods_Bamboots_Example.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
Expand Down Expand Up @@ -122,7 +121,6 @@
buildActionMask = 2147483647;
files = (
986234E96738F5D2804469F5 /* Pods_Bamboots_ExampleTests.framework in Frameworks */,
177E2875D463FAD4770A5F19 /* Pods_Bamboots_Example_Bamboots_ExampleTests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -351,12 +349,12 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 5AQZQKK3GK;
LastSwiftMigration = 0900;
ProvisioningStyle = Manual;
};
A4AF31DD2045045B009BCAF6 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
ProvisioningStyle = Manual;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -643,7 +641,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -690,7 +688,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -704,13 +702,15 @@
baseConfigurationReference = 837C732B84DC9242063FF9D5 /* Pods-Bamboots_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5AQZQKK3GK;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Bamboots/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
Expand All @@ -721,13 +721,15 @@
baseConfigurationReference = 3563A1CF53A46C0766B4B720 /* Pods-Bamboots_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5AQZQKK3GK;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Bamboots/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
Expand All @@ -744,14 +746,16 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Bamboots_ExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.taihe.Bamboots-ExampleTests";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -770,13 +774,15 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Bamboots_ExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.taihe.Bamboots-ExampleTests";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Bamboots_Example.app/Bamboots_Example";
Expand Down
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>
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Alamofire: f41a599bd63041760b26d393ec1069d9d7b917f4
AlamofireCodable: 55cd99b65e96dc0ef690aa3933cf65189095b4e8
Bamboots: 12eb8041d148aa5b60e7f50919931b7c923f91e2
Bamboots: 74efa8605ce0ba1e352703e8ad0720b81392f817
SnapKit: a42d492c16e80209130a3379f73596c3454b7694
SwiftProtobuf: e41d205c91eac0fb46823f2561712407fefdaf4e

PODFILE CHECKSUM: cc0beb97d059592e7098a53fc70ffab10bf3f03e

COCOAPODS: 1.4.0.rc.1
COCOAPODS: 1.4.0
2 changes: 1 addition & 1 deletion Example/Pods/Local Podspecs/Bamboots.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94c3490

Please sign in to comment.