From 2dfd2cc86e9a5957426492dba156fd892fc2bfce Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 11 Mar 2021 00:09:29 +0100 Subject: [PATCH] Fix int52 --- .../cavallium/data/generator/nativedata/Int52.java | 14 ++++++++++++++ .../data/generator/nativedata/Int52Serializer.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/cavallium/data/generator/nativedata/Int52.java b/src/main/java/it/cavallium/data/generator/nativedata/Int52.java index 2a594e4..15da0ce 100644 --- a/src/main/java/it/cavallium/data/generator/nativedata/Int52.java +++ b/src/main/java/it/cavallium/data/generator/nativedata/Int52.java @@ -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 { + /** + * 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) { diff --git a/src/main/java/it/cavallium/data/generator/nativedata/Int52Serializer.java b/src/main/java/it/cavallium/data/generator/nativedata/Int52Serializer.java index 1f183f2..8239835 100644 --- a/src/main/java/it/cavallium/data/generator/nativedata/Int52Serializer.java +++ b/src/main/java/it/cavallium/data/generator/nativedata/Int52Serializer.java @@ -35,7 +35,7 @@ public class Int52Serializer implements DataSerializer { } 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]);