Fix decoding
This commit is contained in:
parent
c6b51c98fb
commit
253017c429
@ -130,6 +130,8 @@ private func readElements<T>(from url: URL) throws -> [Timestamped<T>] where T:
|
|||||||
let file = url.lastPathComponent
|
let file = url.lastPathComponent
|
||||||
print("File \(file): Loaded \(data.count) bytes")
|
print("File \(file): Loaded \(data.count) bytes")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let decoder = CBORDecoder()
|
let decoder = CBORDecoder()
|
||||||
let timestampLength = 9
|
let timestampLength = 9
|
||||||
let byteCountLength = 2
|
let byteCountLength = 2
|
||||||
@ -159,7 +161,7 @@ private func readElements<T>(from url: URL) throws -> [Timestamped<T>] where T:
|
|||||||
let timestampData = data[startIndexOfTimestamp..<startIndexOfTimestamp+timestampLength]
|
let timestampData = data[startIndexOfTimestamp..<startIndexOfTimestamp+timestampLength]
|
||||||
let timestamp = try decoder.decode(Double.self, from: timestampData)
|
let timestamp = try decoder.decode(Double.self, from: timestampData)
|
||||||
let date = Date(timeIntervalSince1970: timestamp)
|
let date = Date(timeIntervalSince1970: timestamp)
|
||||||
let elementData = data[currentIndex..<nextIndex]
|
let elementData = data[startIndexOfTimestamp+timestampLength..<nextIndex]
|
||||||
do {
|
do {
|
||||||
let element: T = try decoder.decode(from: elementData)
|
let element: T = try decoder.decode(from: elementData)
|
||||||
result.append(.init(value: element, timestamp: date))
|
result.append(.init(value: element, timestamp: date))
|
||||||
|
Loading…
Reference in New Issue
Block a user