blob: 014d7fcd9d671ebe2f669a7fa4e540f6609dac75 [file] [log] [blame]
Pier Luigi Ventred1173a12016-03-30 15:51:03 +02001/*
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +02002 * Copyright 2016-present Open Networking Laboratory
Pier Luigi Ventred1173a12016-03-30 15:51:03 +02003 *
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 */
16
17package org.onosproject.sdxl2;
18
19import com.esotericsoftware.kryo.Kryo;
20import com.esotericsoftware.kryo.Serializer;
21import com.esotericsoftware.kryo.io.Input;
22import com.esotericsoftware.kryo.io.Output;
23import org.onlab.packet.MacAddress;
24import org.onlab.packet.VlanId;
25import org.onosproject.net.ConnectPoint;
26
27import java.util.List;
28
29/**
pierventre3849e562016-05-11 11:47:32 +020030 * Kryo serializer for SDX-L2 connection point.
Pier Luigi Ventred1173a12016-03-30 15:51:03 +020031 */
32public class SdxL2ConnectionPointSerializer extends Serializer<SdxL2ConnectionPoint> {
33
34 /**
35 * Serialize the object using kryo.
36 *
37 * @param kryo the serializer
38 * @param output the output
39 * @param object the object to serialize
40 */
41 public void write(Kryo kryo, Output output, SdxL2ConnectionPoint object) {
42 kryo.writeClassAndObject(output, object.name());
43 kryo.writeClassAndObject(output, object.connectPoint());
44 kryo.writeClassAndObject(output, object.macAddress());
45 kryo.writeClassAndObject(output, object.vlanIds());
46 }
47
48 /**
49 * Create an object from one serialized using kryo.
50 *
51 * @param kryo the serializer
52 * @param input the inpunt
53 * @param type the object to create
54 * @return the object
55 */
56 public SdxL2ConnectionPoint read(Kryo kryo, Input input, Class<SdxL2ConnectionPoint> type) {
57 String name = (String) kryo.readClassAndObject(input);
58 ConnectPoint cp = (ConnectPoint) kryo.readClassAndObject(input);
59 MacAddress mac = (MacAddress) kryo.readClassAndObject(input);
60 List<VlanId> vlans = (List<VlanId>) kryo.readClassAndObject(input);
61 return new SdxL2ConnectionPoint(name, cp, vlans, mac);
62 }
63}