mirror of https://github.com/oxen-io/session-ios
Code generate Swift wrappers for protocol buffers.
parent
808443f2a9
commit
b164ce9403
@ -0,0 +1,125 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// WARNING: This code is generated. Only edit within the markers.
|
||||
|
||||
public enum FingerprintProtoError: Error {
|
||||
case invalidProtobuf(description: String)
|
||||
}
|
||||
|
||||
// MARK: - FingerprintProtoLogicalFingerprint
|
||||
|
||||
@objc public class FingerprintProtoLogicalFingerprint: NSObject {
|
||||
|
||||
@objc public let identityData: Data?
|
||||
|
||||
@objc public init(identityData: Data?) {
|
||||
self.identityData = identityData
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprint {
|
||||
let proto = try FingerprintProtos_LogicalFingerprint(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprint) throws -> FingerprintProtoLogicalFingerprint {
|
||||
var identityData: Data? = nil
|
||||
if proto.hasIdentityData {
|
||||
identityData = proto.identityData
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for FingerprintProtoLogicalFingerprint -
|
||||
|
||||
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprint -
|
||||
|
||||
let result = FingerprintProtoLogicalFingerprint(identityData: identityData)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: FingerprintProtos_LogicalFingerprint {
|
||||
let proto = FingerprintProtos_LogicalFingerprint.with { (builder) in
|
||||
if let identityData = self.identityData {
|
||||
builder.identityData = identityData
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - FingerprintProtoLogicalFingerprints
|
||||
|
||||
@objc public class FingerprintProtoLogicalFingerprints: NSObject {
|
||||
|
||||
@objc public let version: UInt32
|
||||
@objc public let localFingerprint: FingerprintProtoLogicalFingerprint?
|
||||
@objc public let remoteFingerprint: FingerprintProtoLogicalFingerprint?
|
||||
|
||||
@objc public init(version: UInt32,
|
||||
localFingerprint: FingerprintProtoLogicalFingerprint?,
|
||||
remoteFingerprint: FingerprintProtoLogicalFingerprint?) {
|
||||
self.version = version
|
||||
self.localFingerprint = localFingerprint
|
||||
self.remoteFingerprint = remoteFingerprint
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprints {
|
||||
let proto = try FingerprintProtos_LogicalFingerprints(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprints) throws -> FingerprintProtoLogicalFingerprints {
|
||||
var version: UInt32 = 0
|
||||
if proto.hasVersion {
|
||||
version = proto.version
|
||||
}
|
||||
|
||||
var localFingerprint: FingerprintProtoLogicalFingerprint? = nil
|
||||
if proto.hasLocalFingerprint {
|
||||
localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint)
|
||||
}
|
||||
|
||||
var remoteFingerprint: FingerprintProtoLogicalFingerprint? = nil
|
||||
if proto.hasRemoteFingerprint {
|
||||
remoteFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.remoteFingerprint)
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for FingerprintProtoLogicalFingerprints -
|
||||
|
||||
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprints -
|
||||
|
||||
let result = FingerprintProtoLogicalFingerprints(version: version,
|
||||
localFingerprint: localFingerprint,
|
||||
remoteFingerprint: remoteFingerprint)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: FingerprintProtos_LogicalFingerprints {
|
||||
let proto = FingerprintProtos_LogicalFingerprints.with { (builder) in
|
||||
builder.version = self.version
|
||||
|
||||
if let localFingerprint = self.localFingerprint {
|
||||
builder.localFingerprint = localFingerprint.asProtobuf
|
||||
}
|
||||
|
||||
if let remoteFingerprint = self.remoteFingerprint {
|
||||
builder.remoteFingerprint = remoteFingerprint.asProtobuf
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// WARNING: This code is generated. Only edit within the markers.
|
||||
|
||||
public enum ProvisioningProtoError: Error {
|
||||
case invalidProtobuf(description: String)
|
||||
}
|
||||
|
||||
// MARK: - ProvisioningProtoProvisionEnvelope
|
||||
|
||||
@objc public class ProvisioningProtoProvisionEnvelope: NSObject {
|
||||
|
||||
@objc public let publicKey: Data?
|
||||
@objc public let body: Data?
|
||||
|
||||
@objc public init(publicKey: Data?,
|
||||
body: Data?) {
|
||||
self.publicKey = publicKey
|
||||
self.body = body
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionEnvelope {
|
||||
let proto = try ProvisioningProtos_ProvisionEnvelope(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionEnvelope) throws -> ProvisioningProtoProvisionEnvelope {
|
||||
var publicKey: Data? = nil
|
||||
if proto.hasPublicKey {
|
||||
publicKey = proto.publicKey
|
||||
}
|
||||
|
||||
var body: Data? = nil
|
||||
if proto.hasBody {
|
||||
body = proto.body
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for ProvisioningProtoProvisionEnvelope -
|
||||
|
||||
// MARK: - End Validation Logic for ProvisioningProtoProvisionEnvelope -
|
||||
|
||||
let result = ProvisioningProtoProvisionEnvelope(publicKey: publicKey,
|
||||
body: body)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: ProvisioningProtos_ProvisionEnvelope {
|
||||
let proto = ProvisioningProtos_ProvisionEnvelope.with { (builder) in
|
||||
if let publicKey = self.publicKey {
|
||||
builder.publicKey = publicKey
|
||||
}
|
||||
|
||||
if let body = self.body {
|
||||
builder.body = body
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ProvisioningProtoProvisionMessage
|
||||
|
||||
@objc public class ProvisioningProtoProvisionMessage: NSObject {
|
||||
|
||||
@objc public let identityKeyPublic: Data?
|
||||
@objc public let identityKeyPrivate: Data?
|
||||
@objc public let number: String?
|
||||
@objc public let provisioningCode: String?
|
||||
@objc public let userAgent: String?
|
||||
@objc public let profileKey: Data?
|
||||
@objc public let readReceipts: Bool
|
||||
|
||||
@objc public init(identityKeyPublic: Data?,
|
||||
identityKeyPrivate: Data?,
|
||||
number: String?,
|
||||
provisioningCode: String?,
|
||||
userAgent: String?,
|
||||
profileKey: Data?,
|
||||
readReceipts: Bool) {
|
||||
self.identityKeyPublic = identityKeyPublic
|
||||
self.identityKeyPrivate = identityKeyPrivate
|
||||
self.number = number
|
||||
self.provisioningCode = provisioningCode
|
||||
self.userAgent = userAgent
|
||||
self.profileKey = profileKey
|
||||
self.readReceipts = readReceipts
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionMessage {
|
||||
let proto = try ProvisioningProtos_ProvisionMessage(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionMessage) throws -> ProvisioningProtoProvisionMessage {
|
||||
var identityKeyPublic: Data? = nil
|
||||
if proto.hasIdentityKeyPublic {
|
||||
identityKeyPublic = proto.identityKeyPublic
|
||||
}
|
||||
|
||||
var identityKeyPrivate: Data? = nil
|
||||
if proto.hasIdentityKeyPrivate {
|
||||
identityKeyPrivate = proto.identityKeyPrivate
|
||||
}
|
||||
|
||||
var number: String? = nil
|
||||
if proto.hasNumber {
|
||||
number = proto.number
|
||||
}
|
||||
|
||||
var provisioningCode: String? = nil
|
||||
if proto.hasProvisioningCode {
|
||||
provisioningCode = proto.provisioningCode
|
||||
}
|
||||
|
||||
var userAgent: String? = nil
|
||||
if proto.hasUserAgent {
|
||||
userAgent = proto.userAgent
|
||||
}
|
||||
|
||||
var profileKey: Data? = nil
|
||||
if proto.hasProfileKey {
|
||||
profileKey = proto.profileKey
|
||||
}
|
||||
|
||||
var readReceipts: Bool = false
|
||||
if proto.hasReadReceipts {
|
||||
readReceipts = proto.readReceipts
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for ProvisioningProtoProvisionMessage -
|
||||
|
||||
// MARK: - End Validation Logic for ProvisioningProtoProvisionMessage -
|
||||
|
||||
let result = ProvisioningProtoProvisionMessage(identityKeyPublic: identityKeyPublic,
|
||||
identityKeyPrivate: identityKeyPrivate,
|
||||
number: number,
|
||||
provisioningCode: provisioningCode,
|
||||
userAgent: userAgent,
|
||||
profileKey: profileKey,
|
||||
readReceipts: readReceipts)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: ProvisioningProtos_ProvisionMessage {
|
||||
let proto = ProvisioningProtos_ProvisionMessage.with { (builder) in
|
||||
if let identityKeyPublic = self.identityKeyPublic {
|
||||
builder.identityKeyPublic = identityKeyPublic
|
||||
}
|
||||
|
||||
if let identityKeyPrivate = self.identityKeyPrivate {
|
||||
builder.identityKeyPrivate = identityKeyPrivate
|
||||
}
|
||||
|
||||
if let number = self.number {
|
||||
builder.number = number
|
||||
}
|
||||
|
||||
if let provisioningCode = self.provisioningCode {
|
||||
builder.provisioningCode = provisioningCode
|
||||
}
|
||||
|
||||
if let userAgent = self.userAgent {
|
||||
builder.userAgent = userAgent
|
||||
}
|
||||
|
||||
if let profileKey = self.profileKey {
|
||||
builder.profileKey = profileKey
|
||||
}
|
||||
|
||||
builder.readReceipts = self.readReceipts
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// WARNING: This code is generated. Only edit within the markers.
|
||||
|
||||
public enum SignalIOSProtoError: Error {
|
||||
case invalidProtobuf(description: String)
|
||||
}
|
||||
|
||||
// MARK: - SignalIOSProtoBackupSnapshotBackupEntity
|
||||
|
||||
@objc public class SignalIOSProtoBackupSnapshotBackupEntity: NSObject {
|
||||
|
||||
// MARK: - SignalIOSProtoBackupSnapshotBackupEntityType
|
||||
|
||||
@objc public enum SignalIOSProtoBackupSnapshotBackupEntityType: Int32 {
|
||||
case unknown = 0
|
||||
case migration = 1
|
||||
case thread = 2
|
||||
case interaction = 3
|
||||
case attachment = 4
|
||||
}
|
||||
|
||||
private class func SignalIOSProtoBackupSnapshotBackupEntityTypeWrap(_ value: IOSProtos_BackupSnapshot.BackupEntity.TypeEnum) -> SignalIOSProtoBackupSnapshotBackupEntityType {
|
||||
switch value {
|
||||
case .unknown: return .unknown
|
||||
case .migration: return .migration
|
||||
case .thread: return .thread
|
||||
case .interaction: return .interaction
|
||||
case .attachment: return .attachment
|
||||
}
|
||||
}
|
||||
|
||||
private class func SignalIOSProtoBackupSnapshotBackupEntityTypeUnwrap(_ value: SignalIOSProtoBackupSnapshotBackupEntityType) -> IOSProtos_BackupSnapshot.BackupEntity.TypeEnum {
|
||||
switch value {
|
||||
case .unknown: return .unknown
|
||||
case .migration: return .migration
|
||||
case .thread: return .thread
|
||||
case .interaction: return .interaction
|
||||
case .attachment: return .attachment
|
||||
}
|
||||
}
|
||||
|
||||
@objc public let type: SignalIOSProtoBackupSnapshotBackupEntityType
|
||||
@objc public let entityData: Data?
|
||||
|
||||
@objc public init(type: SignalIOSProtoBackupSnapshotBackupEntityType,
|
||||
entityData: Data?) {
|
||||
self.type = type
|
||||
self.entityData = entityData
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
||||
let proto = try IOSProtos_BackupSnapshot.BackupEntity(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: IOSProtos_BackupSnapshot.BackupEntity) throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
||||
var type: SignalIOSProtoBackupSnapshotBackupEntityType = .unknown
|
||||
if proto.hasType {
|
||||
type = SignalIOSProtoBackupSnapshotBackupEntityTypeWrap(proto.type)
|
||||
}
|
||||
|
||||
var entityData: Data? = nil
|
||||
if proto.hasEntityData {
|
||||
entityData = proto.entityData
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity -
|
||||
|
||||
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity -
|
||||
|
||||
let result = SignalIOSProtoBackupSnapshotBackupEntity(type: type,
|
||||
entityData: entityData)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: IOSProtos_BackupSnapshot.BackupEntity {
|
||||
let proto = IOSProtos_BackupSnapshot.BackupEntity.with { (builder) in
|
||||
builder.type = SignalIOSProtoBackupSnapshotBackupEntity.SignalIOSProtoBackupSnapshotBackupEntityTypeUnwrap(self.type)
|
||||
|
||||
if let entityData = self.entityData {
|
||||
builder.entityData = entityData
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SignalIOSProtoBackupSnapshot
|
||||
|
||||
@objc public class SignalIOSProtoBackupSnapshot: NSObject {
|
||||
|
||||
@objc public let entity: [SignalIOSProtoBackupSnapshotBackupEntity]
|
||||
|
||||
@objc public init(entity: [SignalIOSProtoBackupSnapshotBackupEntity]) {
|
||||
self.entity = entity
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshot {
|
||||
let proto = try IOSProtos_BackupSnapshot(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: IOSProtos_BackupSnapshot) throws -> SignalIOSProtoBackupSnapshot {
|
||||
var entity: [SignalIOSProtoBackupSnapshotBackupEntity] = []
|
||||
for item in proto.entity {
|
||||
let wrapped = try SignalIOSProtoBackupSnapshotBackupEntity.parseProto(item)
|
||||
entity.append(wrapped)
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for SignalIOSProtoBackupSnapshot -
|
||||
|
||||
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshot -
|
||||
|
||||
let result = SignalIOSProtoBackupSnapshot(entity: entity)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: IOSProtos_BackupSnapshot {
|
||||
let proto = IOSProtos_BackupSnapshot.with { (builder) in
|
||||
var entityUnwrapped = [IOSProtos_BackupSnapshot.BackupEntity]()
|
||||
for item in entity {
|
||||
entityUnwrapped.append(item.asProtobuf)
|
||||
}
|
||||
builder.entity = entityUnwrapped
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// WARNING: This code is generated. Only edit within the markers.
|
||||
|
||||
public enum WebSocketProtoError: Error {
|
||||
case invalidProtobuf(description: String)
|
||||
}
|
||||
|
||||
// MARK: - WebSocketProtoWebSocketRequestMessage
|
||||
|
||||
@objc public class WebSocketProtoWebSocketRequestMessage: NSObject {
|
||||
|
||||
@objc public let verb: String?
|
||||
@objc public let path: String?
|
||||
@objc public let body: Data?
|
||||
@objc public let headers: [String]
|
||||
@objc public let requestId: UInt64
|
||||
|
||||
@objc public init(verb: String?,
|
||||
path: String?,
|
||||
body: Data?,
|
||||
headers: [String],
|
||||
requestId: UInt64) {
|
||||
self.verb = verb
|
||||
self.path = path
|
||||
self.body = body
|
||||
self.headers = headers
|
||||
self.requestId = requestId
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketRequestMessage {
|
||||
let proto = try WebSocketProtos_WebSocketRequestMessage(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketRequestMessage) throws -> WebSocketProtoWebSocketRequestMessage {
|
||||
var verb: String? = nil
|
||||
if proto.hasVerb {
|
||||
verb = proto.verb
|
||||
}
|
||||
|
||||
var path: String? = nil
|
||||
if proto.hasPath {
|
||||
path = proto.path
|
||||
}
|
||||
|
||||
var body: Data? = nil
|
||||
if proto.hasBody {
|
||||
body = proto.body
|
||||
}
|
||||
|
||||
var headers: [String] = []
|
||||
for item in proto.headers {
|
||||
let wrapped = item
|
||||
headers.append(wrapped)
|
||||
}
|
||||
|
||||
var requestId: UInt64 = 0
|
||||
if proto.hasRequestId {
|
||||
requestId = proto.requestId
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for WebSocketProtoWebSocketRequestMessage -
|
||||
|
||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketRequestMessage -
|
||||
|
||||
let result = WebSocketProtoWebSocketRequestMessage(verb: verb,
|
||||
path: path,
|
||||
body: body,
|
||||
headers: headers,
|
||||
requestId: requestId)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: WebSocketProtos_WebSocketRequestMessage {
|
||||
let proto = WebSocketProtos_WebSocketRequestMessage.with { (builder) in
|
||||
if let verb = self.verb {
|
||||
builder.verb = verb
|
||||
}
|
||||
|
||||
if let path = self.path {
|
||||
builder.path = path
|
||||
}
|
||||
|
||||
if let body = self.body {
|
||||
builder.body = body
|
||||
}
|
||||
|
||||
var headersUnwrapped = [String]()
|
||||
for item in headers {
|
||||
headersUnwrapped.append(item)
|
||||
}
|
||||
builder.headers = headersUnwrapped
|
||||
|
||||
builder.requestId = self.requestId
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - WebSocketProtoWebSocketResponseMessage
|
||||
|
||||
@objc public class WebSocketProtoWebSocketResponseMessage: NSObject {
|
||||
|
||||
@objc public let requestId: UInt64
|
||||
@objc public let status: UInt32
|
||||
@objc public let message: String?
|
||||
@objc public let headers: [String]
|
||||
@objc public let body: Data?
|
||||
|
||||
@objc public init(requestId: UInt64,
|
||||
status: UInt32,
|
||||
message: String?,
|
||||
headers: [String],
|
||||
body: Data?) {
|
||||
self.requestId = requestId
|
||||
self.status = status
|
||||
self.message = message
|
||||
self.headers = headers
|
||||
self.body = body
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketResponseMessage {
|
||||
let proto = try WebSocketProtos_WebSocketResponseMessage(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketResponseMessage) throws -> WebSocketProtoWebSocketResponseMessage {
|
||||
var requestId: UInt64 = 0
|
||||
if proto.hasRequestId {
|
||||
requestId = proto.requestId
|
||||
}
|
||||
|
||||
var status: UInt32 = 0
|
||||
if proto.hasStatus {
|
||||
status = proto.status
|
||||
}
|
||||
|
||||
var message: String? = nil
|
||||
if proto.hasMessage {
|
||||
message = proto.message
|
||||
}
|
||||
|
||||
var headers: [String] = []
|
||||
for item in proto.headers {
|
||||
let wrapped = item
|
||||
headers.append(wrapped)
|
||||
}
|
||||
|
||||
var body: Data? = nil
|
||||
if proto.hasBody {
|
||||
body = proto.body
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for WebSocketProtoWebSocketResponseMessage -
|
||||
|
||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketResponseMessage -
|
||||
|
||||
let result = WebSocketProtoWebSocketResponseMessage(requestId: requestId,
|
||||
status: status,
|
||||
message: message,
|
||||
headers: headers,
|
||||
body: body)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: WebSocketProtos_WebSocketResponseMessage {
|
||||
let proto = WebSocketProtos_WebSocketResponseMessage.with { (builder) in
|
||||
builder.requestId = self.requestId
|
||||
|
||||
builder.status = self.status
|
||||
|
||||
if let message = self.message {
|
||||
builder.message = message
|
||||
}
|
||||
|
||||
var headersUnwrapped = [String]()
|
||||
for item in headers {
|
||||
headersUnwrapped.append(item)
|
||||
}
|
||||
builder.headers = headersUnwrapped
|
||||
|
||||
if let body = self.body {
|
||||
builder.body = body
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - WebSocketProtoWebSocketMessage
|
||||
|
||||
@objc public class WebSocketProtoWebSocketMessage: NSObject {
|
||||
|
||||
// MARK: - WebSocketProtoWebSocketMessageType
|
||||
|
||||
@objc public enum WebSocketProtoWebSocketMessageType: Int32 {
|
||||
case unknown = 0
|
||||
case request = 1
|
||||
case response = 2
|
||||
}
|
||||
|
||||
private class func WebSocketProtoWebSocketMessageTypeWrap(_ value: WebSocketProtos_WebSocketMessage.TypeEnum) -> WebSocketProtoWebSocketMessageType {
|
||||
switch value {
|
||||
case .unknown: return .unknown
|
||||
case .request: return .request
|
||||
case .response: return .response
|
||||
}
|
||||
}
|
||||
|
||||
private class func WebSocketProtoWebSocketMessageTypeUnwrap(_ value: WebSocketProtoWebSocketMessageType) -> WebSocketProtos_WebSocketMessage.TypeEnum {
|
||||
switch value {
|
||||
case .unknown: return .unknown
|
||||
case .request: return .request
|
||||
case .response: return .response
|
||||
}
|
||||
}
|
||||
|
||||
@objc public let type: WebSocketProtoWebSocketMessageType
|
||||
@objc public let request: WebSocketProtoWebSocketRequestMessage?
|
||||
@objc public let response: WebSocketProtoWebSocketResponseMessage?
|
||||
|
||||
@objc public init(type: WebSocketProtoWebSocketMessageType,
|
||||
request: WebSocketProtoWebSocketRequestMessage?,
|
||||
response: WebSocketProtoWebSocketResponseMessage?) {
|
||||
self.type = type
|
||||
self.request = request
|
||||
self.response = response
|
||||
}
|
||||
|
||||
@objc
|
||||
public func serializedData() throws -> Data {
|
||||
return try self.asProtobuf.serializedData()
|
||||
}
|
||||
|
||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketMessage {
|
||||
let proto = try WebSocketProtos_WebSocketMessage(serializedData: serializedData)
|
||||
return try parseProto(proto)
|
||||
}
|
||||
|
||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketMessage) throws -> WebSocketProtoWebSocketMessage {
|
||||
var type: WebSocketProtoWebSocketMessageType = .unknown
|
||||
if proto.hasType {
|
||||
type = WebSocketProtoWebSocketMessageTypeWrap(proto.type)
|
||||
}
|
||||
|
||||
var request: WebSocketProtoWebSocketRequestMessage? = nil
|
||||
if proto.hasRequest {
|
||||
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
|
||||
}
|
||||
|
||||
var response: WebSocketProtoWebSocketResponseMessage? = nil
|
||||
if proto.hasResponse {
|
||||
response = try WebSocketProtoWebSocketResponseMessage.parseProto(proto.response)
|
||||
}
|
||||
|
||||
// MARK: - Begin Validation Logic for WebSocketProtoWebSocketMessage -
|
||||
|
||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketMessage -
|
||||
|
||||
let result = WebSocketProtoWebSocketMessage(type: type,
|
||||
request: request,
|
||||
response: response)
|
||||
return result
|
||||
}
|
||||
|
||||
fileprivate var asProtobuf: WebSocketProtos_WebSocketMessage {
|
||||
let proto = WebSocketProtos_WebSocketMessage.with { (builder) in
|
||||
builder.type = WebSocketProtoWebSocketMessage.WebSocketProtoWebSocketMessageTypeUnwrap(self.type)
|
||||
|
||||
if let request = self.request {
|
||||
builder.request = request.asProtobuf
|
||||
}
|
||||
|
||||
if let response = self.response {
|
||||
builder.response = response.asProtobuf
|
||||
}
|
||||
}
|
||||
|
||||
return proto
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue