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.SshMsgServiceAccept;
import com.jscape.util.io.DataCodec;

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

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

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

        return new SshMsgServiceAccept(serviceName);
    }

    @Override
    public void write(Message value, OutputStream out)
            throws IOException {
        SshMsgServiceAccept message = (SshMsgServiceAccept) value;
        StringCodec.writeUsAsciiValue(message.serviceName, out);
    }
}
