Yuta HIGUCHI | 497c884 | 2014-09-25 14:23:34 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.store.serializers; |
| 2 | |
| 3 | import org.onlab.onos.net.ElementId; |
| 4 | import org.onlab.onos.store.impl.OnosTimestamp; |
| 5 | |
| 6 | import com.esotericsoftware.kryo.Kryo; |
| 7 | import com.esotericsoftware.kryo.Serializer; |
| 8 | import com.esotericsoftware.kryo.io.Input; |
| 9 | import com.esotericsoftware.kryo.io.Output; |
| 10 | |
| 11 | /** |
| 12 | * Kryo Serializer for {@link OnosTimestamp}. |
| 13 | */ |
| 14 | public class OnosTimestampSerializer extends Serializer<OnosTimestamp> { |
| 15 | |
| 16 | /** |
| 17 | * Default constructor. |
| 18 | */ |
| 19 | public OnosTimestampSerializer() { |
| 20 | // non-null, immutable |
| 21 | super(false, true); |
| 22 | } |
| 23 | @Override |
| 24 | public void write(Kryo kryo, Output output, OnosTimestamp object) { |
| 25 | kryo.writeClassAndObject(output, object.id()); |
| 26 | output.writeInt(object.termNumber()); |
| 27 | output.writeInt(object.sequenceNumber()); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public OnosTimestamp read(Kryo kryo, Input input, Class<OnosTimestamp> type) { |
| 32 | ElementId id = (ElementId) kryo.readClassAndObject(input); |
| 33 | final int term = input.readInt(); |
| 34 | final int sequence = input.readInt(); |
| 35 | return new OnosTimestamp(id, term, sequence); |
| 36 | } |
| 37 | } |