serialize method

Uint8List serialize()

Serialize header to bytes

Implementation

Uint8List serialize() {
  final buffer = ByteData(messageHeaderSize);

  // Network magic (4 bytes, little endian)
  buffer.setUint32(0, network.magic, Endian.little);

  // Command (12 bytes, null-padded)
  final commandBytes = utf8.encode(command);
  for (int i = 0; i < commandSize; i++) {
    buffer.setUint8(4 + i, i < commandBytes.length ? commandBytes[i] : 0);
  }

  // Payload length (4 bytes, little endian)
  buffer.setUint32(16, payloadLength, Endian.little);

  // Checksum (4 bytes, raw bytes)
  for (int i = 0; i < 4; i++) {
    buffer.setUint8(20 + i, checksum[i]);
  }

  return buffer.buffer.asUint8List();
}