blob: 1f4dc7bf35f88770926af095f0f7dedb6d355136 [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 */
tomb41d1ac2014-09-24 01:51:24 -070016package org.onlab.onos.store.serializers;
17
18import com.esotericsoftware.kryo.Kryo;
19import com.esotericsoftware.kryo.Serializer;
20import com.esotericsoftware.kryo.io.Input;
21import com.esotericsoftware.kryo.io.Output;
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070022
tomb41d1ac2014-09-24 01:51:24 -070023import org.onlab.onos.cluster.NodeId;
24
25/**
26 * Kryo Serializer for {@link org.onlab.onos.cluster.NodeId}.
27 */
28public final class NodeIdSerializer extends Serializer<NodeId> {
29
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070030 /**
31 * Creates {@link NodeId} serializer instance.
32 */
33 public NodeIdSerializer() {
34 // non-null, immutable
35 super(false, true);
36 }
37
tomb41d1ac2014-09-24 01:51:24 -070038 @Override
39 public void write(Kryo kryo, Output output, NodeId object) {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070040 output.writeString(object.toString());
tomb41d1ac2014-09-24 01:51:24 -070041 }
42
43 @Override
44 public NodeId read(Kryo kryo, Input input, Class<NodeId> type) {
Yuta HIGUCHI5bdebe32014-10-04 21:40:41 -070045 final String id = input.readString();
tomb41d1ac2014-09-24 01:51:24 -070046 return new NodeId(id);
47 }
48}