Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 1 | package org.onlab.onos.store.serializers; |
| 2 | |
| 3 | import org.onlab.onos.net.MastershipRole; |
| 4 | |
| 5 | import com.esotericsoftware.kryo.Kryo; |
| 6 | import com.esotericsoftware.kryo.Serializer; |
| 7 | import com.esotericsoftware.kryo.io.Input; |
| 8 | import com.esotericsoftware.kryo.io.Output; |
| 9 | |
| 10 | /** |
| 11 | * Kryo Serializer for {@link org.onlab.onos.net.MastershipRole}. |
| 12 | */ |
| 13 | public class MastershipRoleSerializer extends Serializer<MastershipRole> { |
| 14 | |
Yuta HIGUCHI | 03fec1f | 2014-10-03 09:13:50 -0700 | [diff] [blame] | 15 | /** |
| 16 | * Creates {@link MastershipRole} serializer instance. |
| 17 | */ |
| 18 | public MastershipRoleSerializer() { |
| 19 | // non-null, immutable |
| 20 | super(false, true); |
| 21 | } |
| 22 | |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 23 | @Override |
| 24 | public MastershipRole read(Kryo kryo, Input input, Class<MastershipRole> type) { |
| 25 | final String role = kryo.readObject(input, String.class); |
| 26 | return MastershipRole.valueOf(role); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public void write(Kryo kryo, Output output, MastershipRole object) { |
| 31 | kryo.writeObject(output, object.toString()); |
| 32 | } |
| 33 | |
| 34 | } |