blob: 8e8577bb5f21a6187d131d34af4b524dd8cfca74 [file] [log] [blame]
Chris Simpsona9b6c702018-04-08 07:11:37 -04001/*
2* Licensed to the Apache Software Foundation (ASF) under one
3* or more contributor license agreements. See the NOTICE file
4* distributed with this work for additional information
5* regarding copyright ownership. The ASF licenses this file
6* to you under the Apache License, Version 2.0 (the
7* "License"); you may not use this file except in compliance
8* with the License. You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing,
13* software distributed under the License is distributed on an
14* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15* KIND, either express or implied. See the License for the
16* specific language governing permissions and limitations
17* under the License.
18*/
19
20import Foundation // For (NS)Data
21
22
23/// Generic protocol, implementes TProtocol and wraps a concrete protocol.
24/// Useful for generically subclassing protocols to override specific methods
25/// (i.e. TMultiplexedProtocol)
26open class TWrappedProtocol<Protocol: TProtocol> : TProtocol {
27 var concreteProtocol: Protocol
28
29 public var transport: TTransport {
30 get {
31 return concreteProtocol.transport
32 }
33 set {
34 concreteProtocol.transport = newValue
35 }
36 }
37
38 public required init(on transport: TTransport) {
39 self.concreteProtocol = Protocol(on: transport)
40 }
41
42 // Read methods
43
44 public func readMessageBegin() throws -> (String, TMessageType, Int32) {
45 return try concreteProtocol.readMessageBegin()
46 }
47
48 public func readMessageEnd() throws {
49 try concreteProtocol.readMessageEnd()
50 }
51
52 public func readStructBegin() throws -> String {
53 return try concreteProtocol.readStructBegin()
54 }
55
56 public func readStructEnd() throws {
57 try concreteProtocol.readStructEnd()
58 }
59
60 public func readFieldBegin() throws -> (String, TType, Int32) {
61 return try concreteProtocol.readFieldBegin()
62 }
63
64 public func readFieldEnd() throws {
65 try concreteProtocol.readFieldEnd()
66 }
67
68 public func readMapBegin() throws -> (TType, TType, Int32) {
69 return try concreteProtocol.readMapBegin()
70 }
71
72 public func readMapEnd() throws {
73 try concreteProtocol.readMapEnd()
74 }
75
76 public func readSetBegin() throws -> (TType, Int32) {
77 return try concreteProtocol.readSetBegin()
78 }
79
80 public func readSetEnd() throws {
81 try concreteProtocol.readSetEnd()
82 }
83
84 public func readListBegin() throws -> (TType, Int32) {
85 return try concreteProtocol.readListBegin()
86 }
87
88 public func readListEnd() throws {
89 try concreteProtocol.readListEnd()
90 }
91
92 public func read() throws -> String {
93 return try concreteProtocol.read()
94 }
95
96 public func read() throws -> Bool {
97 return try concreteProtocol.read()
98 }
99
100 public func read() throws -> UInt8 {
101 return try concreteProtocol.read()
102 }
103
104 public func read() throws -> Int16 {
105 return try concreteProtocol.read()
106 }
107
108 public func read() throws -> Int32 {
109 return try concreteProtocol.read()
110 }
111
112 public func read() throws -> Int64 {
113 return try concreteProtocol.read()
114 }
115
116 public func read() throws -> Double {
117 return try concreteProtocol.read()
118 }
119
120 public func read() throws -> Data {
121 return try concreteProtocol.read()
122 }
123
124 // Write methods
125
126 public func writeMessageBegin(name: String, type messageType: TMessageType, sequenceID: Int32) throws {
127 return try concreteProtocol.writeMessageBegin(name: name, type: messageType, sequenceID: sequenceID)
128 }
129
130 public func writeMessageEnd() throws {
131 try concreteProtocol.writeMessageEnd()
132 }
133
134 public func writeStructBegin(name: String) throws {
135 try concreteProtocol.writeStructBegin(name: name)
136 }
137
138 public func writeStructEnd() throws {
139 try concreteProtocol.writeStructEnd()
140 }
141
142 public func writeFieldBegin(name: String, type fieldType: TType, fieldID: Int32) throws {
143 try concreteProtocol.writeFieldBegin(name: name, type: fieldType, fieldID: fieldID)
144 }
145
146 public func writeFieldStop() throws {
147 try concreteProtocol.writeFieldStop()
148 }
149
150 public func writeFieldEnd() throws {
151 try concreteProtocol.writeFieldEnd()
152 }
153
154 public func writeMapBegin(keyType: TType, valueType: TType, size: Int32) throws {
155 try concreteProtocol.writeMapBegin(keyType: keyType, valueType: valueType, size: size)
156 }
157
158 public func writeMapEnd() throws {
159 try concreteProtocol.writeMapEnd()
160 }
161
162 public func writeSetBegin(elementType: TType, size: Int32) throws {
163 try concreteProtocol.writeSetBegin(elementType: elementType, size: size)
164 }
165
166 public func writeSetEnd() throws {
167 try concreteProtocol.writeSetEnd()
168 }
169
170 public func writeListBegin(elementType: TType, size: Int32) throws {
171 try concreteProtocol.writeListBegin(elementType: elementType, size: size)
172 }
173
174 public func writeListEnd() throws {
175 try concreteProtocol.writeListEnd()
176 }
177 public func write(_ value: String) throws {
178 try concreteProtocol.write(value)
179 }
180
181 public func write(_ value: Bool) throws {
182 try concreteProtocol.write(value)
183 }
184
185 public func write(_ value: UInt8) throws {
186 try concreteProtocol.write(value)
187 }
188
189 public func write(_ value: Int16) throws {
190 try concreteProtocol.write(value)
191 }
192
193 public func write(_ value: Int32) throws {
194 try concreteProtocol.write(value)
195 }
196
197 public func write(_ value: Int64) throws {
198 try concreteProtocol.write(value)
199 }
200
201 public func write(_ value: Double) throws {
202 try concreteProtocol.write(value)
203 }
204
205 public func write(_ data: Data) throws {
206 try concreteProtocol.write(data)
207 }
208}