fix:增加peerId长度补齐逻辑但不使用
This commit is contained in:
parent
1a67783d7a
commit
b2d2c75b54
@ -68,6 +68,18 @@ class ScpMessage {
|
||||
return 'ScpMessage{ProtocolFlag: $ProtocolFlag, MessageType: $MessageType, MessageId: $MessageId, SpTotal: $SpTotal, SpIndex: $SpIndex, FromPeerId: $FromPeerId, ToPeerId: $ToPeerId, PayloadType: $PayloadType, PayloadCRC: $PayloadCRC, PayloadLength: $PayloadLength, Payload: $Payload}';
|
||||
}
|
||||
|
||||
// 辅助函数:定长字符串编码
|
||||
List<int> encodeFixedLengthString(String? str, int length) {
|
||||
final bytes = utf8.encode(str ?? '');
|
||||
if (bytes.length > length) {
|
||||
return bytes.sublist(0, length);
|
||||
} else if (bytes.length < length) {
|
||||
return bytes + List.filled(length - bytes.length, 0);
|
||||
} else {
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
String serialize() {
|
||||
final bytes = <int>[];
|
||||
|
||||
@ -98,16 +110,19 @@ class ScpMessage {
|
||||
if (SpIndex != null) {
|
||||
bytes.add(SpIndex!);
|
||||
}
|
||||
|
||||
// FromPeerId (字符串,记录长度)
|
||||
// FromPeerId (字符串,长度固定为44字节)
|
||||
if (FromPeerId != null) {
|
||||
bytes.addAll(utf8.encode(FromPeerId!));
|
||||
}
|
||||
// FromPeerId (44字节定长)
|
||||
// bytes.addAll(encodeFixedLengthString(FromPeerId, 44));
|
||||
|
||||
// ToPeerId (字符串,假设长度固定为32字节)
|
||||
// ToPeerId (字符串,长度固定为44字节)
|
||||
if (ToPeerId != null) {
|
||||
bytes.addAll(utf8.encode(ToPeerId!));
|
||||
}
|
||||
// ToPeerId (44字节定长)
|
||||
// bytes.addAll(encodeFixedLengthString(ToPeerId, 44));
|
||||
|
||||
// PayloadType (2 bytes)
|
||||
if (PayloadType != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user