First commit

This commit is contained in:
Andrea Cavalli 2021-06-08 01:59:21 +02:00
commit e57088c0dd
44 changed files with 2177 additions and 0 deletions

50
.github/workflows/maven-publish.yml vendored Normal file
View File

@ -0,0 +1,50 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
name: Maven Package
on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
jobs:
build:
strategy:
matrix:
include:
- { os: ubuntu-20.04, arch: "linux/amd64" }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Setup variables
shell: bash
run: |
# ====== Variables
export REVISION=${{ github.run_number }}
echo "REVISION=$REVISION" >> $GITHUB_ENV
- name: Set up JDK 16
if: github.ref == 'refs/heads/master'
uses: actions/setup-java@v1
with:
java-version: 16
server-id: mchv-release-distribution
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}
- name: Deploy to Maven (Release)
if: github.ref == 'refs/heads/master'
shell: bash
run: |
echo "REVISION: $REVISION"
mvn -B -Drevision=${REVISION} clean deploy
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target/
*.iml

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Data generator runtime
======================
Dependency of data-generator

116
pom.xml Normal file
View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Data generator runtime</name>
<groupId>it.cavallium</groupId>
<artifactId>data-generator-runtime</artifactId>
<version>1.0.${revision}</version>
<packaging>jar</packaging>
<properties>
<revision>0-SNAPSHOT</revision>
</properties>
<repositories>
<repository>
<id>mchv-release</id>
<name>MCHV Release Apache Maven Packages</name>
<url>https://mvn.mchv.eu/repository/mchv</url>
</repository>
<repository>
<id>mchv-snapshot</id>
<name>MCHV Snapshot Apache Maven Packages</name>
<url>https://mvn.mchv.eu/repository/mchv-snapshot</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>mchv-release-distribution</id>
<name>MCHV Release Apache Maven Packages Distribution</name>
<url>https://mvn.mchv.eu/repository/mchv</url>
</repository>
<snapshotRepository>
<id>mchv-snapshot-distribution</id>
<name>MCHV Snapshot Apache Maven Packages Distribution</name>
<url>https://mvn.mchv.eu/repository/mchv-snapshot</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator-runtime.git</connection>
<developerConnection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator-runtime.git</developerConnection>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.0-M1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -0,0 +1,13 @@
package it.cavallium.data.generator;
public class CommonField {
public final String fieldName;
public final String fieldType;
public final boolean hasSetter;
public CommonField(String fieldName, String fieldType, boolean hasSetter) {
this.fieldName = fieldName;
this.fieldType = fieldType;
this.hasSetter = hasSetter;
}
}

View File

@ -0,0 +1,9 @@
package it.cavallium.data.generator;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataInitializer<T> {
@NotNull T initialize() throws IOException;
}

View File

@ -0,0 +1,13 @@
package it.cavallium.data.generator;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataSerializer<T> {
void serialize(DataOutput dataOutput, @NotNull T data) throws IOException;
@NotNull T deserialize(DataInput dataInput) throws IOException;
}

View File

@ -0,0 +1,9 @@
package it.cavallium.data.generator;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataUpgrader<T, U> {
@NotNull U upgrade(@NotNull T data) throws IOException;
}

View File

@ -0,0 +1,50 @@
package it.cavallium.data.generator;
public class Nullable<T> {
private static final long serialVersionUID = 1L;
private final T value;
public Nullable(T value) {
this.value = value;
}
public static <T> Nullable<T> of(T value) {
if (value == null) {
throw new NullPointerException();
} else {
return new Nullable<>(value);
}
}
public static <T> Nullable<T> ofNullable(T value) {
return new Nullable<>(value);
}
public static <T> Nullable<T> empty() {
return new Nullable<>(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@org.jetbrains.annotations.NotNull
public T get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
@org.jetbrains.annotations.Nullable
public T getNullable() {
return value;
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class ArrayInt52Serializer implements DataSerializer< List<Int52>> {
@Override
public void serialize(DataOutput dataOutput, List<Int52> data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
Int52Serializer.INSTANCE.serialize(dataOutput, data.get(i));
}
}
@NotNull
@Override
public List<Int52> deserialize(DataInput dataInput) throws IOException {
var data = new Int52[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = Int52Serializer.INSTANCE.deserialize(dataInput);
}
return List.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class ArrayStringSerializer implements DataSerializer<List<String>> {
@Override
public void serialize(DataOutput dataOutput, @NotNull List<String> data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeUTF(data.get(i));
}
}
@NotNull
@Override
public List<String> deserialize(DataInput dataInput) throws IOException {
var data = new String[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readUTF();
}
return List.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.booleans.BooleanList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraybooleanSerializer implements DataSerializer<BooleanList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull BooleanList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeBoolean(data.getBoolean(i));
}
}
@NotNull
@Override
public BooleanList deserialize(DataInput dataInput) throws IOException {
var data = new boolean[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readBoolean();
}
return BooleanList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.bytes.ByteList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraybyteSerializer implements DataSerializer<ByteList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull ByteList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeByte(data.getByte(i));
}
}
@NotNull
@Override
public ByteList deserialize(DataInput dataInput) throws IOException {
var data = new byte[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readByte();
}
return ByteList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.chars.CharList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraycharSerializer implements DataSerializer<CharList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull CharList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeChar(data.getChar(i));
}
}
@NotNull
@Override
public CharList deserialize(DataInput dataInput) throws IOException {
var data = new char[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readChar();
}
return CharList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraydoubleSerializer implements DataSerializer<DoubleList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull DoubleList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeDouble(data.getDouble(i));
}
}
@NotNull
@Override
public DoubleList deserialize(DataInput dataInput) throws IOException {
var data = new double[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readDouble();
}
return DoubleList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.floats.FloatList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayfloatSerializer implements DataSerializer<FloatList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull FloatList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeFloat(data.getFloat(i));
}
}
@NotNull
@Override
public FloatList deserialize(DataInput dataInput) throws IOException {
var data = new float[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readFloat();
}
return FloatList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.ints.IntList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayintSerializer implements DataSerializer<IntList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull IntList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeInt(data.getInt(i));
}
}
@NotNull
@Override
public IntList deserialize(DataInput dataInput) throws IOException {
var data = new int[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readInt();
}
return IntList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.longs.LongList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraylongSerializer implements DataSerializer<LongList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull LongList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeLong(data.getLong(i));
}
}
@NotNull
@Override
public LongList deserialize(DataInput dataInput) throws IOException {
var data = new long[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readLong();
}
return LongList.of(data);
}
}

View File

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.shorts.ShortList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayshortSerializer implements DataSerializer<ShortList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull ShortList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeShort(data.getShort(i));
}
}
@NotNull
@Override
public ShortList deserialize(DataInput dataInput) throws IOException {
var data = new short[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readShort();
}
return ShortList.of(data);
}
}

View File

@ -0,0 +1,5 @@
package it.cavallium.data.generator.nativedata;
public interface IGenericNullable {
Object $getNullable();
}

View File

@ -0,0 +1,90 @@
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;
public static final Int52 ZERO = new Int52(0);
private final long value;
private Int52(long value) {
this.value = value;
}
public static Int52 fromLong(long value) {
if (value < 0) {
throw new IllegalArgumentException("Only positive values are supported");
}
if (value > 0x0F_FF_FF_FF_FF_FF_FFL) {
throw new IllegalArgumentException("Only values below or equal to " + 0xFFFFFFFFFFFFFL + " are supported");
}
return new Int52(value);
}
long getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Int52 int52 = (Int52) o;
return value == int52.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
return Long.toString(value);
}
@Override
public int intValue() {
return (int) value;
}
@Override
public long longValue() {
return value;
}
@Override
public float floatValue() {
return (float) value;
}
@Override
public double doubleValue() {
return (double) value;
}
@Override
public int compareTo(@NotNull Int52 o) {
return Long.compareUnsigned(this.value, o.value);
}
}

View File

@ -0,0 +1,67 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class Int52Serializer implements DataSerializer<Int52> {
public static final Int52Serializer INSTANCE = new Int52Serializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
serializeValue(dataOutput, data);
}
@NotNull
@Override
public Int52 deserialize(DataInput dataInput) throws IOException {
return deserializeValue(dataInput);
}
public static void serializeValue(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
long value = data.getValue();
for(int i = 0; i < 7; i++) {
dataOutput.writeByte(((int)((value >> (6 - i) * 8) & (i == 0 ? 0b00001111L : 255L))));
}
}
public static Int52 deserializeValue(DataInput dataInput) throws IOException {
long value = 0;
return Int52.fromLong(
((long) dataInput.readUnsignedByte() & 0b00001111) << 48
| ((long) dataInput.readUnsignedByte()) << 40
| ((long) dataInput.readUnsignedByte() << 32)
| ((long) dataInput.readUnsignedByte() << 24)
| ((long) dataInput.readUnsignedByte()) << 16
| ((long) dataInput.readUnsignedByte()) << 8
| ((long) dataInput.readUnsignedByte())
);
}
public static byte[] toByteArray(long value) {
byte[] result = new byte[7];
for(int i = 6; i >= 0; --i) {
result[i] = (byte)((int)(value & (i == 0 ? 0b00001111L : 255L)));
value >>= 8;
}
return result;
}
public static long fromByteArray(byte[] bytes) {
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]);
}
public static long fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return ((long)b1 & 0b00001111) << 48 | ((long)b2 & 255L) << 40 | ((long)b3 & 255L) << 32 | ((long)b4 & 255L) << 24 | ((long)b5 & 255L) << 16 | ((long)b6 & 255L) << 8 | (long)b7 & 255L;
}
}

View File

@ -0,0 +1,102 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableInt52 implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Int52 value;
public NullableInt52(Int52 value) {
this.value = value;
}
public static NullableInt52 of(@NotNull Int52 value) {
return new NullableInt52(value);
}
public static NullableInt52 ofNullable(@Nullable Int52 value) {
return new NullableInt52(value);
}
public static <T> NullableInt52 empty() {
return new NullableInt52(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@NotNull
public Int52 get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public Int52 orElse(Int52 defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Object $getNullable() {
return this.getNullable();
}
@Nullable
public Int52 getNullable() {
return value;
}
@Nullable
public Int52 getNullable(Int52 defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public NullableInt52 clone() {
if (value != null) {
return NullableInt52.of(value);
} else {
return NullableInt52.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (NullableInt52) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,37 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableInt52Serializer implements DataSerializer<NullableInt52> {
public static final NullableInt52Serializer INSTANCE = new NullableInt52Serializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull NullableInt52 data) throws IOException {
// 0b10000000 = empty, 0b00000000 = with value
if (data.isEmpty()) {
dataOutput.writeByte(0b10000000);
} else {
dataOutput.write(Int52Serializer.toByteArray(data.get().getValue()));
}
}
@NotNull
@Override
public NullableInt52 deserialize(DataInput dataInput) throws IOException {
// 0b10000000 = empty, 0b00000000 = with value
byte firstByteAndIsPresent = dataInput.readByte();
if ((firstByteAndIsPresent & 0b10000000) != 0) {
return NullableInt52.empty();
} else {
byte[] secondPart = new byte[7];
secondPart[0] = (byte) (firstByteAndIsPresent & 0b00001111);
dataInput.readFully(secondPart, 1, secondPart.length - 1);
return NullableInt52.of(Int52.fromLong(Int52Serializer.fromByteArray(secondPart)));
}
}
}

View File

@ -0,0 +1,117 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableString implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final String value;
public NullableString(String value) {
this.value = value;
}
public static NullableString of(@NotNull String value) {
if (value == null) {
throw new NullPointerException();
} else {
return new NullableString(value);
}
}
public static NullableString ofNullable(@Nullable String value) {
return new NullableString(value);
}
public static NullableString ofNullableBlank(@Nullable String value) {
if (value == null || value.isBlank()) {
return empty();
}
return new NullableString(value);
}
public static <T> NullableString empty() {
return new NullableString(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public boolean isContentful() {
return value != null && !value.isBlank();
}
@NotNull
public String get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public String orElse(String defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public String $getNullable() {
return this.getNullable();
}
@Nullable
public String getNullable() {
return value;
}
@NotNull
public String getNullable(String defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public NullableString clone() {
if (value != null) {
return NullableString.of(value);
} else {
return NullableString.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (NullableString) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableStringSerializer implements DataSerializer<NullableString> {
public static final NullableStringSerializer INSTANCE = new NullableStringSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull NullableString data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
String dataContent = data.get();
dataOutput.writeUTF(dataContent);
}
}
@NotNull
@Override
public NullableString deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return NullableString.empty();
} else {
return NullableString.of(dataInput.readUTF());
}
}
}

View File

@ -0,0 +1,101 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullableboolean implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Boolean value;
public Nullableboolean(Boolean value) {
this.value = value;
}
public static Nullableboolean of(boolean value) {
return new Nullableboolean(value);
}
public static Nullableboolean ofNullable(@Nullable Boolean value) {
return new Nullableboolean(value);
}
public static <T> Nullableboolean empty() {
return new Nullableboolean(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public boolean get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public boolean orElse(boolean defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Boolean $getNullable() {
return this.getNullable();
}
@Nullable
public Boolean getNullable() {
return value;
}
public boolean getNullable(boolean defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullableboolean clone() {
if (value != null) {
return Nullableboolean.of(value);
} else {
return Nullableboolean.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Nullableboolean that = (Nullableboolean) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablebooleanSerializer implements DataSerializer<Nullableboolean> {
public static final NullablebooleanSerializer INSTANCE = new NullablebooleanSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableboolean data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
boolean dataContent = data.get();
dataOutput.writeBoolean(dataContent);
}
}
@NotNull
@Override
public Nullableboolean deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableboolean.empty();
} else {
return Nullableboolean.of(dataInput.readBoolean());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablebyte implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Byte value;
public Nullablebyte(Byte value) {
this.value = value;
}
public static Nullablebyte of(byte value) {
return new Nullablebyte(value);
}
public static Nullablebyte ofNullable(@Nullable Byte value) {
return new Nullablebyte(value);
}
public static <T> Nullablebyte empty() {
return new Nullablebyte(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public byte get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public byte orElse(byte defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Byte $getNullable() {
return this.getNullable();
}
@Nullable
public Byte getNullable() {
return value;
}
public byte getNullable(byte defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablebyte clone() {
if (value != null) {
return Nullablebyte.of(value);
} else {
return Nullablebyte.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Nullablebyte that = (Nullablebyte) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablebyteSerializer implements DataSerializer<Nullablebyte> {
public static final NullablebyteSerializer INSTANCE = new NullablebyteSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablebyte data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
byte dataContent = data.get();
dataOutput.writeByte(dataContent);
}
}
@NotNull
@Override
public Nullablebyte deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablebyte.empty();
} else {
return Nullablebyte.of(dataInput.readByte());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablechar implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Character value;
public Nullablechar(Character value) {
this.value = value;
}
public static Nullablechar of(char value) {
return new Nullablechar(value);
}
public static Nullablechar ofNullable(@Nullable Character value) {
return new Nullablechar(value);
}
public static <T> Nullablechar empty() {
return new Nullablechar(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public char get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public char orElse(char defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Character $getNullable() {
return this.getNullable();
}
@Nullable
public Character getNullable() {
return value;
}
public char getNullable(char defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablechar clone() {
if (value != null) {
return Nullablechar.of(value);
} else {
return Nullablechar.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullablechar) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablecharSerializer implements DataSerializer<Nullablechar> {
public static final NullablecharSerializer INSTANCE = new NullablecharSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablechar data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
char dataContent = data.get();
dataOutput.writeChar(dataContent);
}
}
@NotNull
@Override
public Nullablechar deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablechar.empty();
} else {
return Nullablechar.of(dataInput.readChar());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullabledouble implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Double value;
public Nullabledouble(Double value) {
this.value = value;
}
public static Nullabledouble of(double value) {
return new Nullabledouble(value);
}
public static Nullabledouble ofNullable(@Nullable Double value) {
return new Nullabledouble(value);
}
public static <T> Nullabledouble empty() {
return new Nullabledouble(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public double get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public double orElse(double defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Double $getNullable() {
return this.getNullable();
}
@Nullable
public Double getNullable() {
return value;
}
public double getNullable(double defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullabledouble clone() {
if (value != null) {
return Nullabledouble.of(value);
} else {
return Nullabledouble.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullabledouble) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullabledoubleSerializer implements DataSerializer<Nullabledouble> {
public static final NullabledoubleSerializer INSTANCE = new NullabledoubleSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullabledouble data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
double dataContent = data.get();
dataOutput.writeDouble(dataContent);
}
}
@NotNull
@Override
public Nullabledouble deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullabledouble.empty();
} else {
return Nullabledouble.of(dataInput.readDouble());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablefloat implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Float value;
public Nullablefloat(Float value) {
this.value = value;
}
public static Nullablefloat of(float value) {
return new Nullablefloat(value);
}
public static Nullablefloat ofNullable(@Nullable Float value) {
return new Nullablefloat(value);
}
public static <T> Nullablefloat empty() {
return new Nullablefloat(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public float get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public float orElse(float defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Object $getNullable() {
return this.getNullable();
}
@Nullable
public Float getNullable() {
return value;
}
public float getNullable(float defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablefloat clone() {
if (value != null) {
return Nullablefloat.of(value);
} else {
return Nullablefloat.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullablefloat) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablefloatSerializer implements DataSerializer<Nullablefloat> {
public static final NullablefloatSerializer INSTANCE = new NullablefloatSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablefloat data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
float dataContent = data.get();
dataOutput.writeFloat(dataContent);
}
}
@NotNull
@Override
public Nullablefloat deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablefloat.empty();
} else {
return Nullablefloat.of(dataInput.readFloat());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullableint implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Integer value;
public Nullableint(Integer value) {
this.value = value;
}
public static Nullableint of(int value) {
return new Nullableint(value);
}
public static Nullableint ofNullable(@Nullable Integer value) {
return new Nullableint(value);
}
public static <T> Nullableint empty() {
return new Nullableint(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public int get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public int orElse(int defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Integer $getNullable() {
return this.getNullable();
}
@Nullable
public Integer getNullable() {
return value;
}
public int getNullable(int defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullableint clone() {
if (value != null) {
return Nullableint.of(value);
} else {
return Nullableint.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullableint) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableintSerializer implements DataSerializer<Nullableint> {
public static final NullableintSerializer INSTANCE = new NullableintSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableint data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
int dataContent = data.get();
dataOutput.writeInt(dataContent);
}
}
@NotNull
@Override
public Nullableint deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableint.empty();
} else {
return Nullableint.of(dataInput.readInt());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablelong implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Long value;
public Nullablelong(Long value) {
this.value = value;
}
public static Nullablelong of(long value) {
return new Nullablelong(value);
}
public static Nullablelong ofNullable(@Nullable Long value) {
return new Nullablelong(value);
}
public static <T> Nullablelong empty() {
return new Nullablelong(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public long get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public long orElse(long defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Long $getNullable() {
return this.getNullable();
}
@Nullable
public Long getNullable() {
return value;
}
public long getNullable(long defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablelong clone() {
if (value != null) {
return Nullablelong.of(value);
} else {
return Nullablelong.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullablelong) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablelongSerializer implements DataSerializer<Nullablelong> {
public static final NullablelongSerializer INSTANCE = new NullablelongSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablelong data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
long dataContent = data.get();
dataOutput.writeLong(dataContent);
}
}
@NotNull
@Override
public Nullablelong deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablelong.empty();
} else {
return Nullablelong.of(dataInput.readLong());
}
}
}

View File

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullableshort implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Short value;
public Nullableshort(Short value) {
this.value = value;
}
public static Nullableshort of(short value) {
return new Nullableshort(value);
}
public static Nullableshort ofNullable(@Nullable Short value) {
return new Nullableshort(value);
}
public static <T> Nullableshort empty() {
return new Nullableshort(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public short get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public short orElse(short defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Short $getNullable() {
return this.getNullable();
}
@Nullable
public Short getNullable() {
return value;
}
public short getNullable(short defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullableshort clone() {
if (value != null) {
return Nullableshort.of(value);
} else {
return Nullableshort.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullableshort) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableshortSerializer implements DataSerializer<Nullableshort> {
public static final NullableshortSerializer INSTANCE = new NullableshortSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableshort data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
short dataContent = data.get();
dataOutput.writeShort(dataContent);
}
}
@NotNull
@Override
public Nullableshort deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableshort.empty();
} else {
return Nullableshort.of(dataInput.readShort());
}
}
}

View File

@ -0,0 +1,28 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.jetbrains.annotations.NotNull;
public class StringSerializer implements DataSerializer<String> {
public static final StringSerializer INSTANCE = new StringSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull String data) throws IOException {
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
dataOutput.writeInt(bytes.length);
dataOutput.write(bytes);
}
@NotNull
@Override
public String deserialize(DataInput dataInput) throws IOException {
byte[] bytes = new byte[dataInput.readInt()];
dataInput.readFully(bytes);
return new String(bytes, StandardCharsets.UTF_8);
}
}

View File

@ -0,0 +1,69 @@
package it.cavallium.data.generator.nativedata;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestInt52Serializer {
@Test
public void testInt52Serialization() throws IOException {
for (int i = 0; i <= 300; i++) {
testInt52Serialization(i);
}
testInt52Serialization(0xF_FF_FF_FF_FF_FF_FFL);
}
public void testInt52Serialization(long n) throws IOException {
var serializer = new Int52Serializer();
byte[] out;
try (var baos = new ByteArrayOutputStream()) {
try (var dos = new DataOutputStream(baos)) {
serializer.serialize(dos, Int52.fromLong(n));
}
out = baos.toByteArray();
}
var bais = new ByteArrayInputStream(out);
var dis = new DataInputStream(bais);
Assertions.assertEquals(n, serializer.deserialize(dis).longValue(), "Deserialized number differ");
}
@Test
public void testInt52OptionalSerialization() throws IOException {
testInt52OptionalSerialization(null);
for (long i = 0; i <= 300; i++) {
testInt52OptionalSerialization(i);
}
testInt52OptionalSerialization(0xF_FF_FF_FF_FF_FF_FFL);
}
public void testInt52OptionalSerialization(@Nullable Long n) throws IOException {
var serializer = new NullableInt52Serializer();
byte[] out;
try (var baos = new ByteArrayOutputStream()) {
try (var dos = new DataOutputStream(baos)) {
if (n == null) {
serializer.serialize(dos, NullableInt52.empty());
} else {
serializer.serialize(dos, NullableInt52.of(Int52.fromLong(n)));
}
}
out = baos.toByteArray();
}
var bais = new ByteArrayInputStream(out);
var dis = new DataInputStream(bais);
if (n == null) {
Assertions.assertNull(serializer.deserialize(dis).getNullable(), "Deserialized number is not empty");
} else {
Assertions.assertEquals(n, serializer.deserialize(dis).get().longValue(), "Deserialized number differ");
}
}
}