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

import com.jscape.inet.ssh.protocol.messages.Message;
import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.StringCodec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgUserAuthPasswdChangeReq;
import com.jscape.util.io.DataCodec;

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

/**
 * @author Alex Usun
 */
public class SshMsgUserAuthPasswdChangeReqCodec
        implements DataCodec<Message> {

    @Override
    public Message read(InputStream in)
            throws IOException {
        String prompt = StringCodec.readUtf8Value(in);
        String languageTag = StringCodec.readUsAsciiValue(in);

        return new SshMsgUserAuthPasswdChangeReq(prompt, languageTag);
    }

    @Override
    public void write(Message value, OutputStream out)
            throws IOException {
        SshMsgUserAuthPasswdChangeReq message = (SshMsgUserAuthPasswdChangeReq) value;
        StringCodec.writeUtf8Value(message.prompt, out);
        StringCodec.writeUsAsciiValue(message.languageTag, out);
    }
}
