decode method
Decode message from bytes
Implementation
@override
void decode(Uint8List data, int protocolVersion, MessageEncoding encoding) {
if (data.isEmpty) {
throw WireException('Inv message cannot be empty');
}
final buffer = ByteData.sublistView(data);
int offset = 0;
// Read count of inventory vectors
final count = VarInt.read(buffer, offset);
offset += VarInt.size(count);
// Validate count
if (count > 50000) {
throw WireException('Too many inventory vectors: $count (max 50000)');
}
// Check remaining data length
final expectedSize = count * 36; // Each InvVect is 36 bytes
if (data.length < offset + expectedSize) {
throw WireException(
'Insufficient data for inventory vectors: '
'need ${offset + expectedSize}, got ${data.length}',
);
}
// Read inventory vectors
invList.clear();
for (int i = 0; i < count; i++) {
final inv = InvVect.deserialize(data, offset);
invList.add(inv);
offset += 36;
}
}