All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zmq.io.coder.raw.RawDecoder Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package zmq.io.coder.raw;

import java.nio.ByteBuffer;

import zmq.Msg;
import zmq.io.coder.IDecoder;
import zmq.util.ValueReference;

public class RawDecoder implements IDecoder
{
    //  The buffer for data to decode.
    private final ByteBuffer buffer;

    protected Msg inProgress;

    public RawDecoder(int bufsize)
    {
        buffer = ByteBuffer.allocateDirect(bufsize);
        inProgress = new Msg();
    }

    @Override
    public ByteBuffer getBuffer()
    {
        buffer.clear();
        return buffer;
    }

    @Override
    public Step.Result decode(ByteBuffer buffer, int size, ValueReference processed)
    {
        processed.set(size);
        inProgress = new Msg(size);
        inProgress.put(buffer);

        return Step.Result.DECODED;
    }

    @Override
    public Msg msg()
    {
        return inProgress;
    }

    @Override
    public void destroy()
    {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy