mirror of
https://github.com/google/flatbuffers.git
synced 2026-11-12 06:56:21 +00:00
[Swift] Migrate to swift 6.0 and Implements support gRPC v2 (#8983)
* Migrate to swift 6.0 & swift-gRPC 2.0 The following migrates to swift 6.0, and also migrate to swift-grpc 2.0 that uses swift-nio under the hood to provide nicer API and async await Adds sendable to enum & update @_implementationOnly imports to use internal imports * Address PR comments regarding misspelling & proper method naming.
This commit is contained in:
@@ -1,147 +0,0 @@
|
||||
// Generated GRPC code for FlatBuffers swift!
|
||||
/// The following code is generated by the Flatbuffers library which might not be in sync with grpc-swift
|
||||
/// in case of an issue please open github issue, though it would be maintained
|
||||
|
||||
// swiftlint:disable all
|
||||
// swiftformat:disable all
|
||||
|
||||
#if !os(Windows)
|
||||
import Foundation
|
||||
import GRPC
|
||||
import NIO
|
||||
import NIOHTTP1
|
||||
import FlatBuffers
|
||||
|
||||
public protocol GRPCFlatBufPayload: GRPCPayload, FlatBufferGRPCMessage {}
|
||||
public extension GRPCFlatBufPayload {
|
||||
init(serializedByteBuffer: inout NIO.ByteBuffer) throws {
|
||||
self.init(byteBuffer: FlatBuffers.ByteBuffer(contiguousBytes: serializedByteBuffer.readableBytesView, count: serializedByteBuffer.readableBytes))
|
||||
}
|
||||
func serialize(into buffer: inout NIO.ByteBuffer) throws {
|
||||
withUnsafeReadableBytes { buffer.writeBytes($0) }
|
||||
}
|
||||
}
|
||||
extension Message: GRPCFlatBufPayload {}
|
||||
|
||||
/// Usage: instantiate models_GreeterServiceClient, then call methods of this protocol to make API calls.
|
||||
public protocol models_GreeterClientProtocol: GRPCClient {
|
||||
|
||||
var serviceName: String { get }
|
||||
|
||||
var interceptors: models_GreeterClientInterceptorFactoryProtocol? { get }
|
||||
|
||||
func SayHello(
|
||||
_ request: Message<models_HelloRequest>
|
||||
, callOptions: CallOptions?
|
||||
) -> UnaryCall<Message<models_HelloRequest>, Message<models_HelloReply>>
|
||||
|
||||
func SayManyHellos(
|
||||
_ request: Message<models_HelloRequest>
|
||||
, callOptions: CallOptions?,
|
||||
handler: @escaping (Message<models_HelloReply>) -> Void
|
||||
) -> ServerStreamingCall<Message<models_HelloRequest>, Message<models_HelloReply>>
|
||||
|
||||
}
|
||||
|
||||
extension models_GreeterClientProtocol {
|
||||
|
||||
public var serviceName: String { "models.Greeter" }
|
||||
|
||||
public func SayHello(
|
||||
_ request: Message<models_HelloRequest>
|
||||
, callOptions: CallOptions? = nil
|
||||
) -> UnaryCall<Message<models_HelloRequest>, Message<models_HelloReply>> {
|
||||
return self.makeUnaryCall(
|
||||
path: "/models.Greeter/SayHello",
|
||||
request: request,
|
||||
callOptions: callOptions ?? self.defaultCallOptions,
|
||||
interceptors: self.interceptors?.makeSayHelloInterceptors() ?? []
|
||||
)
|
||||
}
|
||||
|
||||
public func SayManyHellos(
|
||||
_ request: Message<models_HelloRequest>
|
||||
, callOptions: CallOptions? = nil,
|
||||
handler: @escaping (Message<models_HelloReply>) -> Void
|
||||
) -> ServerStreamingCall<Message<models_HelloRequest>, Message<models_HelloReply>> {
|
||||
return self.makeServerStreamingCall(
|
||||
path: "/models.Greeter/SayManyHellos",
|
||||
request: request,
|
||||
callOptions: callOptions ?? self.defaultCallOptions,
|
||||
interceptors: self.interceptors?.makeSayManyHellosInterceptors() ?? [],
|
||||
handler: handler
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public protocol models_GreeterClientInterceptorFactoryProtocol {
|
||||
/// - Returns: Interceptors to use when invoking 'SayHello'.
|
||||
func makeSayHelloInterceptors() -> [ClientInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
||||
|
||||
/// - Returns: Interceptors to use when invoking 'SayManyHellos'.
|
||||
func makeSayManyHellosInterceptors() -> [ClientInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
||||
|
||||
}
|
||||
|
||||
public final class models_GreeterServiceClient: models_GreeterClientProtocol {
|
||||
public let channel: GRPCChannel
|
||||
public var defaultCallOptions: CallOptions
|
||||
public var interceptors: models_GreeterClientInterceptorFactoryProtocol?
|
||||
|
||||
public init(
|
||||
channel: GRPCChannel,
|
||||
defaultCallOptions: CallOptions = CallOptions(),
|
||||
interceptors: models_GreeterClientInterceptorFactoryProtocol? = nil
|
||||
) {
|
||||
self.channel = channel
|
||||
self.defaultCallOptions = defaultCallOptions
|
||||
self.interceptors = interceptors
|
||||
}
|
||||
}
|
||||
|
||||
public protocol models_GreeterProvider: CallHandlerProvider {
|
||||
var interceptors: models_GreeterServerInterceptorFactoryProtocol? { get }
|
||||
func SayHello(request: Message<models_HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<models_HelloReply>>
|
||||
func SayManyHellos(request: Message<models_HelloRequest>, context: StreamingResponseCallContext<Message<models_HelloReply>>) -> EventLoopFuture<GRPCStatus>
|
||||
}
|
||||
|
||||
public extension models_GreeterProvider {
|
||||
|
||||
var serviceName: Substring { return "models.Greeter" }
|
||||
|
||||
func handle(method name: Substring, context: CallHandlerContext) -> GRPCServerHandlerProtocol? {
|
||||
switch name {
|
||||
case "SayHello":
|
||||
return UnaryServerHandler(
|
||||
context: context,
|
||||
requestDeserializer: GRPCPayloadDeserializer<Message<models_HelloRequest>>(),
|
||||
responseSerializer: GRPCPayloadSerializer<Message<models_HelloReply>>(),
|
||||
interceptors: self.interceptors?.makeSayHelloInterceptors() ?? [],
|
||||
userFunction: self.SayHello(request:context:))
|
||||
|
||||
case "SayManyHellos":
|
||||
return ServerStreamingServerHandler(
|
||||
context: context,
|
||||
requestDeserializer: GRPCPayloadDeserializer<Message<models_HelloRequest>>(),
|
||||
responseSerializer: GRPCPayloadSerializer<Message<models_HelloReply>>(),
|
||||
interceptors: self.interceptors?.makeSayManyHellosInterceptors() ?? [],
|
||||
userFunction: self.SayManyHellos(request:context:))
|
||||
|
||||
default: return nil;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public protocol models_GreeterServerInterceptorFactoryProtocol {
|
||||
/// - Returns: Interceptors to use when handling 'SayHello'.
|
||||
/// Defaults to calling `self.makeInterceptors()`.
|
||||
func makeSayHelloInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
||||
|
||||
/// - Returns: Interceptors to use when handling 'SayManyHellos'.
|
||||
/// Defaults to calling `self.makeInterceptors()`.
|
||||
func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// swiftlint:disable all
|
||||
// swiftformat:disable all
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private struct VT {
|
||||
static let message: VOffset = 4
|
||||
}
|
||||
|
||||
public var message: String? { let o = _accessor.offset(VT.message); return o == 0 ? nil : _accessor.string(at: o) }
|
||||
public var messageSegmentArray: [UInt8]? { return _accessor.getVector(at: VT.message) }
|
||||
public static func startHelloReply(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
|
||||
public static func add(message: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: message, at: VT.message) }
|
||||
public static func endHelloReply(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createHelloReply(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
messageOffset message: Offset = Offset()
|
||||
) -> Offset {
|
||||
let __start = models_HelloReply.startHelloReply(&fbb)
|
||||
models_HelloReply.add(message: message, &fbb)
|
||||
return models_HelloReply.endHelloReply(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VT.message, fieldName: "message", required: false, type: ForwardOffset<String>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
extension models_HelloReply: Encodable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case message = "message"
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(message, forKey: .message)
|
||||
}
|
||||
}
|
||||
|
||||
public struct models_HelloRequest: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private struct VT {
|
||||
static let name: VOffset = 4
|
||||
}
|
||||
|
||||
public var name: String? { let o = _accessor.offset(VT.name); return o == 0 ? nil : _accessor.string(at: o) }
|
||||
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VT.name) }
|
||||
public static func startHelloRequest(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
|
||||
public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VT.name) }
|
||||
public static func endHelloRequest(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createHelloRequest(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
nameOffset name: Offset = Offset()
|
||||
) -> Offset {
|
||||
let __start = models_HelloRequest.startHelloRequest(&fbb)
|
||||
models_HelloRequest.add(name: name, &fbb)
|
||||
return models_HelloRequest.endHelloRequest(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VT.name, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
extension models_HelloRequest: Encodable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case name = "name"
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(name, forKey: .name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user