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.Uint32Codec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgKexDhGexRequest;
import com.jscape.util.io.DataCodec;

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

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

    @Override
    public Message read(InputStream in)
            throws IOException {
        int min = Uint32Codec.readValue(in);
        int n = Uint32Codec.readValue(in);
        int max = Uint32Codec.readValue(in);

        return new SshMsgKexDhGexRequest(min, n, max);
    }

    @Override
    public void write(Message value, OutputStream out)
            throws IOException {
        SshMsgKexDhGexRequest message = (SshMsgKexDhGexRequest) value;
        Uint32Codec.writeValue(message.min, out);
        Uint32Codec.writeValue(message.n, out);
        Uint32Codec.writeValue(message.max, out);
    }
}
