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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
22 public protocol TTransport {
25 func read(size: Int) throws -> Data
26 func write(data: Data) throws
29 // Optional (default provided)
30 func readAll(size: Int) throws -> Data
31 func isOpen() throws -> Bool
36 public extension TTransport {
37 func isOpen() throws -> Bool { return true }
38 func open() throws { }
39 func close() throws { }
41 func readAll(size: Int) throws -> Data {
45 let chunk = try self.read(size: size - have)
49 throw TTransportError(error: .endOfFile)
56 public protocol TAsyncTransport : TTransport {
58 func flush(_ completion: @escaping (TAsyncTransport, Error?) ->())
61 public protocol TAsyncTransportFactory {
62 associatedtype Transport : TAsyncTransport
63 func newTransport() -> Transport