Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.serializers; |
| 2 | |
| 3 | import org.onlab.onos.net.DeviceId; |
| 4 | import org.onlab.onos.net.HostLocation; |
| 5 | import org.onlab.onos.net.PortNumber; |
| 6 | |
| 7 | import com.esotericsoftware.kryo.Kryo; |
| 8 | import com.esotericsoftware.kryo.Serializer; |
| 9 | import com.esotericsoftware.kryo.io.Input; |
| 10 | import com.esotericsoftware.kryo.io.Output; |
| 11 | |
| 12 | /** |
| 13 | * Kryo Serializer for {@link HostLocation}. |
| 14 | */ |
| 15 | public class HostLocationSerializer extends Serializer<HostLocation> { |
| 16 | |
| 17 | /** |
| 18 | * Creates {@link HostLocation} serializer instance. |
| 19 | */ |
| 20 | public HostLocationSerializer() { |
| 21 | // non-null, immutable |
| 22 | super(false, true); |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public void write(Kryo kryo, Output output, HostLocation object) { |
| 27 | kryo.writeClassAndObject(output, object.deviceId()); |
| 28 | kryo.writeClassAndObject(output, object.port()); |
| 29 | output.writeLong(object.time()); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) { |
| 34 | DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); |
| 35 | PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input); |
| 36 | long time = input.readLong(); |
| 37 | return new HostLocation(deviceId, portNumber, time); |
| 38 | } |
| 39 | |
| 40 | } |