Skip to content

Commit

Permalink
remove CBDSSerialized.java as it was unused, fixed IUnNamedDeserializ…
Browse files Browse the repository at this point in the history
…er not decompressing bytes.
  • Loading branch information
Mr-Zombii committed Dec 6, 2024
1 parent ed31e46 commit 2cdbcd8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {
Expand Down

This file was deleted.

64 changes: 42 additions & 22 deletions src/test/java/com/github/nightfall/cbds/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,34 +77,18 @@ public <K, V> IObjectMap<K, V> create(IObjectMap<K, V> 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");

Expand Down Expand Up @@ -145,16 +130,51 @@ public <K, V> IObjectMap<K, V> create(IObjectMap<K, V> 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");
}
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/com/github/nightfall/cbds/objects/TestObject.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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;

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];
Expand Down Expand Up @@ -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");

}
}

0 comments on commit 2cdbcd8

Please sign in to comment.