-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.1.x' into release/widevine/0.1.x
- Loading branch information
Showing
20 changed files
with
260 additions
and
183 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
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
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,51 @@ | ||
// | ||
// ResponseSerializer.swift | ||
// Pods | ||
// | ||
// Created by Rivka Peleg on 14/03/2017. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
enum SerializerError: Error { | ||
case serializationError | ||
} | ||
|
||
|
||
public protocol ResponseSerializer { | ||
/** | ||
This fuction will serialize the response data of certin request to the expected type according to the serializer type | ||
*/ | ||
func serialize(data: Data) throws -> Any | ||
} | ||
|
||
|
||
class JSONSerializer: ResponseSerializer { | ||
|
||
func serialize(data: Data) throws -> Any { | ||
let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions()) | ||
return json | ||
} | ||
} | ||
|
||
|
||
class IntSerializer: ResponseSerializer { | ||
|
||
func serialize(data: Data) throws -> Any { | ||
guard let int8 = [UInt8](data).last else { | ||
throw SerializerError.serializationError | ||
} | ||
|
||
let int: Int = Int(int8) | ||
return int | ||
} | ||
} | ||
|
||
class StringSerializer: ResponseSerializer { | ||
|
||
func serialize(data: Data) throws -> Any { | ||
let string = String(data: data, encoding: .utf8) | ||
return string | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.