package com.jscape.inet.ssh.protocol.v2.messages;

import com.jscape.inet.ssh.protocol.messages.Message;
import com.jscape.util.HexFormat;
import com.jscape.util.net.connection.MessageConnection;

/**
 * @author Alex Usun
 */
public class UnknownMessage
        extends Message<UnknownMessage.Handler> {

    public final int messageCode;
    public final byte[] data;

    public UnknownMessage(int messageCode, byte[] data) {
        this.messageCode = messageCode;
        this.data = data;
    }

    @Override
    public Class handlerClass() {
        return Handler.class;
    }

    @Override
    public void accept(Handler handler, MessageConnection<Message> connection) {
        handler.handle(this, connection);
    }

    @Override
    public String toString() {
        return "UnknownMessage {"
               + "messageCode=" + this.messageCode
               + ", data=" + HexFormat.formatData(this.data)
               + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

        void handle(UnknownMessage message, MessageConnection<Message> connection);

    }
}
