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

import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.StringCodec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgChannelRequest;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgChannelRequestSignal;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author Alex Usun
 */
public class SshMsgChannelRequestSignalCodec
        implements SshMsgChannelRequestCodec.RequestCodec {

    @Override
    public SshMsgChannelRequest read(InputStream in, int recipientChannel, boolean wantReply)
            throws IOException {
        String signalName = StringCodec.readUtf8Value(in);

        return new SshMsgChannelRequestSignal(recipientChannel, signalName);
    }

    @Override
    public void write(SshMsgChannelRequest value, OutputStream out)
            throws IOException {
        SshMsgChannelRequestSignal message = (SshMsgChannelRequestSignal) value;
        StringCodec.writeUtf8Value(message.signalName, out);
    }
}
