From 5b3666b81954d3d0a3fdddb286492320b8e288c4 Mon Sep 17 00:00:00 2001 From: Daichi Kamemoto Date: Fri, 2 Jun 2017 23:33:47 +0900 Subject: [PATCH] Add Himotoki --- Cartfile | 2 +- Cartfile.resolved | 17 ++++----- JSONShootout.xcodeproj/project.pbxproj | 20 +++++++++++ .../contents.xcworkspacedata | 3 ++ JSONShootoutTests/Himotoki_Tests.swift | 35 +++++++++++++++++++ JSONShootoutTests/SwiftyJSON_Tests.swift | 4 +-- ModelObjects/Program+Himotoki.swift | 23 ++++++++++++ ModelObjects/Recording+Himotoki.swift | 20 +++++++++++ ModelObjects/Recording.swift | 5 +-- 9 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 JSONShootoutTests/Himotoki_Tests.swift create mode 100644 ModelObjects/Program+Himotoki.swift create mode 100644 ModelObjects/Recording+Himotoki.swift diff --git a/Cartfile b/Cartfile index b470ce4..3c4eb27 100644 --- a/Cartfile +++ b/Cartfile @@ -9,4 +9,4 @@ github "hkellaway/Gloss" "master" github "LoganWright/Genome" == 3.0.3 github "postmates/PMJSON" "master" github "bignerdranch/Freddy" ~> 3.0 - +github "ikesyo/Himotoki" "master" diff --git a/Cartfile.resolved b/Cartfile.resolved index 5dd7271..8a5c03d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,11 +1,12 @@ -github "Anviking/Decodable" "ba6b6fb83e0df6f709acd5f2cdd9da8b49492708" -github "bignerdranch/Freddy" "3.0.2" +github "Anviking/Decodable" "3ba1bc350c84aecbaf24dc87c3cbc6ee4a118d19" +github "Hearst-DD/ObjectMapper" "2.2.7" +github "JohnSundell/Unbox" "4c0b4ae2f7aa10c17849e91231a4d2a04291bcfc" github "LoganWright/Genome" "3.0.3" -github "hkellaway/Gloss" "27242cb5175958ce43395ff837f63967ba111d4a" +github "SwiftyJSON/SwiftyJSON" "121d6cc3715822145fd83b8679d7e1644b2e1c59" +github "bignerdranch/Freddy" "3.0.2" +github "hkellaway/Gloss" "e45facba610ceefd4796c264e0989d1947102e62" +github "ikesyo/Himotoki" "c8b03067aa0d72a9cf47185d99d4a13a2fca1f0e" +github "lyft/mapper" "db431abebe6b6ec632a3829edd75be0a440e331a" +github "postmates/PMJSON" "8d4c0a5cd5be1b53c00eef62db2b579a5777eb28" github "utahiosmac/Marshal" "7a814e26312d5e7f1209168ca1a7860dcc12cf5f" -github "Hearst-DD/ObjectMapper" "2.2.2" -github "postmates/PMJSON" "c21e8b9dbf47db2f1a16d7aba453b7844c0cff10" -github "SwiftyJSON/SwiftyJSON" "adf34cfb4c9f2ff4e3c420c6d9fb1e2eaf3b3791" -github "JohnSundell/Unbox" "0466fcb72ee1454a302d3ee6640f19fec4c0e037" github "vdka/json" "0.15.0" -github "lyft/mapper" "4031d7d7c8b111af564a4f5d5970cf5d68747a03" diff --git a/JSONShootout.xcodeproj/project.pbxproj b/JSONShootout.xcodeproj/project.pbxproj index 679efc5..c840caa 100644 --- a/JSONShootout.xcodeproj/project.pbxproj +++ b/JSONShootout.xcodeproj/project.pbxproj @@ -86,6 +86,12 @@ CCD5105B1CFFFF7000E9C0D1 /* SwiftyJSON_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD5105A1CFFFF7000E9C0D1 /* SwiftyJSON_Tests.swift */; }; CCFD5B551D0A718C0021C2B3 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCD510581CFFFB4C00E9C0D1 /* SwiftyJSON.framework */; }; CCFD5B571D0A71990021C2B3 /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CCD510581CFFFB4C00E9C0D1 /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + DF8DD6DC1ECFEDA0002B3D1A /* Himotoki.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF8DD6DB1ECFEDA0002B3D1A /* Himotoki.framework */; }; + DF8DD6DD1ECFEDA0002B3D1A /* Himotoki.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DF8DD6DB1ECFEDA0002B3D1A /* Himotoki.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + DF8DD6E11ECFF587002B3D1A /* Himotoki.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF8DD6DB1ECFEDA0002B3D1A /* Himotoki.framework */; }; + DF8DD6E31ECFF695002B3D1A /* Recording+Himotoki.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF8DD6E21ECFF695002B3D1A /* Recording+Himotoki.swift */; }; + DF8DD6E51ED00848002B3D1A /* Program+Himotoki.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF8DD6E41ED00848002B3D1A /* Program+Himotoki.swift */; }; + DF8DD6E71ED00BE9002B3D1A /* Himotoki_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF8DD6E61ED00BE9002B3D1A /* Himotoki_Tests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -114,6 +120,7 @@ files = ( CC7A7FB81DC053E400A69A0B /* Decodable.framework in Embed Frameworks */, 2098D54B1DC1F5E800A15075 /* Genome.framework in Embed Frameworks */, + DF8DD6DD1ECFEDA0002B3D1A /* Himotoki.framework in Embed Frameworks */, 681299071DBFFCBC009960BE /* ObjectMapper.framework in Embed Frameworks */, CC3023441CF9616600B51746 /* Marshal.framework in Embed Frameworks */, CC3023461CF9616700B51746 /* Mapper.framework in Embed Frameworks */, @@ -195,6 +202,10 @@ CC9786C51CEBACE8005A5DEA /* Unbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Unbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CCD510581CFFFB4C00E9C0D1 /* SwiftyJSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CCD5105A1CFFFF7000E9C0D1 /* SwiftyJSON_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON_Tests.swift; sourceTree = ""; }; + DF8DD6DB1ECFEDA0002B3D1A /* Himotoki.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Himotoki.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DF8DD6E21ECFF695002B3D1A /* Recording+Himotoki.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Recording+Himotoki.swift"; sourceTree = ""; }; + DF8DD6E41ED00848002B3D1A /* Program+Himotoki.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Program+Himotoki.swift"; sourceTree = ""; }; + DF8DD6E61ED00BE9002B3D1A /* Himotoki_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Himotoki_Tests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -206,6 +217,7 @@ 20A0B96B1DC26810001D8A14 /* GenomeFoundation.framework in Frameworks */, 2098D54A1DC1F5E800A15075 /* Genome.framework in Frameworks */, 681299051DBFFCAB009960BE /* ObjectMapper.framework in Frameworks */, + DF8DD6DC1ECFEDA0002B3D1A /* Himotoki.framework in Frameworks */, CCFD5B551D0A718C0021C2B3 /* SwiftyJSON.framework in Frameworks */, 716A8A9A1DC1D10A00BF314B /* Gloss.framework in Frameworks */, CC7A7FB71DC053E400A69A0B /* Decodable.framework in Frameworks */, @@ -232,6 +244,7 @@ files = ( 2F2868961DE7F34B002A6F68 /* Freddy.framework in Frameworks */, 2098D54C1DC1F5FB00A15075 /* Genome.framework in Frameworks */, + DF8DD6E11ECFF587002B3D1A /* Himotoki.framework in Frameworks */, 716A8A9D1DC1D18B00BF314B /* JSON.framework in Frameworks */, 716A8A981DC1D0E900BF314B /* Gloss.framework in Frameworks */, CCD510591CFFFB4C00E9C0D1 /* SwiftyJSON.framework in Frameworks */, @@ -250,6 +263,7 @@ 7C3FCD281DC1B16100C82DEE /* Frameworks */ = { isa = PBXGroup; children = ( + DF8DD6DB1ECFEDA0002B3D1A /* Himotoki.framework */, 2F2868971DE7F48A002A6F68 /* Freddy.framework */, 2F2868951DE7F34B002A6F68 /* Freddy.framework */, 9E9BF9C91DCD117300548161 /* PMJSON.framework */, @@ -318,6 +332,7 @@ AA2B38D31DC0B6D3008CECCD /* JSON_Tests.swift */, 9E9BF9CB1DCD11BA00548161 /* PMJSON_Tests.swift */, 2F28689B1DE7F66F002A6F68 /* Freddy_Tests.swift */, + DF8DD6E61ED00BE9002B3D1A /* Himotoki_Tests.swift */, CC5A1A4C1CEAE182007238F3 /* Large.json */, CC5A1A181CEADE59007238F3 /* Info.plist */, ); @@ -343,6 +358,7 @@ 20A0B9561DC2584D001D8A14 /* Recording+Genome.swift */, 9E9BF9CF1DCD307200548161 /* Recording+PMJSON.swift */, 2F28689F1DE8843C002A6F68 /* Recording+Freddy.swift */, + DF8DD6E21ECFF695002B3D1A /* Recording+Himotoki.swift */, 71337C921DBEBFB400DCA374 /* Program+Marshal.swift */, 71337C941DBEBFC300DCA374 /* Program+Mapper.swift */, 71337C961DBEBFD000DCA374 /* Program+Unbox.swift */, @@ -354,6 +370,7 @@ 20A0B9581DC25B60001D8A14 /* Program+Genome.swift */, 9E9BF9CD1DCD126D00548161 /* Program+PMJSON.swift */, 2F28689D1DE7FB58002A6F68 /* Program+Freddy.swift */, + DF8DD6E41ED00848002B3D1A /* Program+Himotoki.swift */, ); path = ModelObjects; sourceTree = ""; @@ -523,6 +540,7 @@ 5B69A1DE1DBEC9A400B12579 /* Decodable_Tests.swift in Sources */, CCD5105B1CFFFF7000E9C0D1 /* SwiftyJSON_Tests.swift in Sources */, 7C3FCD351DC1B61600C82DEE /* Gloss_Tests.swift in Sources */, + DF8DD6E71ED00BE9002B3D1A /* Himotoki_Tests.swift in Sources */, 9E9BF9CC1DCD11BA00548161 /* PMJSON_Tests.swift in Sources */, 681299181DC00DB1009960BE /* ObjectMapper_Test.swift in Sources */, ); @@ -541,8 +559,10 @@ 6812991B1DC00DBB009960BE /* Program+ObjectMapper.swift in Sources */, 9E9BF9D01DCD307200548161 /* Recording+PMJSON.swift in Sources */, 71337C991DBEBFDC00DCA374 /* Program+SwiftyJSON.swift in Sources */, + DF8DD6E31ECFF695002B3D1A /* Recording+Himotoki.swift in Sources */, 2F28689E1DE7FB58002A6F68 /* Program+Freddy.swift in Sources */, 71337C931DBEBFB400DCA374 /* Program+Marshal.swift in Sources */, + DF8DD6E51ED00848002B3D1A /* Program+Himotoki.swift in Sources */, CC9786C01CEBAC6C005A5DEA /* NSDate+JSON.swift in Sources */, 9E9BF9CE1DCD126D00548161 /* Program+PMJSON.swift in Sources */, 5B69A1DA1DBEC84200B12579 /* Recording+Decodable.swift in Sources */, diff --git a/JSONShootout.xcworkspace/contents.xcworkspacedata b/JSONShootout.xcworkspace/contents.xcworkspacedata index 59f18a9..6988d0f 100644 --- a/JSONShootout.xcworkspace/contents.xcworkspacedata +++ b/JSONShootout.xcworkspace/contents.xcworkspacedata @@ -37,4 +37,7 @@ + + diff --git a/JSONShootoutTests/Himotoki_Tests.swift b/JSONShootoutTests/Himotoki_Tests.swift new file mode 100644 index 0000000..1b2285e --- /dev/null +++ b/JSONShootoutTests/Himotoki_Tests.swift @@ -0,0 +1,35 @@ +// +// Himotoki_Tests.swift +// JSONShootout +// +// Created by yudoufu on 2017/05/20. +// Copyright © 2017年 SwiftBit. All rights reserved. +// + +import XCTest +import ModelObjects +import Himotoki + +class Himotoki_Tests: XCTestCase { + func testDeserialization() { + self.measure { + let d: NSDictionary = try! JSONSerialization.jsonObject(with: self.data, options: []) as! NSDictionary + XCTAssert(d.count > 0) + } + } + + func testPerormance() { + let json = try! JSONSerialization.jsonObject(with: self.data, options: []) + + self.measure { + let programs: [Program] = try! decodeArray(json, rootKeyPath: ["ProgramList", "Programs"]) + XCTAssert(programs.count > 1000) + } + } + + private lazy var data:Data = { + let path = Bundle(for: type(of: self)).url(forResource: "Large", withExtension: "json") + let data = try! Data(contentsOf: path!) + return data + }() +} diff --git a/JSONShootoutTests/SwiftyJSON_Tests.swift b/JSONShootoutTests/SwiftyJSON_Tests.swift index d1cf920..2b7dcc9 100644 --- a/JSONShootoutTests/SwiftyJSON_Tests.swift +++ b/JSONShootoutTests/SwiftyJSON_Tests.swift @@ -14,13 +14,13 @@ class SwiftyJSON_Tests: XCTestCase { func testDeserialization() { self.measure { - let json = JSON(data:self.data as Data) + let json = try! JSON(data:self.data as Data) XCTAssert(json.count > 0) } } func testPerformance() { - let json = JSON(data:self.data as Data) + let json = try! JSON(data:self.data as Data) self.measure { let programRA = json["ProgramList"]["Programs"].arrayValue let programs = programRA.map(Program.init) diff --git a/ModelObjects/Program+Himotoki.swift b/ModelObjects/Program+Himotoki.swift new file mode 100644 index 0000000..2eb79bc --- /dev/null +++ b/ModelObjects/Program+Himotoki.swift @@ -0,0 +1,23 @@ +// +// Program+Himotoki.swift +// JSONShootout +// +// Created by yudoufu on 2017/05/20. +// Copyright © 2017年 SwiftBit. All rights reserved. +// + +import Himotoki + +extension Program: Decodable { + public static func decode(_ e: Extractor) throws -> Program { + return try Program( + title: e <| "Title", + chanId: e <| ["Channel", "ChanId" ], + description: e <|? "Description", + subtitle: e <|? "SubTitle", + recording: e <| "Recording", + season: (e <|? "Season" as String?).flatMap { Int($0) }, + episode: (e <|? "Episode" as String?).flatMap { Int($0) } + ) + } +} diff --git a/ModelObjects/Recording+Himotoki.swift b/ModelObjects/Recording+Himotoki.swift new file mode 100644 index 0000000..313dd77 --- /dev/null +++ b/ModelObjects/Recording+Himotoki.swift @@ -0,0 +1,20 @@ +// +// Recording+Himotoki.swift +// JSONShootout +// +// Created by yudoufu on 2017/05/20. +// Copyright © 2017年 SwiftBit. All rights reserved. +// + +import Himotoki + +extension Recording: Decodable { + public static func decode(_ e: Extractor) throws -> Recording { + return try Recording( + startTsStr: e <| "StartTs", + status: (try? e <| "Status") ?? .Unknown, + recordId: e <| "RecordId", + recGroup: (try? e <| "RecGroup") ?? .Unknown + ) + } +} diff --git a/ModelObjects/Recording.swift b/ModelObjects/Recording.swift index fcc57e4..98d392a 100644 --- a/ModelObjects/Recording.swift +++ b/ModelObjects/Recording.swift @@ -7,16 +7,17 @@ // import Unbox +import Himotoki public struct Recording { - enum Status: String, UnboxableEnum { + enum Status: String, UnboxableEnum, Decodable { case None = "0" case Recorded = "-3" case Recording = "-2" case Unknown } - enum RecGroup: String, UnboxableEnum { + enum RecGroup: String, UnboxableEnum, Decodable { case Deleted = "Deleted" case Default = "Default" case LiveTV = "LiveTV"