From 28c905a7365a37d0874b865f513c64b31d8679f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Mon, 6 Jan 2020 20:10:50 +0100 Subject: Add custom serialization to type collection --- .../mimuw/cloudatlas/agent/modules/UDUPSerializer.java | 18 ++++++++++++++---- .../java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/UDUPSerializer.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/UDUPSerializer.java index 79236ca..40c4d7c 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/UDUPSerializer.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/UDUPSerializer.java @@ -12,6 +12,8 @@ import java.io.ByteArrayOutputStream; import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedHashMap; /** @@ -69,24 +71,32 @@ public class UDUPSerializer { kryo.register(ValueList.class, new Serializer() { @Override public void write(Kryo kryo, Output output, Object object) { - + ValueList vl = (ValueList) object; + kryo.writeObject(output, ((TypeCollection) vl.getType()).getElementType()); + kryo.writeObject(output, vl.getValue()); } @Override public Object read(Kryo kryo, Input input, Class type) { - return null; + Type t = kryo.readObject(input, Type.class); + ArrayList list = kryo.readObject(input, ArrayList.class); + return new ValueList(list, t); } }); kryo.register(ValueSet.class, new Serializer() { @Override public void write(Kryo kryo, Output output, Object object) { - + ValueSet vs = (ValueSet) object; + kryo.writeObject(output, ((TypeCollection) vs.getType()).getElementType()); + kryo.writeObject(output, vs.getValue()); } @Override public Object read(Kryo kryo, Input input, Class type) { - return null; + Type t = kryo.readObject(input, Type.class); + HashSet set = kryo.readObject(input, HashSet.class); + return new ValueSet(set, t); } }); diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java index c4bb8e7..8809312 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/UDUPTest.java @@ -14,6 +14,8 @@ import pl.edu.mimuw.cloudatlas.model.ValueInt; import java.net.InetAddress; import java.net.UnknownHostException; +// TODO add serialization tests that target custom serializers (type collections!) + public class UDUPTest { @Test -- cgit v1.2.3