/** * Toggles the endianness of the specified 16-bit short integer. */ public static short swapShort(short value) { return Short.reverseBytes(value); }
@Override public final short getShort(int index) { wrapped.checkIndex(index, 2); short v = _getShort(wrapped, index); return nativeByteOrder ? v : Short.reverseBytes(v); }
@Override public final ByteBuf setShort(int index, int value) { wrapped.checkIndex(index, 2); _setShort(wrapped, index, nativeByteOrder ? (short) value : Short.reverseBytes((short) value)); return this; }
@Override public final ByteBuf writeShort(int value) { wrapped.ensureWritable0(2); _setShort(wrapped, wrapped.writerIndex, nativeByteOrder ? (short) value : Short.reverseBytes((short) value)); wrapped.writerIndex += 2; return this; }
static short getShort(long address) { if (UNALIGNED) { short v = PlatformDependent.getShort(address); return BIG_ENDIAN_NATIVE_ORDER ? v : Short.reverseBytes(v); } return (short) (PlatformDependent.getByte(address) << 8 | PlatformDependent.getByte(address + 1) & 0xff); }
static void setShortLE(byte[] array, int index, int value) { if (UNALIGNED) { PlatformDependent.putShort(array, index, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) value) : (short) value); } else { PlatformDependent.putByte(array, index, (byte) value); PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8)); } }
static short getShortLE(long address) { if (UNALIGNED) { short v = PlatformDependent.getShort(address); return BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(v) : v; } return (short) (PlatformDependent.getByte(address) & 0xff | PlatformDependent.getByte(address + 1) << 8); }
static void setShortLE(long address, int value) { if (UNALIGNED) { PlatformDependent.putShort( address, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) value) : (short) value); } else { PlatformDependent.putByte(address, (byte) value); PlatformDependent.putByte(address + 1, (byte) (value >>> 8)); } }
static void setShort(long address, int value) { if (UNALIGNED) { PlatformDependent.putShort( address, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value)); } else { PlatformDependent.putByte(address, (byte) (value >>> 8)); PlatformDependent.putByte(address + 1, (byte) value); } }
static short getShort(byte[] array, int index) { if (UNALIGNED) { short v = PlatformDependent.getShort(array, index); return BIG_ENDIAN_NATIVE_ORDER ? v : Short.reverseBytes(v); } return (short) (PlatformDependent.getByte(array, index) << 8 | PlatformDependent.getByte(array, index + 1) & 0xff); }
static short getShortLE(byte[] array, int index) { if (UNALIGNED) { short v = PlatformDependent.getShort(array, index); return BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(v) : v; } return (short) (PlatformDependent.getByte(array, index) & 0xff | PlatformDependent.getByte(array, index + 1) << 8); }
static void setShort(byte[] array, int index, int value) { if (UNALIGNED) { PlatformDependent.putShort(array, index, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value)); } else { PlatformDependent.putByte(array, index, (byte) (value >>> 8)); PlatformDependent.putByte(array, index + 1, (byte) value); } }
static void setMedium(long address, int value) { PlatformDependent.putByte(address, (byte) (value >>> 16)); if (UNALIGNED) { PlatformDependent.putShort(address + 1, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value)); } else { PlatformDependent.putByte(address + 1, (byte) (value >>> 8)); PlatformDependent.putByte(address + 2, (byte) value); } }
static void setMediumLE(long address, int value) { PlatformDependent.putByte(address, (byte) value); if (UNALIGNED) { PlatformDependent.putShort(address + 1, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) (value >>> 8)) : (short) (value >>> 8)); } else { PlatformDependent.putByte(address + 1, (byte) (value >>> 8)); PlatformDependent.putByte(address + 2, (byte) (value >>> 16)); } }
static void setMedium(byte[] array, int index, int value) { PlatformDependent.putByte(array, index, (byte) (value >>> 16)); if (UNALIGNED) { PlatformDependent.putShort(array, index + 1, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value)); } else { PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8)); PlatformDependent.putByte(array, index + 2, (byte) value); } }
static void setMediumLE(byte[] array, int index, int value) { PlatformDependent.putByte(array, index, (byte) value); if (UNALIGNED) { PlatformDependent.putShort(array, index + 1, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) (value >>> 8)) : (short) (value >>> 8)); } else { PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8)); PlatformDependent.putByte(array, index + 2, (byte) (value >>> 16)); } }
static int getUnsignedMediumLE(long address) { if (UNALIGNED) { return (PlatformDependent.getByte(address) & 0xff) | ((BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(PlatformDependent.getShort(address + 1)) : PlatformDependent.getShort(address + 1)) & 0xffff) << 8; } return PlatformDependent.getByte(address) & 0xff | (PlatformDependent.getByte(address + 1) & 0xff) << 8 | (PlatformDependent.getByte(address + 2) & 0xff) << 16; }
static int getUnsignedMedium(byte[] array, int index) { if (UNALIGNED) { return (PlatformDependent.getByte(array, index) & 0xff) << 16 | (BIG_ENDIAN_NATIVE_ORDER ? PlatformDependent.getShort(array, index + 1) : Short.reverseBytes(PlatformDependent.getShort(array, index + 1))) & 0xffff; } return (PlatformDependent.getByte(array, index) & 0xff) << 16 | (PlatformDependent.getByte(array, index + 1) & 0xff) << 8 | PlatformDependent.getByte(array, index + 2) & 0xff; }
static int getUnsignedMedium(long address) { if (UNALIGNED) { return (PlatformDependent.getByte(address) & 0xff) << 16 | (BIG_ENDIAN_NATIVE_ORDER ? PlatformDependent.getShort(address + 1) : Short.reverseBytes(PlatformDependent.getShort(address + 1))) & 0xffff; } return (PlatformDependent.getByte(address) & 0xff) << 16 | (PlatformDependent.getByte(address + 1) & 0xff) << 8 | PlatformDependent.getByte(address + 2) & 0xff; }
static int getUnsignedMediumLE(byte[] array, int index) { if (UNALIGNED) { return (PlatformDependent.getByte(array, index) & 0xff) | ((BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(PlatformDependent.getShort(array, index + 1)) : PlatformDependent.getShort(array, index + 1)) & 0xffff) << 8; } return PlatformDependent.getByte(array, index) & 0xff | (PlatformDependent.getByte(array, index + 1) & 0xff) << 8 | (PlatformDependent.getByte(array, index + 2) & 0xff) << 16; }