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

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

    @Override
    public Message read(InputStream in)
            throws IOException {
        boolean alwaysDisplay = BooleanCodec.readValue(in);
        String message = StringCodec.readUtf8Value(in);
        String languageTag = StringCodec.readUsAsciiValue(in);

        return new SshMsgDebug(alwaysDisplay, message, languageTag);
    }

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