package com.jscape.inet.scp.protocol.marshaling;

import com.jscape.inet.scp.protocol.messages.EndDirectoryMessage;
import com.jscape.inet.scp.protocol.messages.Message;
import com.jscape.util.io.primitive.ByteCodec;

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

/**
 * @author Alex Usun
 */
public class EndDirectoryMessageCodec
        extends CodecBase {

    public Message read(InputStream in)
            throws IOException {
        int eol = ByteCodec.readValue(in) & 0xFF;

        if (eol != EOL) {
            throw new IOException("Error reading message.");
        }

        return new EndDirectoryMessage();
    }

    public void write(Message value, OutputStream out)
            throws IOException {
        out.write(EOL);
    }
}
