fix:调整心跳包解析
This commit is contained in:
parent
db7cd20a12
commit
44ba4c2920
@ -1,37 +1,55 @@
|
|||||||
class HeartbeatResponse {
|
class HeartbeatResponse {
|
||||||
int? statusCode;
|
int? statusCode;
|
||||||
int? nextPingTime;
|
int? nextPingTime;
|
||||||
|
String? clientAddr;
|
||||||
|
|
||||||
HeartbeatResponse({
|
HeartbeatResponse({
|
||||||
this.statusCode,
|
this.statusCode,
|
||||||
this.nextPingTime,
|
this.nextPingTime,
|
||||||
|
this.clientAddr,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory HeartbeatResponse.fromBytes(List<int> bytes) {
|
factory HeartbeatResponse.fromBytes(List<int> bytes) {
|
||||||
final message = HeartbeatResponse();
|
final message = HeartbeatResponse();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
// Set default value for statusCode
|
// 检查是否有足够的数据来解析状态码
|
||||||
message.statusCode = 0; // 或者其他默认值
|
if (bytes.length < 1) {
|
||||||
|
|
||||||
// Check if the entire array has at least 2 bytes for nextPingTime
|
|
||||||
if (bytes.length < 2) {
|
|
||||||
throw FormatException("Insufficient data for HeartbeatResponse");
|
throw FormatException("Insufficient data for HeartbeatResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextPingTime (2 bytes, little-endian)
|
// 解析状态码 (1 byte)
|
||||||
if (bytes.length - offset >= 2) {
|
message.statusCode = bytes[offset];
|
||||||
message.nextPingTime = (bytes[offset + 1] << 8) | bytes[offset];
|
offset += 1;
|
||||||
offset += 2;
|
|
||||||
} else {
|
// 检查是否有足够的数据来解析 nextPingTime
|
||||||
throw FormatException("Invalid nextPingTime length");
|
if (bytes.length < offset + 2) {
|
||||||
|
throw FormatException("Insufficient data for nextPingTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析 nextPingTime (2 bytes, little-endian)
|
||||||
|
message.nextPingTime = (bytes[offset + 1] << 8) | bytes[offset];
|
||||||
|
offset += 2;
|
||||||
|
|
||||||
|
// 解析 clientAddr (null-terminated string)
|
||||||
|
final clientAddrBytes = <int>[];
|
||||||
|
while (offset < bytes.length && bytes[offset] != 0) {
|
||||||
|
clientAddrBytes.add(bytes[offset]);
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 跳过 null terminator
|
||||||
|
if (offset < bytes.length && bytes[offset] == 0) {
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.clientAddr = String.fromCharCodes(clientAddrBytes);
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'HeartbeatResponse{statusCode: $statusCode, nextPingTime: $nextPingTime}';
|
return 'HeartbeatResponse{statusCode: $statusCode, nextPingTime: $nextPingTime, clientAddr: $clientAddr}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
102
lib/talk/startChart/proto/talk_data_h264_frame.pb.dart
Normal file
102
lib/talk/startChart/proto/talk_data_h264_frame.pb.dart
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
//
|
||||||
|
// Generated code. Do not modify.
|
||||||
|
// source: talk_data_h264_frame.proto
|
||||||
|
//
|
||||||
|
// @dart = 2.12
|
||||||
|
|
||||||
|
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
||||||
|
// ignore_for_file: constant_identifier_names, library_prefixes
|
||||||
|
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
||||||
|
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
||||||
|
|
||||||
|
import 'dart:core' as $core;
|
||||||
|
|
||||||
|
import 'package:protobuf/protobuf.dart' as $pb;
|
||||||
|
|
||||||
|
import 'talk_data_h264_frame.pbenum.dart';
|
||||||
|
|
||||||
|
export 'talk_data_h264_frame.pbenum.dart';
|
||||||
|
|
||||||
|
class TalkDataH264Frame extends $pb.GeneratedMessage {
|
||||||
|
factory TalkDataH264Frame({
|
||||||
|
$core.int? frameSeq,
|
||||||
|
TalkDataH264Frame_FrameTypeE? frameType,
|
||||||
|
$core.List<$core.int>? frameData,
|
||||||
|
}) {
|
||||||
|
final $result = create();
|
||||||
|
if (frameSeq != null) {
|
||||||
|
$result.frameSeq = frameSeq;
|
||||||
|
}
|
||||||
|
if (frameType != null) {
|
||||||
|
$result.frameType = frameType;
|
||||||
|
}
|
||||||
|
if (frameData != null) {
|
||||||
|
$result.frameData = frameData;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
TalkDataH264Frame._() : super();
|
||||||
|
factory TalkDataH264Frame.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
||||||
|
factory TalkDataH264Frame.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
|
||||||
|
|
||||||
|
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'TalkDataH264Frame', package: const $pb.PackageName(_omitMessageNames ? '' : 'main'), createEmptyInstance: create)
|
||||||
|
..a<$core.int>(1, _omitFieldNames ? '' : 'FrameSeq', $pb.PbFieldType.OU3, protoName: 'FrameSeq')
|
||||||
|
..e<TalkDataH264Frame_FrameTypeE>(2, _omitFieldNames ? '' : 'FrameType', $pb.PbFieldType.OE, protoName: 'FrameType', defaultOrMaker: TalkDataH264Frame_FrameTypeE.NONE, valueOf: TalkDataH264Frame_FrameTypeE.valueOf, enumValues: TalkDataH264Frame_FrameTypeE.values)
|
||||||
|
..a<$core.List<$core.int>>(3, _omitFieldNames ? '' : 'FrameData', $pb.PbFieldType.OY, protoName: 'FrameData')
|
||||||
|
..hasRequiredFields = false
|
||||||
|
;
|
||||||
|
|
||||||
|
@$core.Deprecated(
|
||||||
|
'Using this can add significant overhead to your binary. '
|
||||||
|
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
|
||||||
|
'Will be removed in next major version')
|
||||||
|
TalkDataH264Frame clone() => TalkDataH264Frame()..mergeFromMessage(this);
|
||||||
|
@$core.Deprecated(
|
||||||
|
'Using this can add significant overhead to your binary. '
|
||||||
|
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||||
|
'Will be removed in next major version')
|
||||||
|
TalkDataH264Frame copyWith(void Function(TalkDataH264Frame) updates) => super.copyWith((message) => updates(message as TalkDataH264Frame)) as TalkDataH264Frame;
|
||||||
|
|
||||||
|
$pb.BuilderInfo get info_ => _i;
|
||||||
|
|
||||||
|
@$core.pragma('dart2js:noInline')
|
||||||
|
static TalkDataH264Frame create() => TalkDataH264Frame._();
|
||||||
|
TalkDataH264Frame createEmptyInstance() => create();
|
||||||
|
static $pb.PbList<TalkDataH264Frame> createRepeated() => $pb.PbList<TalkDataH264Frame>();
|
||||||
|
@$core.pragma('dart2js:noInline')
|
||||||
|
static TalkDataH264Frame getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<TalkDataH264Frame>(create);
|
||||||
|
static TalkDataH264Frame? _defaultInstance;
|
||||||
|
|
||||||
|
/// 帧序号 seq
|
||||||
|
@$pb.TagNumber(1)
|
||||||
|
$core.int get frameSeq => $_getIZ(0);
|
||||||
|
@$pb.TagNumber(1)
|
||||||
|
set frameSeq($core.int v) { $_setUnsignedInt32(0, v); }
|
||||||
|
@$pb.TagNumber(1)
|
||||||
|
$core.bool hasFrameSeq() => $_has(0);
|
||||||
|
@$pb.TagNumber(1)
|
||||||
|
void clearFrameSeq() => clearField(1);
|
||||||
|
|
||||||
|
@$pb.TagNumber(2)
|
||||||
|
TalkDataH264Frame_FrameTypeE get frameType => $_getN(1);
|
||||||
|
@$pb.TagNumber(2)
|
||||||
|
set frameType(TalkDataH264Frame_FrameTypeE v) { setField(2, v); }
|
||||||
|
@$pb.TagNumber(2)
|
||||||
|
$core.bool hasFrameType() => $_has(1);
|
||||||
|
@$pb.TagNumber(2)
|
||||||
|
void clearFrameType() => clearField(2);
|
||||||
|
|
||||||
|
/// 帧数据
|
||||||
|
@$pb.TagNumber(3)
|
||||||
|
$core.List<$core.int> get frameData => $_getN(2);
|
||||||
|
@$pb.TagNumber(3)
|
||||||
|
set frameData($core.List<$core.int> v) { $_setBytes(2, v); }
|
||||||
|
@$pb.TagNumber(3)
|
||||||
|
$core.bool hasFrameData() => $_has(2);
|
||||||
|
@$pb.TagNumber(3)
|
||||||
|
void clearFrameData() => clearField(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
|
||||||
|
const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names');
|
||||||
36
lib/talk/startChart/proto/talk_data_h264_frame.pbenum.dart
Normal file
36
lib/talk/startChart/proto/talk_data_h264_frame.pbenum.dart
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// Generated code. Do not modify.
|
||||||
|
// source: talk_data_h264_frame.proto
|
||||||
|
//
|
||||||
|
// @dart = 2.12
|
||||||
|
|
||||||
|
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
||||||
|
// ignore_for_file: constant_identifier_names, library_prefixes
|
||||||
|
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
||||||
|
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
||||||
|
|
||||||
|
import 'dart:core' as $core;
|
||||||
|
|
||||||
|
import 'package:protobuf/protobuf.dart' as $pb;
|
||||||
|
|
||||||
|
/// 帧类型,对于H264,I帧、P帧,
|
||||||
|
/// 未知为NONE?有时候发送方不知道,或者渲染方可以从帧数据中解析
|
||||||
|
class TalkDataH264Frame_FrameTypeE extends $pb.ProtobufEnum {
|
||||||
|
static const TalkDataH264Frame_FrameTypeE NONE = TalkDataH264Frame_FrameTypeE._(0, _omitEnumNames ? '' : 'NONE');
|
||||||
|
static const TalkDataH264Frame_FrameTypeE I = TalkDataH264Frame_FrameTypeE._(1, _omitEnumNames ? '' : 'I');
|
||||||
|
static const TalkDataH264Frame_FrameTypeE P = TalkDataH264Frame_FrameTypeE._(2, _omitEnumNames ? '' : 'P');
|
||||||
|
|
||||||
|
static const $core.List<TalkDataH264Frame_FrameTypeE> values = <TalkDataH264Frame_FrameTypeE> [
|
||||||
|
NONE,
|
||||||
|
I,
|
||||||
|
P,
|
||||||
|
];
|
||||||
|
|
||||||
|
static final $core.Map<$core.int, TalkDataH264Frame_FrameTypeE> _byValue = $pb.ProtobufEnum.initByValue(values);
|
||||||
|
static TalkDataH264Frame_FrameTypeE? valueOf($core.int value) => _byValue[value];
|
||||||
|
|
||||||
|
const TalkDataH264Frame_FrameTypeE._($core.int v, $core.String n) : super(v, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names');
|
||||||
43
lib/talk/startChart/proto/talk_data_h264_frame.pbjson.dart
Normal file
43
lib/talk/startChart/proto/talk_data_h264_frame.pbjson.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// Generated code. Do not modify.
|
||||||
|
// source: talk_data_h264_frame.proto
|
||||||
|
//
|
||||||
|
// @dart = 2.12
|
||||||
|
|
||||||
|
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
||||||
|
// ignore_for_file: constant_identifier_names, library_prefixes
|
||||||
|
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
||||||
|
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
||||||
|
|
||||||
|
import 'dart:convert' as $convert;
|
||||||
|
import 'dart:core' as $core;
|
||||||
|
import 'dart:typed_data' as $typed_data;
|
||||||
|
|
||||||
|
@$core.Deprecated('Use talkDataH264FrameDescriptor instead')
|
||||||
|
const TalkDataH264Frame$json = {
|
||||||
|
'1': 'TalkDataH264Frame',
|
||||||
|
'2': [
|
||||||
|
{'1': 'FrameSeq', '3': 1, '4': 1, '5': 13, '10': 'FrameSeq'},
|
||||||
|
{'1': 'FrameType', '3': 2, '4': 1, '5': 14, '6': '.main.TalkDataH264Frame.FrameTypeE', '10': 'FrameType'},
|
||||||
|
{'1': 'FrameData', '3': 3, '4': 1, '5': 12, '10': 'FrameData'},
|
||||||
|
],
|
||||||
|
'4': [TalkDataH264Frame_FrameTypeE$json],
|
||||||
|
};
|
||||||
|
|
||||||
|
@$core.Deprecated('Use talkDataH264FrameDescriptor instead')
|
||||||
|
const TalkDataH264Frame_FrameTypeE$json = {
|
||||||
|
'1': 'FrameTypeE',
|
||||||
|
'2': [
|
||||||
|
{'1': 'NONE', '2': 0},
|
||||||
|
{'1': 'I', '2': 1},
|
||||||
|
{'1': 'P', '2': 2},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Descriptor for `TalkDataH264Frame`. Decode as a `google.protobuf.DescriptorProto`.
|
||||||
|
final $typed_data.Uint8List talkDataH264FrameDescriptor = $convert.base64Decode(
|
||||||
|
'ChFUYWxrRGF0YUgyNjRGcmFtZRIaCghGcmFtZVNlcRgBIAEoDVIIRnJhbWVTZXESQAoJRnJhbW'
|
||||||
|
'VUeXBlGAIgASgOMiIubWFpbi5UYWxrRGF0YUgyNjRGcmFtZS5GcmFtZVR5cGVFUglGcmFtZVR5'
|
||||||
|
'cGUSHAoJRnJhbWVEYXRhGAMgASgMUglGcmFtZURhdGEiJAoKRnJhbWVUeXBlRRIICgROT05FEA'
|
||||||
|
'ASBQoBSRABEgUKAVAQAg==');
|
||||||
|
|
||||||
14
lib/talk/startChart/proto/talk_data_h264_frame.pbserver.dart
Normal file
14
lib/talk/startChart/proto/talk_data_h264_frame.pbserver.dart
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// Generated code. Do not modify.
|
||||||
|
// source: talk_data_h264_frame.proto
|
||||||
|
//
|
||||||
|
// @dart = 2.12
|
||||||
|
|
||||||
|
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
|
||||||
|
// ignore_for_file: constant_identifier_names
|
||||||
|
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
|
||||||
|
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
|
||||||
|
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
|
||||||
|
|
||||||
|
export 'talk_data_h264_frame.pb.dart';
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user