encode method
Encode message to bytes
Implementation
@override
Uint8List encode(int protocolVersion, MessageEncoding encoding) {
final bytes = <int>[];
// Command that was rejected (variable length string)
final cmdUtf8 = utf8.encode(cmd);
VarInt.write(bytes, cmdUtf8.length);
bytes.addAll(cmdUtf8);
// Code indicating why the command was rejected (1 byte)
bytes.add(code.value);
// Human readable reason string (variable length string)
final reasonUtf8 = utf8.encode(reason);
VarInt.write(bytes, reasonUtf8.length);
bytes.addAll(reasonUtf8);
// Hash (only for block/tx rejections, 32 bytes)
if (hash != null) {
bytes.addAll(hash!.bytes);
}
return Uint8List.fromList(bytes);
}