package io.netty.buffer;

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

/* JADX INFO: loaded from: classes.dex */
abstract class AbstractUnsafeSwappedByteBuf extends SwappedByteBuf {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private final boolean nativeByteOrder;
    private final AbstractByteBuf wrapped;

    AbstractUnsafeSwappedByteBuf(AbstractByteBuf abstractByteBuf) {
        super(abstractByteBuf);
        this.wrapped = abstractByteBuf;
        this.nativeByteOrder = PlatformDependent.BIG_ENDIAN_NATIVE_ORDER == (order() == ByteOrder.BIG_ENDIAN);
    }

    protected abstract int _getInt(AbstractByteBuf abstractByteBuf, int i2);

    protected abstract long _getLong(AbstractByteBuf abstractByteBuf, int i2);

    protected abstract short _getShort(AbstractByteBuf abstractByteBuf, int i2);

    protected abstract void _setInt(AbstractByteBuf abstractByteBuf, int i2, int i3);

    protected abstract void _setLong(AbstractByteBuf abstractByteBuf, int i2, long j2);

    protected abstract void _setShort(AbstractByteBuf abstractByteBuf, int i2, short s);

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final char getChar(int i2) {
        return (char) getShort(i2);
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final double getDouble(int i2) {
        return Double.longBitsToDouble(getLong(i2));
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final float getFloat(int i2) {
        return Float.intBitsToFloat(getInt(i2));
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final int getInt(int i2) {
        this.wrapped.checkIndex0(i2, 4);
        int i_getInt = _getInt(this.wrapped, i2);
        return this.nativeByteOrder ? i_getInt : Integer.reverseBytes(i_getInt);
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final long getLong(int i2) {
        this.wrapped.checkIndex(i2, 8);
        long j_getLong = _getLong(this.wrapped, i2);
        return this.nativeByteOrder ? j_getLong : Long.reverseBytes(j_getLong);
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final short getShort(int i2) {
        this.wrapped.checkIndex0(i2, 2);
        short s_getShort = _getShort(this.wrapped, i2);
        return this.nativeByteOrder ? s_getShort : Short.reverseBytes(s_getShort);
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final long getUnsignedInt(int i2) {
        return ((long) getInt(i2)) & 4294967295L;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final int getUnsignedShort(int i2) {
        return getShort(i2) & 65535;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setChar(int i2, int i3) {
        setShort(i2, i3);
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setDouble(int i2, double d2) {
        setLong(i2, Double.doubleToRawLongBits(d2));
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setFloat(int i2, float f2) {
        setInt(i2, Float.floatToRawIntBits(f2));
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setInt(int i2, int i3) {
        this.wrapped.checkIndex0(i2, 4);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        if (!this.nativeByteOrder) {
            i3 = Integer.reverseBytes(i3);
        }
        _setInt(abstractByteBuf, i2, i3);
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setLong(int i2, long j2) {
        this.wrapped.checkIndex(i2, 8);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        if (!this.nativeByteOrder) {
            j2 = Long.reverseBytes(j2);
        }
        _setLong(abstractByteBuf, i2, j2);
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf setShort(int i2, int i3) {
        this.wrapped.checkIndex0(i2, 2);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        short sReverseBytes = (short) i3;
        if (!this.nativeByteOrder) {
            sReverseBytes = Short.reverseBytes(sReverseBytes);
        }
        _setShort(abstractByteBuf, i2, sReverseBytes);
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeChar(int i2) {
        writeShort(i2);
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeDouble(double d2) {
        writeLong(Double.doubleToRawLongBits(d2));
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeFloat(float f2) {
        writeInt(Float.floatToRawIntBits(f2));
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeInt(int i2) {
        this.wrapped.ensureWritable(4);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        int i3 = abstractByteBuf.writerIndex;
        if (!this.nativeByteOrder) {
            i2 = Integer.reverseBytes(i2);
        }
        _setInt(abstractByteBuf, i3, i2);
        this.wrapped.writerIndex += 4;
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeLong(long j2) {
        this.wrapped.ensureWritable(8);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        int i2 = abstractByteBuf.writerIndex;
        if (!this.nativeByteOrder) {
            j2 = Long.reverseBytes(j2);
        }
        _setLong(abstractByteBuf, i2, j2);
        this.wrapped.writerIndex += 8;
        return this;
    }

    @Override // io.netty.buffer.SwappedByteBuf, io.netty.buffer.ByteBuf
    public final ByteBuf writeShort(int i2) {
        this.wrapped.ensureWritable(2);
        AbstractByteBuf abstractByteBuf = this.wrapped;
        int i3 = abstractByteBuf.writerIndex;
        short sReverseBytes = (short) i2;
        if (!this.nativeByteOrder) {
            sReverseBytes = Short.reverseBytes(sReverseBytes);
        }
        _setShort(abstractByteBuf, i3, sReverseBytes);
        this.wrapped.writerIndex += 2;
        return this;
    }
}
