mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Swift proto parsing wrappers.
This commit is contained in:
parent
0d23b06cbc
commit
e1eb58ba3b
4 changed files with 509 additions and 395 deletions
|
@ -14,15 +14,43 @@ public enum FingerprintProtoError: Error {
|
||||||
|
|
||||||
@objc public class FingerprintProtoLogicalFingerprint: NSObject {
|
@objc public class FingerprintProtoLogicalFingerprint: NSObject {
|
||||||
|
|
||||||
@objc public let identityData: Data?
|
// MARK: - FingerprintProtoLogicalFingerprintBuilder
|
||||||
|
|
||||||
@objc public init(identityData: Data?) {
|
@objc public class FingerprintProtoLogicalFingerprintBuilder: NSObject {
|
||||||
self.identityData = identityData
|
|
||||||
|
private var proto = FingerprintProtos_LogicalFingerprint()
|
||||||
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func setIdentityData(_ valueParam: Data) {
|
||||||
|
proto.identityData = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> FingerprintProtoLogicalFingerprint {
|
||||||
|
let wrapper = try FingerprintProtoLogicalFingerprint.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: FingerprintProtos_LogicalFingerprint
|
||||||
|
|
||||||
|
@objc public var identityData: Data? {
|
||||||
|
guard proto.hasIdentityData else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.identityData
|
||||||
|
}
|
||||||
|
@objc public var hasIdentityData: Bool {
|
||||||
|
return proto.hasIdentityData
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: FingerprintProtos_LogicalFingerprint) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprint {
|
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprint {
|
||||||
|
@ -31,49 +59,68 @@ public enum FingerprintProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprint) throws -> FingerprintProtoLogicalFingerprint {
|
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: - Begin Validation Logic for FingerprintProtoLogicalFingerprint -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprint -
|
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprint -
|
||||||
|
|
||||||
let result = FingerprintProtoLogicalFingerprint(identityData: identityData)
|
let result = FingerprintProtoLogicalFingerprint(proto: proto)
|
||||||
return result
|
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
|
// MARK: - FingerprintProtoLogicalFingerprints
|
||||||
|
|
||||||
@objc public class FingerprintProtoLogicalFingerprints: NSObject {
|
@objc public class FingerprintProtoLogicalFingerprints: NSObject {
|
||||||
|
|
||||||
@objc public let version: UInt32
|
// MARK: - FingerprintProtoLogicalFingerprintsBuilder
|
||||||
|
|
||||||
|
@objc public class FingerprintProtoLogicalFingerprintsBuilder: NSObject {
|
||||||
|
|
||||||
|
private var proto = FingerprintProtos_LogicalFingerprints()
|
||||||
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func setVersion(_ valueParam: UInt32) {
|
||||||
|
proto.version = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setLocalFingerprint(_ valueParam: FingerprintProtoLogicalFingerprint) {
|
||||||
|
proto.localFingerprint = valueParam.proto
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setRemoteFingerprint(_ valueParam: FingerprintProtoLogicalFingerprint) {
|
||||||
|
proto.remoteFingerprint = valueParam.proto
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> FingerprintProtoLogicalFingerprints {
|
||||||
|
let wrapper = try FingerprintProtoLogicalFingerprints.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: FingerprintProtos_LogicalFingerprints
|
||||||
|
|
||||||
@objc public let localFingerprint: FingerprintProtoLogicalFingerprint?
|
@objc public let localFingerprint: FingerprintProtoLogicalFingerprint?
|
||||||
@objc public let remoteFingerprint: FingerprintProtoLogicalFingerprint?
|
@objc public let remoteFingerprint: FingerprintProtoLogicalFingerprint?
|
||||||
|
|
||||||
@objc public init(version: UInt32,
|
@objc public var version: UInt32 {
|
||||||
|
return proto.version
|
||||||
|
}
|
||||||
|
@objc public var hasVersion: Bool {
|
||||||
|
return proto.hasVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: FingerprintProtos_LogicalFingerprints,
|
||||||
localFingerprint: FingerprintProtoLogicalFingerprint?,
|
localFingerprint: FingerprintProtoLogicalFingerprint?,
|
||||||
remoteFingerprint: FingerprintProtoLogicalFingerprint?) {
|
remoteFingerprint: FingerprintProtoLogicalFingerprint?) {
|
||||||
self.version = version
|
self.proto = proto
|
||||||
self.localFingerprint = localFingerprint
|
self.localFingerprint = localFingerprint
|
||||||
self.remoteFingerprint = remoteFingerprint
|
self.remoteFingerprint = remoteFingerprint
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprints {
|
@objc public class func parseData(_ serializedData: Data) throws -> FingerprintProtoLogicalFingerprints {
|
||||||
|
@ -82,11 +129,6 @@ public enum FingerprintProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprints) throws -> FingerprintProtoLogicalFingerprints {
|
fileprivate class func parseProto(_ proto: FingerprintProtos_LogicalFingerprints) throws -> FingerprintProtoLogicalFingerprints {
|
||||||
var version: UInt32 = 0
|
|
||||||
if proto.hasVersion {
|
|
||||||
version = proto.version
|
|
||||||
}
|
|
||||||
|
|
||||||
var localFingerprint: FingerprintProtoLogicalFingerprint? = nil
|
var localFingerprint: FingerprintProtoLogicalFingerprint? = nil
|
||||||
if proto.hasLocalFingerprint {
|
if proto.hasLocalFingerprint {
|
||||||
localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint)
|
localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint)
|
||||||
|
@ -101,25 +143,9 @@ public enum FingerprintProtoError: Error {
|
||||||
|
|
||||||
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprints -
|
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprints -
|
||||||
|
|
||||||
let result = FingerprintProtoLogicalFingerprints(version: version,
|
let result = FingerprintProtoLogicalFingerprints(proto: proto,
|
||||||
localFingerprint: localFingerprint,
|
localFingerprint: localFingerprint,
|
||||||
remoteFingerprint: remoteFingerprint)
|
remoteFingerprint: remoteFingerprint)
|
||||||
return result
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,57 @@ public enum ProvisioningProtoError: Error {
|
||||||
|
|
||||||
@objc public class ProvisioningProtoProvisionEnvelope: NSObject {
|
@objc public class ProvisioningProtoProvisionEnvelope: NSObject {
|
||||||
|
|
||||||
@objc public let publicKey: Data?
|
// MARK: - ProvisioningProtoProvisionEnvelopeBuilder
|
||||||
@objc public let body: Data?
|
|
||||||
|
|
||||||
@objc public init(publicKey: Data?,
|
@objc public class ProvisioningProtoProvisionEnvelopeBuilder: NSObject {
|
||||||
body: Data?) {
|
|
||||||
self.publicKey = publicKey
|
private var proto = ProvisioningProtos_ProvisionEnvelope()
|
||||||
self.body = body
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func setPublicKey(_ valueParam: Data) {
|
||||||
|
proto.publicKey = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setBody(_ valueParam: Data) {
|
||||||
|
proto.body = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> ProvisioningProtoProvisionEnvelope {
|
||||||
|
let wrapper = try ProvisioningProtoProvisionEnvelope.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: ProvisioningProtos_ProvisionEnvelope
|
||||||
|
|
||||||
|
@objc public var publicKey: Data? {
|
||||||
|
guard proto.hasPublicKey else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.publicKey
|
||||||
|
}
|
||||||
|
@objc public var hasPublicKey: Bool {
|
||||||
|
return proto.hasPublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var body: Data? {
|
||||||
|
guard proto.hasBody else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.body
|
||||||
|
}
|
||||||
|
@objc public var hasBody: Bool {
|
||||||
|
return proto.hasBody
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: ProvisioningProtos_ProvisionEnvelope) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionEnvelope {
|
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionEnvelope {
|
||||||
|
@ -34,71 +73,137 @@ public enum ProvisioningProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionEnvelope) throws -> ProvisioningProtoProvisionEnvelope {
|
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: - Begin Validation Logic for ProvisioningProtoProvisionEnvelope -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for ProvisioningProtoProvisionEnvelope -
|
// MARK: - End Validation Logic for ProvisioningProtoProvisionEnvelope -
|
||||||
|
|
||||||
let result = ProvisioningProtoProvisionEnvelope(publicKey: publicKey,
|
let result = ProvisioningProtoProvisionEnvelope(proto: proto)
|
||||||
body: body)
|
|
||||||
return result
|
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
|
// MARK: - ProvisioningProtoProvisionMessage
|
||||||
|
|
||||||
@objc public class ProvisioningProtoProvisionMessage: NSObject {
|
@objc public class ProvisioningProtoProvisionMessage: NSObject {
|
||||||
|
|
||||||
@objc public let identityKeyPublic: Data?
|
// MARK: - ProvisioningProtoProvisionMessageBuilder
|
||||||
@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?,
|
@objc public class ProvisioningProtoProvisionMessageBuilder: NSObject {
|
||||||
identityKeyPrivate: Data?,
|
|
||||||
number: String?,
|
private var proto = ProvisioningProtos_ProvisionMessage()
|
||||||
provisioningCode: String?,
|
|
||||||
userAgent: String?,
|
@objc public override init() {}
|
||||||
profileKey: Data?,
|
|
||||||
readReceipts: Bool) {
|
@objc public func setIdentityKeyPublic(_ valueParam: Data) {
|
||||||
self.identityKeyPublic = identityKeyPublic
|
proto.identityKeyPublic = valueParam
|
||||||
self.identityKeyPrivate = identityKeyPrivate
|
}
|
||||||
self.number = number
|
|
||||||
self.provisioningCode = provisioningCode
|
@objc public func setIdentityKeyPrivate(_ valueParam: Data) {
|
||||||
self.userAgent = userAgent
|
proto.identityKeyPrivate = valueParam
|
||||||
self.profileKey = profileKey
|
}
|
||||||
self.readReceipts = readReceipts
|
|
||||||
|
@objc public func setNumber(_ valueParam: String) {
|
||||||
|
proto.number = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setProvisioningCode(_ valueParam: String) {
|
||||||
|
proto.provisioningCode = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setUserAgent(_ valueParam: String) {
|
||||||
|
proto.userAgent = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setProfileKey(_ valueParam: Data) {
|
||||||
|
proto.profileKey = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setReadReceipts(_ valueParam: Bool) {
|
||||||
|
proto.readReceipts = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> ProvisioningProtoProvisionMessage {
|
||||||
|
let wrapper = try ProvisioningProtoProvisionMessage.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: ProvisioningProtos_ProvisionMessage
|
||||||
|
|
||||||
|
@objc public var identityKeyPublic: Data? {
|
||||||
|
guard proto.hasIdentityKeyPublic else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.identityKeyPublic
|
||||||
|
}
|
||||||
|
@objc public var hasIdentityKeyPublic: Bool {
|
||||||
|
return proto.hasIdentityKeyPublic
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var identityKeyPrivate: Data? {
|
||||||
|
guard proto.hasIdentityKeyPrivate else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.identityKeyPrivate
|
||||||
|
}
|
||||||
|
@objc public var hasIdentityKeyPrivate: Bool {
|
||||||
|
return proto.hasIdentityKeyPrivate
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var number: String? {
|
||||||
|
guard proto.hasNumber else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.number
|
||||||
|
}
|
||||||
|
@objc public var hasNumber: Bool {
|
||||||
|
return proto.hasNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var provisioningCode: String? {
|
||||||
|
guard proto.hasProvisioningCode else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.provisioningCode
|
||||||
|
}
|
||||||
|
@objc public var hasProvisioningCode: Bool {
|
||||||
|
return proto.hasProvisioningCode
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var userAgent: String? {
|
||||||
|
guard proto.hasUserAgent else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.userAgent
|
||||||
|
}
|
||||||
|
@objc public var hasUserAgent: Bool {
|
||||||
|
return proto.hasUserAgent
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var profileKey: Data? {
|
||||||
|
guard proto.hasProfileKey else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.profileKey
|
||||||
|
}
|
||||||
|
@objc public var hasProfileKey: Bool {
|
||||||
|
return proto.hasProfileKey
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var readReceipts: Bool {
|
||||||
|
return proto.readReceipts
|
||||||
|
}
|
||||||
|
@objc public var hasReadReceipts: Bool {
|
||||||
|
return proto.hasReadReceipts
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: ProvisioningProtos_ProvisionMessage) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionMessage {
|
@objc public class func parseData(_ serializedData: Data) throws -> ProvisioningProtoProvisionMessage {
|
||||||
|
@ -107,84 +212,11 @@ public enum ProvisioningProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: ProvisioningProtos_ProvisionMessage) throws -> ProvisioningProtoProvisionMessage {
|
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: - Begin Validation Logic for ProvisioningProtoProvisionMessage -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for ProvisioningProtoProvisionMessage -
|
// MARK: - End Validation Logic for ProvisioningProtoProvisionMessage -
|
||||||
|
|
||||||
let result = ProvisioningProtoProvisionMessage(identityKeyPublic: identityKeyPublic,
|
let result = ProvisioningProtoProvisionMessage(proto: proto)
|
||||||
identityKeyPrivate: identityKeyPrivate,
|
|
||||||
number: number,
|
|
||||||
provisioningCode: provisioningCode,
|
|
||||||
userAgent: userAgent,
|
|
||||||
profileKey: profileKey,
|
|
||||||
readReceipts: readReceipts)
|
|
||||||
return result
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,18 +44,54 @@ public enum SignalIOSProtoError: Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public let type: SignalIOSProtoBackupSnapshotBackupEntityType
|
// MARK: - SignalIOSProtoBackupSnapshotBackupEntityBuilder
|
||||||
@objc public let entityData: Data?
|
|
||||||
|
|
||||||
@objc public init(type: SignalIOSProtoBackupSnapshotBackupEntityType,
|
@objc public class SignalIOSProtoBackupSnapshotBackupEntityBuilder: NSObject {
|
||||||
entityData: Data?) {
|
|
||||||
self.type = type
|
private var proto = IOSProtos_BackupSnapshot.BackupEntity()
|
||||||
self.entityData = entityData
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func setType(_ valueParam: SignalIOSProtoBackupSnapshotBackupEntityType) {
|
||||||
|
proto.type = SignalIOSProtoBackupSnapshotBackupEntityTypeUnwrap(valueParam)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setEntityData(_ valueParam: Data) {
|
||||||
|
proto.entityData = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
||||||
|
let wrapper = try SignalIOSProtoBackupSnapshotBackupEntity.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: IOSProtos_BackupSnapshot.BackupEntity
|
||||||
|
|
||||||
|
@objc public var type: SignalIOSProtoBackupSnapshotBackupEntityType {
|
||||||
|
return SignalIOSProtoBackupSnapshotBackupEntity.SignalIOSProtoBackupSnapshotBackupEntityTypeWrap(proto.type)
|
||||||
|
}
|
||||||
|
@objc public var hasType: Bool {
|
||||||
|
return proto.hasType
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var entityData: Data? {
|
||||||
|
guard proto.hasEntityData else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.entityData
|
||||||
|
}
|
||||||
|
@objc public var hasEntityData: Bool {
|
||||||
|
return proto.hasEntityData
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: IOSProtos_BackupSnapshot.BackupEntity) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
||||||
|
@ -64,51 +100,52 @@ public enum SignalIOSProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: IOSProtos_BackupSnapshot.BackupEntity) throws -> SignalIOSProtoBackupSnapshotBackupEntity {
|
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: - Begin Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity -
|
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshotBackupEntity -
|
||||||
|
|
||||||
let result = SignalIOSProtoBackupSnapshotBackupEntity(type: type,
|
let result = SignalIOSProtoBackupSnapshotBackupEntity(proto: proto)
|
||||||
entityData: entityData)
|
|
||||||
return result
|
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
|
// MARK: - SignalIOSProtoBackupSnapshot
|
||||||
|
|
||||||
@objc public class SignalIOSProtoBackupSnapshot: NSObject {
|
@objc public class SignalIOSProtoBackupSnapshot: NSObject {
|
||||||
|
|
||||||
|
// MARK: - SignalIOSProtoBackupSnapshotBuilder
|
||||||
|
|
||||||
|
@objc public class SignalIOSProtoBackupSnapshotBuilder: NSObject {
|
||||||
|
|
||||||
|
private var proto = IOSProtos_BackupSnapshot()
|
||||||
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func addEntity(_ valueParam: SignalIOSProtoBackupSnapshotBackupEntity) {
|
||||||
|
var items = proto.entity
|
||||||
|
items.append(valueParam.proto)
|
||||||
|
proto.entity = items
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> SignalIOSProtoBackupSnapshot {
|
||||||
|
let wrapper = try SignalIOSProtoBackupSnapshot.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: IOSProtos_BackupSnapshot
|
||||||
|
|
||||||
@objc public let entity: [SignalIOSProtoBackupSnapshotBackupEntity]
|
@objc public let entity: [SignalIOSProtoBackupSnapshotBackupEntity]
|
||||||
|
|
||||||
@objc public init(entity: [SignalIOSProtoBackupSnapshotBackupEntity]) {
|
private init(proto: IOSProtos_BackupSnapshot,
|
||||||
|
entity: [SignalIOSProtoBackupSnapshotBackupEntity]) {
|
||||||
|
self.proto = proto
|
||||||
self.entity = entity
|
self.entity = entity
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshot {
|
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshot {
|
||||||
|
@ -127,19 +164,8 @@ public enum SignalIOSProtoError: Error {
|
||||||
|
|
||||||
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshot -
|
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshot -
|
||||||
|
|
||||||
let result = SignalIOSProtoBackupSnapshot(entity: entity)
|
let result = SignalIOSProtoBackupSnapshot(proto: proto,
|
||||||
|
entity: entity)
|
||||||
return result
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,27 +14,92 @@ public enum WebSocketProtoError: Error {
|
||||||
|
|
||||||
@objc public class WebSocketProtoWebSocketRequestMessage: NSObject {
|
@objc public class WebSocketProtoWebSocketRequestMessage: NSObject {
|
||||||
|
|
||||||
@objc public let verb: String?
|
// MARK: - WebSocketProtoWebSocketRequestMessageBuilder
|
||||||
@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?,
|
@objc public class WebSocketProtoWebSocketRequestMessageBuilder: NSObject {
|
||||||
path: String?,
|
|
||||||
body: Data?,
|
private var proto = WebSocketProtos_WebSocketRequestMessage()
|
||||||
headers: [String],
|
|
||||||
requestId: UInt64) {
|
@objc public override init() {}
|
||||||
self.verb = verb
|
|
||||||
self.path = path
|
@objc public func setVerb(_ valueParam: String) {
|
||||||
self.body = body
|
proto.verb = valueParam
|
||||||
self.headers = headers
|
}
|
||||||
self.requestId = requestId
|
|
||||||
|
@objc public func setPath(_ valueParam: String) {
|
||||||
|
proto.path = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setBody(_ valueParam: Data) {
|
||||||
|
proto.body = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func addHeaders(_ valueParam: String) {
|
||||||
|
var items = proto.headers
|
||||||
|
items.append(valueParam)
|
||||||
|
proto.headers = items
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setRequestId(_ valueParam: UInt64) {
|
||||||
|
proto.requestId = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> WebSocketProtoWebSocketRequestMessage {
|
||||||
|
let wrapper = try WebSocketProtoWebSocketRequestMessage.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: WebSocketProtos_WebSocketRequestMessage
|
||||||
|
|
||||||
|
@objc public var verb: String? {
|
||||||
|
guard proto.hasVerb else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.verb
|
||||||
|
}
|
||||||
|
@objc public var hasVerb: Bool {
|
||||||
|
return proto.hasVerb
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var path: String? {
|
||||||
|
guard proto.hasPath else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.path
|
||||||
|
}
|
||||||
|
@objc public var hasPath: Bool {
|
||||||
|
return proto.hasPath
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var body: Data? {
|
||||||
|
guard proto.hasBody else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.body
|
||||||
|
}
|
||||||
|
@objc public var hasBody: Bool {
|
||||||
|
return proto.hasBody
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var headers: [String] {
|
||||||
|
return proto.headers
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var requestId: UInt64 {
|
||||||
|
return proto.requestId
|
||||||
|
}
|
||||||
|
@objc public var hasRequestId: Bool {
|
||||||
|
return proto.hasRequestId
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: WebSocketProtos_WebSocketRequestMessage) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketRequestMessage {
|
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketRequestMessage {
|
||||||
|
@ -43,96 +108,102 @@ public enum WebSocketProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketRequestMessage) throws -> WebSocketProtoWebSocketRequestMessage {
|
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: - Begin Validation Logic for WebSocketProtoWebSocketRequestMessage -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketRequestMessage -
|
// MARK: - End Validation Logic for WebSocketProtoWebSocketRequestMessage -
|
||||||
|
|
||||||
let result = WebSocketProtoWebSocketRequestMessage(verb: verb,
|
let result = WebSocketProtoWebSocketRequestMessage(proto: proto)
|
||||||
path: path,
|
|
||||||
body: body,
|
|
||||||
headers: headers,
|
|
||||||
requestId: requestId)
|
|
||||||
return result
|
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
|
// MARK: - WebSocketProtoWebSocketResponseMessage
|
||||||
|
|
||||||
@objc public class WebSocketProtoWebSocketResponseMessage: NSObject {
|
@objc public class WebSocketProtoWebSocketResponseMessage: NSObject {
|
||||||
|
|
||||||
@objc public let requestId: UInt64
|
// MARK: - WebSocketProtoWebSocketResponseMessageBuilder
|
||||||
@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,
|
@objc public class WebSocketProtoWebSocketResponseMessageBuilder: NSObject {
|
||||||
status: UInt32,
|
|
||||||
message: String?,
|
private var proto = WebSocketProtos_WebSocketResponseMessage()
|
||||||
headers: [String],
|
|
||||||
body: Data?) {
|
@objc public override init() {}
|
||||||
self.requestId = requestId
|
|
||||||
self.status = status
|
@objc public func setRequestId(_ valueParam: UInt64) {
|
||||||
self.message = message
|
proto.requestId = valueParam
|
||||||
self.headers = headers
|
}
|
||||||
self.body = body
|
|
||||||
|
@objc public func setStatus(_ valueParam: UInt32) {
|
||||||
|
proto.status = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setMessage(_ valueParam: String) {
|
||||||
|
proto.message = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func addHeaders(_ valueParam: String) {
|
||||||
|
var items = proto.headers
|
||||||
|
items.append(valueParam)
|
||||||
|
proto.headers = items
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setBody(_ valueParam: Data) {
|
||||||
|
proto.body = valueParam
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> WebSocketProtoWebSocketResponseMessage {
|
||||||
|
let wrapper = try WebSocketProtoWebSocketResponseMessage.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: WebSocketProtos_WebSocketResponseMessage
|
||||||
|
|
||||||
|
@objc public var requestId: UInt64 {
|
||||||
|
return proto.requestId
|
||||||
|
}
|
||||||
|
@objc public var hasRequestId: Bool {
|
||||||
|
return proto.hasRequestId
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var status: UInt32 {
|
||||||
|
return proto.status
|
||||||
|
}
|
||||||
|
@objc public var hasStatus: Bool {
|
||||||
|
return proto.hasStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var message: String? {
|
||||||
|
guard proto.hasMessage else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.message
|
||||||
|
}
|
||||||
|
@objc public var hasMessage: Bool {
|
||||||
|
return proto.hasMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var headers: [String] {
|
||||||
|
return proto.headers
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var body: Data? {
|
||||||
|
guard proto.hasBody else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return proto.body
|
||||||
|
}
|
||||||
|
@objc public var hasBody: Bool {
|
||||||
|
return proto.hasBody
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: WebSocketProtos_WebSocketResponseMessage) {
|
||||||
|
self.proto = proto
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketResponseMessage {
|
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketResponseMessage {
|
||||||
|
@ -141,67 +212,13 @@ public enum WebSocketProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketResponseMessage) throws -> WebSocketProtoWebSocketResponseMessage {
|
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: - Begin Validation Logic for WebSocketProtoWebSocketResponseMessage -
|
||||||
|
|
||||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketResponseMessage -
|
// MARK: - End Validation Logic for WebSocketProtoWebSocketResponseMessage -
|
||||||
|
|
||||||
let result = WebSocketProtoWebSocketResponseMessage(requestId: requestId,
|
let result = WebSocketProtoWebSocketResponseMessage(proto: proto)
|
||||||
status: status,
|
|
||||||
message: message,
|
|
||||||
headers: headers,
|
|
||||||
body: body)
|
|
||||||
return result
|
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
|
// MARK: - WebSocketProtoWebSocketMessage
|
||||||
|
@ -232,21 +249,55 @@ public enum WebSocketProtoError: Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public let type: WebSocketProtoWebSocketMessageType
|
// MARK: - WebSocketProtoWebSocketMessageBuilder
|
||||||
|
|
||||||
|
@objc public class WebSocketProtoWebSocketMessageBuilder: NSObject {
|
||||||
|
|
||||||
|
private var proto = WebSocketProtos_WebSocketMessage()
|
||||||
|
|
||||||
|
@objc public override init() {}
|
||||||
|
|
||||||
|
@objc public func setType(_ valueParam: WebSocketProtoWebSocketMessageType) {
|
||||||
|
proto.type = WebSocketProtoWebSocketMessageTypeUnwrap(valueParam)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setRequest(_ valueParam: WebSocketProtoWebSocketRequestMessage) {
|
||||||
|
proto.request = valueParam.proto
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func setResponse(_ valueParam: WebSocketProtoWebSocketResponseMessage) {
|
||||||
|
proto.response = valueParam.proto
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public func build() throws -> WebSocketProtoWebSocketMessage {
|
||||||
|
let wrapper = try WebSocketProtoWebSocketMessage.parseProto(proto)
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate let proto: WebSocketProtos_WebSocketMessage
|
||||||
|
|
||||||
@objc public let request: WebSocketProtoWebSocketRequestMessage?
|
@objc public let request: WebSocketProtoWebSocketRequestMessage?
|
||||||
@objc public let response: WebSocketProtoWebSocketResponseMessage?
|
@objc public let response: WebSocketProtoWebSocketResponseMessage?
|
||||||
|
|
||||||
@objc public init(type: WebSocketProtoWebSocketMessageType,
|
@objc public var type: WebSocketProtoWebSocketMessageType {
|
||||||
|
return WebSocketProtoWebSocketMessage.WebSocketProtoWebSocketMessageTypeWrap(proto.type)
|
||||||
|
}
|
||||||
|
@objc public var hasType: Bool {
|
||||||
|
return proto.hasType
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(proto: WebSocketProtos_WebSocketMessage,
|
||||||
request: WebSocketProtoWebSocketRequestMessage?,
|
request: WebSocketProtoWebSocketRequestMessage?,
|
||||||
response: WebSocketProtoWebSocketResponseMessage?) {
|
response: WebSocketProtoWebSocketResponseMessage?) {
|
||||||
self.type = type
|
self.proto = proto
|
||||||
self.request = request
|
self.request = request
|
||||||
self.response = response
|
self.response = response
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public func serializedData() throws -> Data {
|
public func serializedData() throws -> Data {
|
||||||
return try self.asProtobuf.serializedData()
|
return try self.proto.serializedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketMessage {
|
@objc public class func parseData(_ serializedData: Data) throws -> WebSocketProtoWebSocketMessage {
|
||||||
|
@ -255,11 +306,6 @@ public enum WebSocketProtoError: Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketMessage) throws -> WebSocketProtoWebSocketMessage {
|
fileprivate class func parseProto(_ proto: WebSocketProtos_WebSocketMessage) throws -> WebSocketProtoWebSocketMessage {
|
||||||
var type: WebSocketProtoWebSocketMessageType = .unknown
|
|
||||||
if proto.hasType {
|
|
||||||
type = WebSocketProtoWebSocketMessageTypeWrap(proto.type)
|
|
||||||
}
|
|
||||||
|
|
||||||
var request: WebSocketProtoWebSocketRequestMessage? = nil
|
var request: WebSocketProtoWebSocketRequestMessage? = nil
|
||||||
if proto.hasRequest {
|
if proto.hasRequest {
|
||||||
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
|
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
|
||||||
|
@ -274,25 +320,9 @@ public enum WebSocketProtoError: Error {
|
||||||
|
|
||||||
// MARK: - End Validation Logic for WebSocketProtoWebSocketMessage -
|
// MARK: - End Validation Logic for WebSocketProtoWebSocketMessage -
|
||||||
|
|
||||||
let result = WebSocketProtoWebSocketMessage(type: type,
|
let result = WebSocketProtoWebSocketMessage(proto: proto,
|
||||||
request: request,
|
request: request,
|
||||||
response: response)
|
response: response)
|
||||||
return result
|
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 a new issue