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

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

import static com.jscape.util.Parameters.assertNotNull;

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

    public final int recipientChannel;
    public final byte[] data;
    public final int offset;
    public final int length;

    public SshMsgChannelData(int recipientChannel, byte[] data, int offset, int length) {
        this.recipientChannel = recipientChannel;

        assertNotNull(data);
        this.data = data;

        this.offset = offset;
        this.length = length;
    }

    public SshMsgChannelData(int recipientChannel, byte[] data) {
        this(recipientChannel, data, 0, data.length);
    }

    @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 "SshMsgChannelData {"
                + "recipientChannel=" + this.recipientChannel
                + ", data.length=" + this.data.length
                + ", offset=" + this.offset
                + ", length=" + this.length
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
