blob: 83bff3cf2001b5ce20f3c02a8c72f212c4706cbb [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 HIGUCHI60a190b2014-11-07 16:24:47 -080016package org.onlab.onos.store.serializers.impl;
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070017
Yuta HIGUCHI8ce08732014-10-11 10:40:45 -070018import org.onlab.onos.store.impl.MastershipBasedTimestamp;
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070019
20import com.esotericsoftware.kryo.Kryo;
21import com.esotericsoftware.kryo.Serializer;
22import com.esotericsoftware.kryo.io.Input;
23import 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 */
29public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> {
30
31 /**
Yuta HIGUCHI3e0b6512014-10-07 17:43:56 -070032 * Creates a serializer for {@link MastershipBasedTimestamp}.
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070033 */
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}