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.NameListCodec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgUserAuthFailure;
import com.jscape.util.io.DataCodec;
import com.jscape.util.io.primitive.BooleanCodec;

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

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

    @Override
    public Message read(InputStream in)
            throws IOException {
        List<String> authenticationsThatCanContinue = NameListCodec.readUsAsciiValue(in);
        boolean partialSuccess = BooleanCodec.readValue(in);

        return new SshMsgUserAuthFailure(authenticationsThatCanContinue, partialSuccess);
    }

    @Override
    public void write(Message value, OutputStream out)
            throws IOException {
        SshMsgUserAuthFailure message = (SshMsgUserAuthFailure) value;
        NameListCodec.writeUsAsciiValue(message.authenticationsThatCanContinue, out);
        BooleanCodec.writeValue(message.partialSuccess, out);
    }
}
