diff --git a/gradle.properties b/gradle.properties index a05105f4..da54ad79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ kryoVersion=5.5.0 funderbyVersion=0.1.1 regexodusVersion=0.1.15 digitalVersion=0.4.5 -juniperVersion=0.4.2 +juniperVersion=0.5.0 jdkgdxdsVersion=1.4.4 simpleGraphsVersion=v5.1.1 diff --git a/kryo-juniper/build.gradle b/kryo-juniper/build.gradle index 1dcfb824..de014116 100644 --- a/kryo-juniper/build.gradle +++ b/kryo-juniper/build.gradle @@ -30,7 +30,7 @@ compileTestJava { } dependencies { - api "com.github.tommyettinger:kryo-digital:0.4.3.0" + api "com.github.tommyettinger:kryo-digital:0.4.5.0" api "com.esotericsoftware:kryo:$kryoVersion" api "com.github.tommyettinger:juniper:$juniperVersion" testImplementation "junit:junit:4.13.2" diff --git a/kryo-juniper/gradle.properties b/kryo-juniper/gradle.properties index ef3adfd5..2dd48532 100644 --- a/kryo-juniper/gradle.properties +++ b/kryo-juniper/gradle.properties @@ -19,4 +19,4 @@ POM_ARTIFACT_ID=kryo-juniper POM_NAME=kryo-juniper POM_DESCRIPTION=Kryo 5.x serializers for juniper types POM_INCEPTION_YEAR=2022 -VERSION_NAME=0.4.2.0 +VERSION_NAME=0.5.0.0-SNAPSHOT diff --git a/kryo-juniper/src/main/java/com/github/tommyettinger/kryo/juniper/FlowRandomSerializer.java b/kryo-juniper/src/main/java/com/github/tommyettinger/kryo/juniper/FlowRandomSerializer.java new file mode 100644 index 00000000..aaf716d6 --- /dev/null +++ b/kryo-juniper/src/main/java/com/github/tommyettinger/kryo/juniper/FlowRandomSerializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2023 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.github.tommyettinger.kryo.juniper; + +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.Serializer; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; +import com.github.tommyettinger.random.FlowRandom; + +/** + * Kryo {@link Serializer} for juniper {@link FlowRandom}s. + */ +public class FlowRandomSerializer extends Serializer { + + public FlowRandomSerializer() { + setImmutable(false); + setAcceptsNull(false); + } + + @Override + public void write(final Kryo kryo, final Output output, final FlowRandom data) { + output.writeVarLong(data.getStateA(), false); + output.writeVarLong(data.getStateB(), false); + } + + @Override + public FlowRandom read(final Kryo kryo, final Input input, final Class dataClass) { + return new FlowRandom(input.readVarLong(false), input.readVarLong(false)); + } + + @Override + public FlowRandom copy(Kryo kryo, FlowRandom original) { + return original.copy(); + } +} \ No newline at end of file diff --git a/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/DistributionTest.java b/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/DistributionTest.java index 5f09b778..409ea487 100644 --- a/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/DistributionTest.java +++ b/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/DistributionTest.java @@ -73,7 +73,7 @@ public void testDistributions() throws NoSuchMethodException, InvocationTargetEx for (Map.Entry, Class>> ent : mapping.entrySet()) { Kryo kryo = new Kryo(); - kryo.register(WhiskerRandom.class, new WhiskerRandomSerializer()); + kryo.register(AceRandom.class, new AceRandomSerializer()); kryo.register(ent.getKey(), ent.getValue().getDeclaredConstructor().newInstance()); Distribution data = ent.getKey().getDeclaredConstructor().newInstance(); diff --git a/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/RandomTest.java b/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/RandomTest.java index f4d1f2cc..6f3853d6 100644 --- a/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/RandomTest.java +++ b/kryo-juniper/src/test/java/com/github/tommyettinger/kryo/juniper/RandomTest.java @@ -160,7 +160,26 @@ public void testMizuchiRandom() { Assert.assertEquals(data, data2); } } - + + @Test + public void testFlowRandom() { + Kryo kryo = new Kryo(); + kryo.register(FlowRandom.class, new FlowRandomSerializer()); + + FlowRandom data = new FlowRandom(-12345L); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(32); + Output output = new Output(baos); + kryo.writeObject(output, data); + byte[] bytes = output.toBytes(); + try (Input input = new Input(bytes)) { + FlowRandom data2 = kryo.readObject(input, FlowRandom.class); + Assert.assertEquals(data.nextInt(), data2.nextInt()); + Assert.assertEquals(data.nextLong(), data2.nextLong()); + Assert.assertEquals(data, data2); + } + } + @Test public void testRomuTrioRandom() { Kryo kryo = new Kryo();