Swift proto parsing wrappers.

This commit is contained in:
Matthew Chen 2018-08-02 14:28:13 -04:00
parent 0d23b06cbc
commit e1eb58ba3b
4 changed files with 509 additions and 395 deletions

View File

@ -14,15 +14,43 @@ public enum FingerprintProtoError: Error {
@objc public class FingerprintProtoLogicalFingerprint: NSObject {
@objc public let identityData: Data?
// MARK: - FingerprintProtoLogicalFingerprintBuilder
@objc public init(identityData: Data?) {
self.identityData = identityData
@objc public class FingerprintProtoLogicalFingerprintBuilder: NSObject {
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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = FingerprintProtoLogicalFingerprint(proto: proto)
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
// 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 remoteFingerprint: FingerprintProtoLogicalFingerprint?
@objc public init(version: UInt32,
localFingerprint: FingerprintProtoLogicalFingerprint?,
remoteFingerprint: FingerprintProtoLogicalFingerprint?) {
self.version = version
@objc public var version: UInt32 {
return proto.version
}
@objc public var hasVersion: Bool {
return proto.hasVersion
}
private init(proto: FingerprintProtos_LogicalFingerprints,
localFingerprint: FingerprintProtoLogicalFingerprint?,
remoteFingerprint: FingerprintProtoLogicalFingerprint?) {
self.proto = proto
self.localFingerprint = localFingerprint
self.remoteFingerprint = remoteFingerprint
}
@objc
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
var version: UInt32 = 0
if proto.hasVersion {
version = proto.version
}
var localFingerprint: FingerprintProtoLogicalFingerprint? = nil
if proto.hasLocalFingerprint {
localFingerprint = try FingerprintProtoLogicalFingerprint.parseProto(proto.localFingerprint)
@ -101,25 +143,9 @@ public enum FingerprintProtoError: Error {
// MARK: - End Validation Logic for FingerprintProtoLogicalFingerprints -
let result = FingerprintProtoLogicalFingerprints(version: version,
let result = FingerprintProtoLogicalFingerprints(proto: proto,
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
}
}

View File

@ -14,18 +14,57 @@ public enum ProvisioningProtoError: Error {
@objc public class ProvisioningProtoProvisionEnvelope: NSObject {
@objc public let publicKey: Data?
@objc public let body: Data?
// MARK: - ProvisioningProtoProvisionEnvelopeBuilder
@objc public init(publicKey: Data?,
body: Data?) {
self.publicKey = publicKey
self.body = body
@objc public class ProvisioningProtoProvisionEnvelopeBuilder: NSObject {
private var proto = ProvisioningProtos_ProvisionEnvelope()
@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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = ProvisioningProtoProvisionEnvelope(proto: proto)
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
// MARK: - ProvisioningProtoProvisionMessageBuilder
@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 class ProvisioningProtoProvisionMessageBuilder: NSObject {
private var proto = ProvisioningProtos_ProvisionMessage()
@objc public override init() {}
@objc public func setIdentityKeyPublic(_ valueParam: Data) {
proto.identityKeyPublic = valueParam
}
@objc public func setIdentityKeyPrivate(_ valueParam: Data) {
proto.identityKeyPrivate = valueParam
}
@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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = ProvisioningProtoProvisionMessage(proto: proto)
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
}
}

View File

@ -44,18 +44,54 @@ public enum SignalIOSProtoError: Error {
}
}
@objc public let type: SignalIOSProtoBackupSnapshotBackupEntityType
@objc public let entityData: Data?
// MARK: - SignalIOSProtoBackupSnapshotBackupEntityBuilder
@objc public init(type: SignalIOSProtoBackupSnapshotBackupEntityType,
entityData: Data?) {
self.type = type
self.entityData = entityData
@objc public class SignalIOSProtoBackupSnapshotBackupEntityBuilder: NSObject {
private var proto = IOSProtos_BackupSnapshot.BackupEntity()
@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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = SignalIOSProtoBackupSnapshotBackupEntity(proto: proto)
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 {
// 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 init(entity: [SignalIOSProtoBackupSnapshotBackupEntity]) {
private init(proto: IOSProtos_BackupSnapshot,
entity: [SignalIOSProtoBackupSnapshotBackupEntity]) {
self.proto = proto
self.entity = entity
}
@objc
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@objc public class func parseData(_ serializedData: Data) throws -> SignalIOSProtoBackupSnapshot {
@ -127,19 +164,8 @@ public enum SignalIOSProtoError: Error {
// MARK: - End Validation Logic for SignalIOSProtoBackupSnapshot -
let result = SignalIOSProtoBackupSnapshot(entity: entity)
let result = SignalIOSProtoBackupSnapshot(proto: proto,
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
}
}

View File

@ -14,27 +14,92 @@ public enum WebSocketProtoError: Error {
@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
// MARK: - WebSocketProtoWebSocketRequestMessageBuilder
@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 class WebSocketProtoWebSocketRequestMessageBuilder: NSObject {
private var proto = WebSocketProtos_WebSocketRequestMessage()
@objc public override init() {}
@objc public func setVerb(_ valueParam: String) {
proto.verb = valueParam
}
@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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = WebSocketProtoWebSocketRequestMessage(proto: proto)
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?
// MARK: - WebSocketProtoWebSocketResponseMessageBuilder
@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 class WebSocketProtoWebSocketResponseMessageBuilder: NSObject {
private var proto = WebSocketProtos_WebSocketResponseMessage()
@objc public override init() {}
@objc public func setRequestId(_ valueParam: UInt64) {
proto.requestId = valueParam
}
@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
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
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)
let result = WebSocketProtoWebSocketResponseMessage(proto: proto)
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
@ -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 response: WebSocketProtoWebSocketResponseMessage?
@objc public init(type: WebSocketProtoWebSocketMessageType,
request: WebSocketProtoWebSocketRequestMessage?,
response: WebSocketProtoWebSocketResponseMessage?) {
self.type = type
@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?,
response: WebSocketProtoWebSocketResponseMessage?) {
self.proto = proto
self.request = request
self.response = response
}
@objc
public func serializedData() throws -> Data {
return try self.asProtobuf.serializedData()
return try self.proto.serializedData()
}
@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 {
var type: WebSocketProtoWebSocketMessageType = .unknown
if proto.hasType {
type = WebSocketProtoWebSocketMessageTypeWrap(proto.type)
}
var request: WebSocketProtoWebSocketRequestMessage? = nil
if proto.hasRequest {
request = try WebSocketProtoWebSocketRequestMessage.parseProto(proto.request)
@ -274,25 +320,9 @@ public enum WebSocketProtoError: Error {
// MARK: - End Validation Logic for WebSocketProtoWebSocketMessage -
let result = WebSocketProtoWebSocketMessage(type: type,
let result = WebSocketProtoWebSocketMessage(proto: proto,
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
}
}