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

org.zodiac.netty.marshallers.ByteBufferMarshaller Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.netty.marshallers;

import io.netty.buffer.ByteBuf;
import java.nio.ByteBuffer;
import org.zodiac.sdk.toolkit.marshallers.Marshaller;

final class ByteBufferMarshaller implements Marshaller {

    public ByteBufferMarshaller() {
        super();
    }

    @Override
    public ByteBuffer read(ByteBuf data, Object[] hints) throws Exception {
        if (data.isDirect()) {
            return data.internalNioBuffer(0, data.readableBytes());
        } else {
            ByteBuffer buffer = ByteBuffer.allocateDirect(data.readableBytes());
            data.readBytes(buffer);
            return (ByteBuffer) buffer.flip();
        }
    }

    @Override
    public void write(ByteBuffer obj, ByteBuf into, Object[] hints) throws Exception {
        into.writeBytes(obj);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy