Yuta HIGUCHI | a8a53eb | 2014-09-25 17:47:55 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.serializers; |
| 2 | |
| 3 | import org.onlab.onos.net.ConnectPoint; |
| 4 | import org.onlab.onos.net.DefaultLink; |
| 5 | import org.onlab.onos.net.Link.Type; |
| 6 | import org.onlab.onos.net.provider.ProviderId; |
| 7 | |
| 8 | import com.esotericsoftware.kryo.Kryo; |
| 9 | import com.esotericsoftware.kryo.Serializer; |
| 10 | import com.esotericsoftware.kryo.io.Input; |
| 11 | import com.esotericsoftware.kryo.io.Output; |
| 12 | |
| 13 | /** |
| 14 | * Kryo Serializer for {@link DefaultLink}. |
| 15 | */ |
| 16 | public class DefaultLinkSerializer extends Serializer<DefaultLink> { |
| 17 | |
| 18 | /** |
| 19 | * Default constructor. |
| 20 | */ |
| 21 | public DefaultLinkSerializer() { |
| 22 | // non-null, immutable |
| 23 | super(false, true); |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | public void write(Kryo kryo, Output output, DefaultLink object) { |
| 28 | kryo.writeClassAndObject(output, object.providerId()); |
| 29 | kryo.writeClassAndObject(output, object.src()); |
| 30 | kryo.writeClassAndObject(output, object.dst()); |
| 31 | kryo.writeClassAndObject(output, object.type()); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public DefaultLink read(Kryo kryo, Input input, Class<DefaultLink> type) { |
| 36 | ProviderId providerId = (ProviderId) kryo.readClassAndObject(input); |
| 37 | ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input); |
| 38 | ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input); |
| 39 | Type linkType = (Type) kryo.readClassAndObject(input); |
| 40 | return new DefaultLink(providerId, src, dst, linkType); |
| 41 | } |
| 42 | } |