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

import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.Uint32Codec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgChannelRequest;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgChannelRequestBreak;

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

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

    @Override
    public SshMsgChannelRequest read(InputStream in, int recipientChannel, boolean wantReply)
            throws IOException {
        int breakLengthMillis = Uint32Codec.readValue(in);

        return new SshMsgChannelRequestBreak(recipientChannel, wantReply, breakLengthMillis);
    }

    @Override
    public void write(SshMsgChannelRequest value, OutputStream out)
            throws IOException {
        SshMsgChannelRequestBreak message = (SshMsgChannelRequestBreak) value;
        Uint32Codec.writeValue(message.breakLengthMillis, out);
    }
}
