app-starlock/lib/talk/startChart/entity/heartbeat_response.dart

38 lines
935 B
Dart

class HeartbeatResponse {
int? statusCode;
int? nextPingTime;
HeartbeatResponse({
this.statusCode,
this.nextPingTime,
});
factory HeartbeatResponse.fromBytes(List<int> bytes) {
final message = HeartbeatResponse();
int offset = 0;
// Set default value for statusCode
message.statusCode = 0; // 或者其他默认值
// Check if the entire array has at least 2 bytes for nextPingTime
if (bytes.length < 2) {
throw FormatException("Insufficient data for HeartbeatResponse");
}
// 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");
}
return message;
}
@override
String toString() {
return 'HeartbeatResponse{statusCode: $statusCode, nextPingTime: $nextPingTime}';
}
}