// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.channel.unix;

import io.netty.util.internal.CleanableDirectBuffer;
import java.nio.ByteOrder;
import io.netty.util.internal.PlatformDependent;
import java.nio.ByteBuffer;

public final class Buffer
{
    private Buffer() {
    }
    
    @Deprecated
    public static void free(final ByteBuffer buffer) {
        PlatformDependent.freeDirectBuffer(buffer);
    }
    
    @Deprecated
    public static ByteBuffer allocateDirectWithNativeOrder(final int capacity) {
        return ByteBuffer.allocateDirect(capacity).order(PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
    }
    
    public static CleanableDirectBuffer allocateDirectBufferWithNativeOrder(final int capacity) {
        final CleanableDirectBuffer cleanableDirectBuffer = PlatformDependent.allocateDirect(capacity);
        cleanableDirectBuffer.buffer().order(PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
        return cleanableDirectBuffer;
    }
    
    public static long memoryAddress(final ByteBuffer buffer) {
        assert buffer.isDirect();
        if (PlatformDependent.hasUnsafe()) {
            return PlatformDependent.directBufferAddress(buffer);
        }
        return memoryAddress0(buffer);
    }
    
    public static int addressSize() {
        if (PlatformDependent.hasUnsafe()) {
            return PlatformDependent.addressSize();
        }
        return addressSize0();
    }
    
    private static native int addressSize0();
    
    private static native long memoryAddress0(final ByteBuffer p0);
    
    public static ByteBuffer wrapMemoryAddressWithNativeOrder(final long memoryAddress, final int capacity) {
        return wrapMemoryAddress(memoryAddress, capacity).order(ByteOrder.nativeOrder());
    }
    
    public static native ByteBuffer wrapMemoryAddress(final long p0, final int p1);
}
