Skip to content

Commit

Permalink
I have no clue.
Browse files Browse the repository at this point in the history
I've tried switching to readObjectOrNull, I've tried optimizePositive for ints, I've tried setting immutable to false. Things change, but nothing is working...
  • Loading branch information
tommyettinger committed Mar 3, 2024
1 parent 0c3b2f7 commit bc679aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ public class Int3DirectedGraphSerializer extends Serializer<Int3DirectedGraph> {

public Int3DirectedGraphSerializer() {
setAcceptsNull(false);
setImmutable(false);
}

@Override
public void write(final Kryo kryo, final Output output, final Int3DirectedGraph data) {
Collection<PointI3> vertices = data.getVertices();
Collection<Connection<PointI3>> edges = data.internals().getConnections();
int length = vertices.size();
output.writeInt(length);
output.writeInt(length, true);
for(PointI3 v : vertices) {
System.out.println("writing hash " + System.identityHashCode(v));
kryo.writeObjectOrNull(output, v, PointI3.class);
}
length = edges.size();
output.writeInt(length);
output.writeInt(length, true);
for(Connection<PointI3> e : edges) {
kryo.writeObjectOrNull(output, e.getA(), PointI3.class);
kryo.writeObjectOrNull(output, e.getB(), PointI3.class);
Expand All @@ -58,13 +60,15 @@ public void write(final Kryo kryo, final Output output, final Int3DirectedGraph
@Override
public Int3DirectedGraph read(final Kryo kryo, final Input input, final Class<? extends Int3DirectedGraph> dataClass) {
Int3DirectedGraph graph = new Int3DirectedGraph();
int length = input.readInt();
int length = input.readInt(true);
for (int i = 0; i < length; i++) {
graph.addVertex(kryo.readObject(input, PointI3.class));
PointI3 pt = kryo.readObjectOrNull(input, PointI3.class);
System.out.println(pt);
graph.addVertex(pt);
}
length = input.readInt();
length = input.readInt(true);
for (int i = 0; i < length; i++) {
graph.addEdge(kryo.readObject(input, PointI3.class), kryo.readObject(input, PointI3.class), input.readFloat());
graph.addEdge(kryo.readObjectOrNull(input, PointI3.class), kryo.readObjectOrNull(input, PointI3.class), input.readFloat());
}
return graph;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public PointI3Serializer() {

@Override
public void write(final Kryo kryo, final Output output, final PointI3 data) {
output.writeInt(data.x);
output.writeInt(data.y);
output.writeInt(data.z);
output.writeInt(data.x, true);
output.writeInt(data.y, true);
output.writeInt(data.z, true);
}

@Override
public PointI3 read(final Kryo kryo, final Input input, final Class<? extends PointI3> dataClass) {
return new PointI3(input.readInt(), input.readInt(), input.readInt());
return new PointI3(input.readInt(true), input.readInt(true), input.readInt(true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,21 @@ public void testInt2DirectedGraph() {
kryo.register(PointI2.class, new PointI2Serializer());

int n = 5;
Graph<PointI2> data = makeGridGraph2D(new Int2DirectedGraph(), n, new PointI2());

Int2DirectedGraph data = new Int2DirectedGraph();
makeGridGraph2D(data, n, new PointI2());
System.out.println("Initial graph with length " + data.getVertices().size() + ": ");
System.out.println(data.getVertices());
System.out.println(data);
ByteArrayOutputStream baos = new ByteArrayOutputStream(32);
Output output = new Output(baos);
kryo.writeObject(output, data);
byte[] bytes = output.toBytes();
System.out.println("Int2DirectedGraph byte length: " + bytes.length);
try (Input input = new Input(bytes)) {
Int2DirectedGraph data2 = kryo.readObject(input, Int2DirectedGraph.class);
System.out.println("Read back in with length " + data2.getVertices().size() + ": ");
System.out.println(data2.getVertices());
System.out.println(data2);
Assert.assertEquals(data.numberOfComponents(), data2.numberOfComponents());
Assert.assertEquals(data.getEdgeCount(), data2.getEdgeCount());
Assert.assertEquals(new ArrayList<>(data.getVertices()), new ArrayList<>(data2.getVertices()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void testPointI3() {
try (Input input = new Input(bytes)) {
PointI3 data2 = kryo.readObject(input, PointI3.class);
Assert.assertEquals(data, data2);
// System.out.println(data + " == " + data2);
}
}
@Test
Expand Down

0 comments on commit bc679aa

Please sign in to comment.