TempTrack-iOS/TempTrack/Connection/DeviceDataRequest.swift
2023-06-29 10:13:37 +02:00

40 lines
1.0 KiB
Swift

import Foundation
struct DeviceDataRequest: DeviceRequest {
typealias Response = Data
static let type: BluetoothRequestType = .getRecordingData
let offset: Int
let count: Int
var payload: Data {
count.twoByteData + offset.twoByteData
}
init(offset: Int, count: Int) {
self.offset = offset
self.count = count
}
func makeResponse(from responseData: Data, responseType: BluetoothResponseType) -> Data? {
switch responseType {
case .success:
break
case .responseTooLarge:
log.warning("Exceeded payload size for device data request (offset: \(offset), count: \(count))")
break
default:
log.warning("Invalid response \(responseType) to device data request")
return nil
}
guard responseData.count == count else {
log.warning("Got \(responseData.count) for device data request (offset: \(offset), count: \(count))")
return nil
}
return responseData
}
}