Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yuta HIGUCHI | 273dcc8 | 2014-10-03 00:32:12 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.serializers; |
| 17 | |
Yuta HIGUCHI | 8ce0873 | 2014-10-11 10:40:45 -0700 | [diff] [blame] | 18 | import org.onlab.onos.store.impl.MastershipBasedTimestamp; |
Yuta HIGUCHI | 273dcc8 | 2014-10-03 00:32:12 -0700 | [diff] [blame] | 19 | |
| 20 | import com.esotericsoftware.kryo.Kryo; |
| 21 | import com.esotericsoftware.kryo.Serializer; |
| 22 | import com.esotericsoftware.kryo.io.Input; |
| 23 | import com.esotericsoftware.kryo.io.Output; |
| 24 | |
| 25 | // To be used if Timestamp ever needs to cross bundle boundary. |
| 26 | /** |
| 27 | * Kryo Serializer for {@link MastershipBasedTimestamp}. |
| 28 | */ |
| 29 | public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> { |
| 30 | |
| 31 | /** |
Yuta HIGUCHI | 3e0b651 | 2014-10-07 17:43:56 -0700 | [diff] [blame] | 32 | * Creates a serializer for {@link MastershipBasedTimestamp}. |
Yuta HIGUCHI | 273dcc8 | 2014-10-03 00:32:12 -0700 | [diff] [blame] | 33 | */ |
| 34 | public MastershipBasedTimestampSerializer() { |
| 35 | // non-null, immutable |
| 36 | super(false, true); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void write(Kryo kryo, Output output, MastershipBasedTimestamp object) { |
| 41 | output.writeInt(object.termNumber()); |
| 42 | output.writeInt(object.sequenceNumber()); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public MastershipBasedTimestamp read(Kryo kryo, Input input, Class<MastershipBasedTimestamp> type) { |
| 47 | final int term = input.readInt(); |
| 48 | final int sequence = input.readInt(); |
| 49 | return new MastershipBasedTimestamp(term, sequence); |
| 50 | } |
| 51 | } |