From 2cdbcd8cdfaf621d27827fa1591611b2f043f5f5 Mon Sep 17 00:00:00 2001 From: Mr Zombii Date: Fri, 6 Dec 2024 15:16:45 -0600 Subject: [PATCH] remove CBDSSerialized.java as it was unused, fixed IUnNamedDeserializer not decompressing bytes. --- .../io/serial/api/IUnNamedDeserializer.java | 7 +- .../cbds/io/serial/obj/CBDSSerialized.java | 12 ---- .../java/com/github/nightfall/cbds/Main.java | 64 ++++++++++++------- .../nightfall/cbds/objects/TestObject.java | 15 ++++- 4 files changed, 62 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/com/github/nightfall/cbds/io/serial/obj/CBDSSerialized.java diff --git a/src/main/java/com/github/nightfall/cbds/io/serial/api/IUnNamedDeserializer.java b/src/main/java/com/github/nightfall/cbds/io/serial/api/IUnNamedDeserializer.java index 1a55e7b..4b7cc8a 100644 --- a/src/main/java/com/github/nightfall/cbds/io/serial/api/IUnNamedDeserializer.java +++ b/src/main/java/com/github/nightfall/cbds/io/serial/api/IUnNamedDeserializer.java @@ -3,14 +3,17 @@ import com.github.nightfall.cbds.CBDSConstants; import com.github.nightfall.cbds.io.CompoundObject; import com.github.nightfall.cbds.io.custom.IUnNamedCustomSerializable; +import com.github.nightfall.cbds.io.serial.impl.NamedBinaryDeserializer; import com.github.nightfall.cbds.io.serial.impl.UnNamedBinaryDeserializer; import com.github.nightfall.cbds.io.serial.obj.INamedSerializable; import com.github.nightfall.cbds.io.serial.obj.IDataStreamSerializable; import com.github.nightfall.cbds.io.serial.obj.IUnNamedSerializable; import com.github.nightfall.cbds.util.NativeArrayUtil; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.HashMap; +import java.util.zip.GZIPInputStream; public interface IUnNamedDeserializer { @@ -35,11 +38,13 @@ static boolean hasDeserializer(Object obj) { } static IUnNamedDeserializer createDefault(byte[] bytes, boolean isCompressed) throws IOException { + if (isCompressed) + return new UnNamedBinaryDeserializer(new GZIPInputStream(new ByteArrayInputStream(bytes)).readAllBytes()); return new UnNamedBinaryDeserializer(bytes); } static IUnNamedDeserializer createDefault(Byte[] bytes, boolean isCompressed) throws IOException { - return new UnNamedBinaryDeserializer(NativeArrayUtil.toNativeArray(bytes)); + return createDefault(NativeArrayUtil.toNativeArray(bytes), isCompressed); } default IUnNamedDeserializer newInstance(byte[] bytes) throws IOException { diff --git a/src/main/java/com/github/nightfall/cbds/io/serial/obj/CBDSSerialized.java b/src/main/java/com/github/nightfall/cbds/io/serial/obj/CBDSSerialized.java deleted file mode 100644 index fb7a538..0000000 --- a/src/main/java/com/github/nightfall/cbds/io/serial/obj/CBDSSerialized.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.nightfall.cbds.io.serial.obj; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface CBDSSerialized { - -} diff --git a/src/test/java/com/github/nightfall/cbds/Main.java b/src/test/java/com/github/nightfall/cbds/Main.java index f98346f..18f6298 100644 --- a/src/test/java/com/github/nightfall/cbds/Main.java +++ b/src/test/java/com/github/nightfall/cbds/Main.java @@ -2,6 +2,7 @@ import com.github.nightfall.cbds.cr.*; import com.github.nightfall.cbds.io.serial.api.INamedDeserializer; +import com.github.nightfall.cbds.io.serial.api.IUnNamedDeserializer; import com.github.nightfall.cbds.io.serial.api.IUnNamedSerializer; import com.github.nightfall.cbds.io.serial.impl.NamedBinaryDeserializer; import com.github.nightfall.cbds.io.serial.impl.NamedBinarySerializer; @@ -76,34 +77,18 @@ public IObjectMap create(IObjectMap srcMap) { for (int i = 0; i < objs.length; i++) objs[i] = new TestObject(); startTime = System.nanoTime(); -// for (int i = 0; i < objCount; i++) { -// serializer.writeNamedObject("testObj_" + i, new TestObject()); -//// serializer.writeLong("testLong_" + i, random.nextLong()); -//// serializer.writeString("testString0_" + i, random.nextLong() + ""); -//// serializer.writeString("testString1_" + i, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); -// } - serializer.writeNamedObjectArray("testObjs", objs); + serializer.writeUnNamedObjectArray("testObjs", objs); endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to write " + objCount + " objects to CBDS"); startTime = System.nanoTime(); - for (int i = 0; i < objCount; i++) { - userializer.writeNamedObject(new TestObject()); -// userializer.writeLong(random.nextLong()); -// userializer.writeString(random.nextLong() + ""); -// userializer.writeString("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - } + userializer.writeUnNamedObjectArray(objs); + endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to write " + objCount + " objects to UCBDS"); startTime = System.nanoTime(); crSerializer.writeObjArray("testObjs", objs); - for (int i = 0; i < objCount; i++) { -// crSerializer.writeObj("testObj_" + i, new TestObject()); -// crSerializer.writeLong("testLong_" + i, random.nextLong()); -// crSerializer.writeString("testString0_" + i, random.nextLong() + ""); -// crSerializer.writeString("testString1_" + i, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - } endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to write " + objCount + " objects to CRBIN"); @@ -145,16 +130,51 @@ public IObjectMap create(IObjectMap srcMap) { endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to deserialize CBDS"); startTime = System.nanoTime(); - deserializer.readNamedObjectArray("testObjs", TestObject.class); + deserializer.readUnNamedObjectArray("testObjs", TestObject.class); endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to read " + objCount + " item object array from CBDS"); + System.out.println(); + + startTime = System.nanoTime(); + INamedDeserializer deserializerc = INamedDeserializer.createDefault(CBDS_COMPRESSED_BYTES, true); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to deserialize COMPRESSED CBDS"); + startTime = System.nanoTime(); + deserializerc.readUnNamedObjectArray("testObjs", TestObject.class); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to read " + objCount + " item object array from COMPRESSED CBDS"); + + System.out.println(); + + startTime = System.nanoTime(); + IUnNamedDeserializer deserializer0 = IUnNamedDeserializer.createDefault(UCBDS_REGULAR_BYTES, false); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to deserialize UCBDS"); + startTime = System.nanoTime(); + deserializer0.readUnNamedObjectArray(TestObject.class); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to read " + objCount + " item object array from UCBDS"); + + System.out.println(); + + startTime = System.nanoTime(); + IUnNamedDeserializer deserializer1 = IUnNamedDeserializer.createDefault(UCBDS_COMPRESSED_BYTES, true); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to deserialize COMPRESSED UCBDS"); + startTime = System.nanoTime(); + deserializer1.readUnNamedObjectArray(TestObject.class); + endTime = System.nanoTime(); + System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to read " + objCount + " item object array from COMPRESSED UCBDS"); + + System.out.println(); + startTime = System.nanoTime(); - CRBinDeserializer deserializer1 = CRBinDeserializer.fromBase64(new String(CRBIN_B64_REGULAR_BYTES)); + CRBinDeserializer crBinDeserializer = CRBinDeserializer.fromBase64(new String(CRBIN_B64_REGULAR_BYTES)); endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to deserialize CRBIN"); startTime = System.nanoTime(); - deserializer1.readObjArray("testObjs", TestObject.class); + crBinDeserializer.readObjArray("testObjs", TestObject.class); endTime = System.nanoTime(); System.out.println("Took " + nanoToMilli(endTime - startTime) + "ms to read " + objCount + " item object array from CRBIN"); } diff --git a/src/test/java/com/github/nightfall/cbds/objects/TestObject.java b/src/test/java/com/github/nightfall/cbds/objects/TestObject.java index 0472331..0863eb9 100644 --- a/src/test/java/com/github/nightfall/cbds/objects/TestObject.java +++ b/src/test/java/com/github/nightfall/cbds/objects/TestObject.java @@ -1,9 +1,12 @@ package com.github.nightfall.cbds.objects; +import com.github.nightfall.cbds.io.serial.api.IUnNamedDeserializer; +import com.github.nightfall.cbds.io.serial.api.IUnNamedSerializer; import com.github.nightfall.cbds.io.serial.impl.NamedBinarySerializer; import com.github.nightfall.cbds.io.serial.obj.INamedSerializable; import com.github.nightfall.cbds.io.serial.api.INamedDeserializer; import com.github.nightfall.cbds.io.serial.api.INamedSerializer; +import com.github.nightfall.cbds.io.serial.obj.IUnNamedSerializable; import finalforeach.cosmicreach.savelib.crbin.CRBinDeserializer; import finalforeach.cosmicreach.savelib.crbin.CRBinSerializer; import finalforeach.cosmicreach.savelib.crbin.ICRBinSerializable; @@ -11,7 +14,7 @@ import java.io.IOException; import java.util.Random; -public class TestObject implements INamedSerializable, ICRBinSerializable { +public class TestObject implements INamedSerializable, IUnNamedSerializable, ICRBinSerializable { static final Random random = new Random(); static final long[] longs = new long[200]; @@ -48,4 +51,14 @@ public void write(CRBinSerializer serializer) { serializer.writeString("test_key2", "Hello2"); } + @Override + public void read(IUnNamedDeserializer in) throws IOException { + + } + + @Override + public void write(IUnNamedSerializer out) throws IOException { + out.writeString("Hello2"); + + } } \ No newline at end of file