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.SshMsgChannelRequestEnv;

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

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

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

        return new SshMsgChannelRequestEnv(recipientChannel, wantReply, name, value);
    }

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