Fix int52

This commit is contained in:
Andrea Cavalli 2021-03-11 00:09:29 +01:00
parent 1512bf490a
commit 2dfd2cc86e
2 changed files with 15 additions and 1 deletions

View File

@ -1,10 +1,24 @@
package it.cavallium.data.generator.nativedata;
import java.lang.annotation.Native;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
public class Int52 extends Number implements Comparable<Int52> {
/**
* The number of bits used to represent a {@code Int52} value in two's
* complement binary form.
*/
@Native
public static final int SIZE = 52;
/**
* The number of bytes used to represent a {@code Int52} value in two's
* complement binary form.
*/
public static final int BYTES = 7;
private final long value;
private Int52(long value) {

View File

@ -35,7 +35,7 @@ public class Int52Serializer implements DataSerializer<Int52> {
}
public static long fromByteArray(byte[] bytes) {
if (bytes.length != 8) {
if (bytes.length != 7) {
throw new IllegalArgumentException("Size must be 7, got " + bytes.length + " instead");
}
return fromBytes((byte) (bytes[0] & 0b00001111), bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]);