Christian Risi 8ae58929b0 V0.6.9.a Arroyo Toad
Fixed package visibility
2024-12-08 15:51:42 +00:00

98 lines
3.3 KiB
Swift

import Foundation
public struct Message: MessageP {
public let version: UInt8
public let messageType: MessageType
public let devType: DeviceType
public let RESERVED: UInt8
public let signType: SignType
public let timestamp: Date
public let devID: UInt128
public let location: Location
public let fields: [Field]
public init(
version: UInt8,
messageType: MessageType,
devType: DeviceType,
RESERVED: UInt8,
signType: SignType,
timestamp: Date,
devID: UInt128,
location: Location,
fields: [Field]
) {
self.version = version
self.messageType = messageType
self.devType = devType
self.RESERVED = RESERVED
self.signType = signType
self.timestamp = timestamp
self.devID = devID
self.location = location
self.fields = fields
}
public func toString() -> String {
var description = ""
description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n"
description += "Message Type: \t\(self.messageType.rawValue)\n"
description += "Device Type: \t\(self.devType.rawValue)\n"
description += "RESERVED: \t\(self.RESERVED)\n"
description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\n"
description += "Device ID: \t\(self.devID)\n"
description +=
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
description += "Fields: \n"
for field in self.fields {
description +=
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
}
return description
}
}
public struct SignedMessage: MessageP {
public let version: UInt8
public let messageType: MessageType
public let devType: DeviceType
public let RESERVED: UInt8
public let signType: SignType
public let timestamp: Date
public let devID: UInt128
public let location: Location
public let fields: [Field]
public let signature: [UInt8]
public func toString() -> String {
var description = ""
description += "MESSAGE -------\n"
description += "V: \t\(self.version)\n"
description += "Message Type: \t\(self.messageType.rawValue)\n"
description += "Device Type: \t\(self.devType.rawValue)\n"
description += "RESERVED: \t\(self.RESERVED)\n"
description += "Signature Type: \t\(self.signType.rawValue)\n"
description += "Timestamp: \t\(self.timestamp)\n"
description += "Device ID: \t\(self.devID)\n"
description +=
"Location: \tX: \(self.location.x)\tY: \(self.location.y)\tZ: \(self.location.z)\n"
description += "Fields: \n"
for field in self.fields {
description +=
"\t\(String(data: Data(field.key), encoding: .ascii) ?? "UNABLE TO DECODE"): \(String(data: Data(field.value), encoding: .ascii) ?? "UNABLE TO DECODE")\n"
}
description += "Signature: \t\(self.signature)\n"
return description
}
}