package com.jscape.inet.sftp.protocol.v4.marshaling;

import com.jscape.inet.sftp.protocol.v4.messages.SshFxpExtended;
import com.jscape.inet.sftp.protocol.v4.messages.SshFxpExtendedTextSeek;
import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.StringCodec;
import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.Uint64Codec;

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

/**
 * @author Alex Usun
 */
public class SshFxpExtendedTextSeekCodec
        implements SshFxpExtendedCodec.TypeCodec {

    @Override
    public SshFxpExtended read(InputStream in, int id)
            throws IOException {
        byte[] fileHandle = StringCodec.readValue(in);
        long lineNumber = Uint64Codec.readValue(in);

        return new SshFxpExtendedTextSeek(id, fileHandle, lineNumber);
    }

    @Override
    public void write(SshFxpExtended value, OutputStream out)
            throws IOException {
        SshFxpExtendedTextSeek message = (SshFxpExtendedTextSeek) value;
        StringCodec.writeValue(message.fileHandle, out);
        Uint64Codec.writeValue(message.lineNumber, out);
    }
}
