Madan Jampani | fef9b3a | 2014-10-07 18:38:17 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.store.device.impl; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import org.onlab.onos.net.DeviceId; |
| 6 | import org.onlab.onos.net.device.DeviceDescription; |
| 7 | import org.onlab.onos.net.device.PortDescription; |
| 8 | import org.onlab.onos.net.provider.ProviderId; |
| 9 | import org.onlab.onos.store.common.impl.Timestamped; |
| 10 | |
| 11 | import com.esotericsoftware.kryo.Kryo; |
| 12 | import com.esotericsoftware.kryo.Serializer; |
| 13 | import com.esotericsoftware.kryo.io.Input; |
| 14 | import com.esotericsoftware.kryo.io.Output; |
| 15 | |
| 16 | /** |
| 17 | * Kryo Serializer for {@link InternalPortEvent}. |
| 18 | */ |
| 19 | public class InternalPortEventSerializer extends Serializer<InternalPortEvent> { |
| 20 | |
| 21 | /** |
| 22 | * Creates a serializer for {@link InternalPortEvent}. |
| 23 | */ |
| 24 | public InternalPortEventSerializer() { |
| 25 | // does not accept null |
| 26 | super(false); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public void write(Kryo kryo, Output output, InternalPortEvent event) { |
| 31 | kryo.writeClassAndObject(output, event.providerId()); |
| 32 | kryo.writeClassAndObject(output, event.deviceId()); |
| 33 | kryo.writeClassAndObject(output, event.portDescriptions()); |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public InternalPortEvent read(Kryo kryo, Input input, |
| 38 | Class<InternalPortEvent> type) { |
| 39 | ProviderId providerId = (ProviderId) kryo.readClassAndObject(input); |
| 40 | DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); |
| 41 | Timestamped<List<PortDescription>> portDescriptions = (Timestamped<List<PortDescription>>) kryo.readClassAndObject(input); |
| 42 | |
| 43 | return new InternalPortEvent(providerId, deviceId, portDescriptions); |
| 44 | } |
| 45 | } |