2024-12-02 16:13:07 +08:00
|
|
|
class HeartbeatResponse {
|
2024-12-03 14:44:29 +08:00
|
|
|
int? statusCode;
|
|
|
|
|
int? nextPingTime;
|
2024-12-02 16:13:07 +08:00
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
HeartbeatResponse({
|
|
|
|
|
this.statusCode,
|
|
|
|
|
this.nextPingTime,
|
|
|
|
|
});
|
2024-12-02 16:13:07 +08:00
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
factory HeartbeatResponse.fromBytes(List<int> bytes) {
|
|
|
|
|
final message = HeartbeatResponse();
|
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
|
|
// Set default value for statusCode
|
|
|
|
|
message.statusCode = 0; // 或者其他默认值
|
2024-12-02 16:13:07 +08:00
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
// Check if the entire array has at least 2 bytes for nextPingTime
|
|
|
|
|
if (bytes.length < 2) {
|
|
|
|
|
throw FormatException("Insufficient data for HeartbeatResponse");
|
2024-12-02 16:13:07 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
// nextPingTime (2 bytes, little-endian)
|
|
|
|
|
if (bytes.length - offset >= 2) {
|
|
|
|
|
message.nextPingTime = (bytes[offset + 1] << 8) | bytes[offset];
|
|
|
|
|
offset += 2;
|
|
|
|
|
} else {
|
|
|
|
|
throw FormatException("Invalid nextPingTime length");
|
|
|
|
|
}
|
2024-12-02 16:13:07 +08:00
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
return message;
|
2024-12-02 16:13:07 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-03 14:44:29 +08:00
|
|
|
@override
|
|
|
|
|
String toString() {
|
|
|
|
|
return 'HeartbeatResponse{statusCode: $statusCode, nextPingTime: $nextPingTime}';
|
2024-12-02 16:13:07 +08:00
|
|
|
}
|
2024-12-03 14:44:29 +08:00
|
|
|
}
|