V0.6.2 Arroyo Toad

Fixed timeconversion to support unixepoch timestamp
This commit is contained in:
Christian Risi
2024-12-06 19:08:29 +00:00
parent ad4fd555f1
commit f3bc5f32e2
6 changed files with 21 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ public func serializeV1(msg: MessageP) -> Data {
serializedData[4...7] = msg.signType.rawValue.data
// First 8 bytes
serializedData[8...15] = msg.timestamp.data
serializedData[8...15] = msg.timestamp.timeIntervalSince1970.data
// 8 Bytes
serializedData[16...31] = msg.devID.data
@@ -99,7 +99,7 @@ public func deserializeV1(serializedData: Data) throws -> SignedMessage {
let signBytes = try signatureBytes(signature: signType)
let timestamp = serializedData[8...15].timestamp
let timestamp = serializedData[8...15].double
// 8 Bytes
let devID = serializedData[16...31].uint128
@@ -171,7 +171,7 @@ public func deserializeV1(serializedData: Data) throws -> SignedMessage {
devType: devType,
RESERVED: RESERVED,
signType: signType,
timestamp: timestamp,
timestamp: Date(timeIntervalSince1970: timestamp),
devID: devID,
location: Location(x: locationX, y: locationY, z: locationZ),
fields: fields,

View File

@@ -29,4 +29,8 @@ public extension Data {
var timestamp: Date {
return self.withUnsafeBytes{ $0.bindMemory(to: Date.self) }[0]
}
var double: Double {
return self.withUnsafeBytes{ $0.bindMemory(to: Double.self) }[0]
}
}

View File

@@ -41,3 +41,10 @@ extension Date: DataCompatibleP {
return Data(bytes: &obj, count: MemoryLayout<Self>.stride)
}
}
extension Double: DataCompatibleP {
public var data: Data {
var obj = self
return Data(bytes: &obj, count: MemoryLayout<Self>.stride)
}
}