Importing serializers from jelegram
This commit is contained in:
parent
2b8e26f565
commit
748d2db175
682
IntSerializers.java
Normal file
682
IntSerializers.java
Normal file
@ -0,0 +1,682 @@
|
||||
package ru.landgrafhomyak.utility;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class IntSerializers {
|
||||
private IntSerializers() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode8B(@NotNull final byte[] dst, final byte value, final int offset) {
|
||||
dst[offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode8H(@NotNull final byte[] dst, final short value, final int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode8I(@NotNull final byte[] dst, final int value, final int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode8L(@NotNull final byte[] dst, final long value, final int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16leB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = value;
|
||||
dst[++offset] = (byte) (value < 0 ? 0xFF : 0x0);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16beB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = (byte) (value < 0 ? 0xFF : 0x0);
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16leBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = value;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16beBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16leH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16beH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16leI(@NotNull final byte[] dst, final int value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16beI(@NotNull final byte[] dst, final int value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16leL(@NotNull final byte[] dst, final long value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode16beL(@NotNull final byte[] dst, final long value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = value;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = value;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value < 0 ? 0xFF : 0);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value < 0 ? 0xFF : 0);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leI(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beI(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24leL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode24beL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = value;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = value;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leI(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beI(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32leL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode32beL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = value;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beB(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = value;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beBu(@NotNull final byte[] dst, final byte value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beH(@NotNull final byte[] dst, final short value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beHu(@NotNull final byte[] dst, final short value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leI(@NotNull final byte[] dst, int value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beI(@NotNull final byte[] dst, int value, int offset) {
|
||||
final byte sign = (byte) (value < 0 ? 0xFF : 0);
|
||||
dst[offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = sign;
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leIu(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beIu(@NotNull final byte[] dst, int value, int offset) {
|
||||
dst[offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = 0;
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64leL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) value;
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 32);
|
||||
dst[++offset] = (byte) (value >>> 40);
|
||||
dst[++offset] = (byte) (value >>> 48);
|
||||
dst[++offset] = (byte) (value >>> 56);
|
||||
return dst;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static public byte[] encode64beL(@NotNull final byte[] dst, long value, int offset) {
|
||||
dst[offset] = (byte) (value >>> 56);
|
||||
dst[++offset] = (byte) (value >>> 48);
|
||||
dst[++offset] = (byte) (value >>> 40);
|
||||
dst[++offset] = (byte) (value >>> 32);
|
||||
dst[++offset] = (byte) (value >>> 24);
|
||||
dst[++offset] = (byte) (value >>> 16);
|
||||
dst[++offset] = (byte) (value >>> 8);
|
||||
dst[++offset] = (byte) value;
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
static public byte decode8B(@NotNull final byte[] src, final int offset) {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
static public short decode8H(@NotNull final byte[] src, final int offset) {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
static public short decode8Hu(@NotNull final byte[] src, final int offset) {
|
||||
return (short) (((int) src[offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode8I(@NotNull final byte[] src, final int offset) {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
static public int decode8Iu(@NotNull final byte[] src, final int offset) {
|
||||
return ((int) src[offset]) & 0xFF;
|
||||
}
|
||||
|
||||
static public long decode8L(@NotNull final byte[] src, final int offset) {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
static public long decode8Lu(@NotNull final byte[] src, final int offset) {
|
||||
return ((long) src[offset]) & 0xFF;
|
||||
}
|
||||
|
||||
static public short decode16leH(@NotNull final byte[] src, int offset) {
|
||||
return (short) ((((int) src[offset + 1]) << 8) | (((int) src[offset]) & 0xFF));
|
||||
}
|
||||
|
||||
static public short decode16beH(@NotNull final byte[] src, int offset) {
|
||||
return (short) ((((int) src[offset]) << 8) | (((int) src[offset + 1]) & 0xFF));
|
||||
}
|
||||
|
||||
static public int decode16leI(@NotNull final byte[] src, int offset) {
|
||||
return (((int) src[offset + 1]) << 8) | (((int) src[offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode16beI(@NotNull final byte[] src, final int offset) {
|
||||
return (((int) src[offset]) << 8) | (((int) src[offset + 1]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode16leIu(@NotNull final byte[] src, int offset) {
|
||||
return ((((int) src[offset + 1]) & 0xFF) << 8) | (((int) src[offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode16beIu(@NotNull final byte[] src, final int offset) {
|
||||
return ((((int) src[offset]) & 0xFF) << 8) | (((int) src[offset + 1]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode16leL(@NotNull final byte[] src, int offset) {
|
||||
return (((long) src[offset + 1]) << 8) | (((long) src[offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode16beL(@NotNull final byte[] src, final int offset) {
|
||||
return (((long) src[offset]) << 8) | (((long) src[offset + 1]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode16leLu(@NotNull final byte[] src, int offset) {
|
||||
return ((((long) src[offset + 1]) & 0xFF) << 8) | (((long) src[offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode16beLu(@NotNull final byte[] src, final int offset) {
|
||||
return ((((long) src[offset]) & 0xFF) << 8) | (((long) src[offset + 1]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode24leI(@NotNull final byte[] src, int offset) {
|
||||
int result = ((int) src[offset]) & 0xFF;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((int) src[++offset]) << 16);
|
||||
}
|
||||
|
||||
static public int decode24beI(@NotNull final byte[] src, int offset) {
|
||||
int result = ((int) src[offset]) << 16;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((int) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public int decode24leIu(@NotNull final byte[] src, int offset) {
|
||||
int result = ((int) src[offset]) & 0xFF;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
return result | ((((int) src[++offset]) & 0xFF) << 16);
|
||||
}
|
||||
|
||||
static public int decode24beIu(@NotNull final byte[] src, int offset) {
|
||||
int result = (((int) src[offset]) & 0xFF) << 16;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((int) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode24leL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) & 0xFF;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) << 16);
|
||||
}
|
||||
|
||||
static public long decode24beL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode24leLu(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) & 0xFF;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | ((((long) src[++offset]) & 0xFF) << 16);
|
||||
}
|
||||
|
||||
static public long decode24beLu(@NotNull final byte[] src, int offset) {
|
||||
long result = (((long) src[offset]) & 0xFF) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
static public int decode32leI(@NotNull final byte[] src, int offset) {
|
||||
int result = ((int) src[offset]) & 0xFF;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 16;
|
||||
return result | (((int) src[++offset]) << 24);
|
||||
}
|
||||
|
||||
static public int decode32beI(@NotNull final byte[] src, int offset) {
|
||||
int result = ((int) src[offset]) << 24;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 16;
|
||||
result |= (((int) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((int) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode32leL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) & 0xFF;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
return result | (((long) src[++offset]) << 24);
|
||||
}
|
||||
|
||||
static public long decode32beL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) << 24;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode32leLu(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) & 0xFF;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
return result | ((((long) src[++offset]) & 0xFF) << 24);
|
||||
}
|
||||
|
||||
static public long decode32beLu(@NotNull final byte[] src, int offset) {
|
||||
long result = (((long) src[offset]) & 0xFF) << 24;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) & 0xFF);
|
||||
}
|
||||
|
||||
static public long decode64leL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) & 0xFF;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 24;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 32;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 40;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 48;
|
||||
return result | ((((long) src[++offset]) & 0xFF) << 56);
|
||||
}
|
||||
|
||||
static public long decode64beL(@NotNull final byte[] src, int offset) {
|
||||
long result = ((long) src[offset]) << 56;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 48;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 40;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 32;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 24;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 16;
|
||||
result |= (((long) src[++offset]) & 0xFF) << 8;
|
||||
return result | (((long) src[++offset]) & 0xFF);
|
||||
}
|
||||
}
|
@ -0,0 +1,775 @@
|
||||
package ru.landgrafhomyak.utility
|
||||
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
@Suppress("NAME_SHADOWING", "unused", "DuplicatedCode")
|
||||
object IntSerializers {
|
||||
@JvmStatic
|
||||
fun encode8B(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
dst[offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode8H(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
dst[offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode8I(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
dst[offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode8L(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
dst[offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16leB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value
|
||||
dst[++offset] = (if (value < 0) 0xFF else 0x0).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16beB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (if (value < 0) 0xFF else 0x0).toByte()
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16leBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16beBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16leH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16beH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16leI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16beI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16leL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode16beL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = value
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = (if (value < 0) 0xFF else 0).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
dst[++offset] = (if (value < 0) 0xFF else 0).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24leL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode24beL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0x0).toByte()
|
||||
dst[offset] = value
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32leL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode32beL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = value
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beB(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beBu(dst: ByteArray, value: Byte, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = value
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beH(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beHu(dst: ByteArray, value: Short, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = (value.toInt() ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beI(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
val sign = (if (value < 0) 0xFF else 0).toByte()
|
||||
dst[offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = sign
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leIu(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beIu(dst: ByteArray, value: Int, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = 0
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64leL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = value.toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 32).toByte()
|
||||
dst[++offset] = (value ushr 40).toByte()
|
||||
dst[++offset] = (value ushr 48).toByte()
|
||||
dst[++offset] = (value ushr 56).toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun encode64beL(dst: ByteArray, value: Long, offset: Int): ByteArray {
|
||||
var offset = offset
|
||||
dst[offset] = (value ushr 56).toByte()
|
||||
dst[++offset] = (value ushr 48).toByte()
|
||||
dst[++offset] = (value ushr 40).toByte()
|
||||
dst[++offset] = (value ushr 32).toByte()
|
||||
dst[++offset] = (value ushr 24).toByte()
|
||||
dst[++offset] = (value ushr 16).toByte()
|
||||
dst[++offset] = (value ushr 8).toByte()
|
||||
dst[++offset] = value.toByte()
|
||||
return dst
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8B(src: ByteArray, offset: Int): Byte {
|
||||
return src[offset]
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8H(src: ByteArray, offset: Int): Short {
|
||||
return src[offset].toShort()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8Hu(src: ByteArray, offset: Int): Short {
|
||||
return (src[offset].toInt() and 0xFF).toShort()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8I(src: ByteArray, offset: Int): Int {
|
||||
return src[offset].toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8Iu(src: ByteArray, offset: Int): Int {
|
||||
return src[offset].toInt() and 0xFF
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8L(src: ByteArray, offset: Int): Long {
|
||||
return src[offset].toLong()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode8Lu(src: ByteArray, offset: Int): Long {
|
||||
return src[offset].toLong() and 0xFFL
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16leH(src: ByteArray, offset: Int): Short {
|
||||
return ((src[offset + 1].toInt() shl 8) or (src[offset].toInt() and 0xFF)).toShort()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16beH(src: ByteArray, offset: Int): Short {
|
||||
return ((src[offset].toInt() shl 8) or (src[offset + 1].toInt() and 0xFF)).toShort()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16leI(src: ByteArray, offset: Int): Int {
|
||||
return (src[offset + 1].toInt() shl 8) or (src[offset].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16beI(src: ByteArray, offset: Int): Int {
|
||||
return (src[offset].toInt() shl 8) or (src[offset + 1].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16leIu(src: ByteArray, offset: Int): Int {
|
||||
return ((src[offset + 1].toInt() and 0xFF) shl 8) or (src[offset].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16beIu(src: ByteArray, offset: Int): Int {
|
||||
return ((src[offset].toInt() and 0xFF) shl 8) or (src[offset + 1].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16leL(src: ByteArray, offset: Int): Long {
|
||||
return (src[offset + 1].toLong() shl 8) or (src[offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16beL(src: ByteArray, offset: Int): Long {
|
||||
return (src[offset].toLong() shl 8) or (src[offset + 1].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16leLu(src: ByteArray, offset: Int): Long {
|
||||
return ((src[offset + 1].toLong() and 0xFFL) shl 8) or (src[offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode16beLu(src: ByteArray, offset: Int): Long {
|
||||
return ((src[offset].toLong() and 0xFFL) shl 8) or (src[offset + 1].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24leI(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() and 0xFF
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
return result or (src[++offset].toInt() shl 16)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24beI(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() shl 16
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
return result or (src[++offset].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24leIu(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() and 0xFF
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
return result or (src[++offset].toInt() and 0xFF shl 16)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24beIu(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() and 0xFF shl 16
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
return result or (src[++offset].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24leL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() shl 16)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24beL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() shl 16
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24leLu(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode24beLu(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL shl 16
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32leI(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() and 0xFF
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 16)
|
||||
return result or (src[++offset].toInt() shl 24)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32beI(src: ByteArray, offset: Int): Int {
|
||||
var offset = offset
|
||||
var result = src[offset].toInt() shl 24
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 16)
|
||||
result = result or (src[++offset].toInt() and 0xFF shl 8)
|
||||
return result or (src[++offset].toInt() and 0xFF)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32leL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
return result or (src[++offset].toLong() shl 24)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32beL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() shl 24
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32leLu(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
return result or (src[++offset].toLong() and 0xFFL shl 24)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode32beLu(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL shl 24
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode64leL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() and 0xFFL
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 24)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 32)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 40)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 48)
|
||||
return result or (src[++offset].toLong() and 0xFFL shl 56)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decode64beL(src: ByteArray, offset: Int): Long {
|
||||
var offset = offset
|
||||
var result = src[offset].toLong() shl 56
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 48)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 40)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 32)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 24)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 16)
|
||||
result = result or (src[++offset].toLong() and 0xFFL shl 8)
|
||||
return result or (src[++offset].toLong() and 0xFFL)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user