2024-12-06 11:31:07 +00:00
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 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: \t X: \( self . location . x ) \t Y: \( self . location . y ) \t Z: \( 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: \t X: \( self . location . x ) \t Y: \( self . location . y ) \t Z: \( 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
}
2024-12-05 16:21:52 +01:00
}