blob: ce32e12994dfa8e4222116647363e2542c7275dc [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.device.impl;
Madan Jampanifef9b3a2014-10-07 18:38:17 -070017
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070018import static org.onosproject.store.serializers.DeviceIdSerializer.deviceIdSerializer;
19
Madan Jampanifef9b3a2014-10-07 18:38:17 -070020import java.util.List;
21
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.DeviceId;
23import org.onosproject.net.device.PortDescription;
24import org.onosproject.net.provider.ProviderId;
25import org.onosproject.store.impl.Timestamped;
Madan Jampanifef9b3a2014-10-07 18:38:17 -070026
27import com.esotericsoftware.kryo.Kryo;
28import com.esotericsoftware.kryo.Serializer;
29import com.esotericsoftware.kryo.io.Input;
30import com.esotericsoftware.kryo.io.Output;
31
32/**
33 * Kryo Serializer for {@link InternalPortEvent}.
34 */
35public class InternalPortEventSerializer extends Serializer<InternalPortEvent> {
36
37 /**
38 * Creates a serializer for {@link InternalPortEvent}.
39 */
40 public InternalPortEventSerializer() {
41 // does not accept null
42 super(false);
43 }
44
45 @Override
46 public void write(Kryo kryo, Output output, InternalPortEvent event) {
47 kryo.writeClassAndObject(output, event.providerId());
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070048 kryo.writeObject(output, event.deviceId(), deviceIdSerializer());
Madan Jampanifef9b3a2014-10-07 18:38:17 -070049 kryo.writeClassAndObject(output, event.portDescriptions());
50 }
51
52 @Override
53 public InternalPortEvent read(Kryo kryo, Input input,
54 Class<InternalPortEvent> type) {
55 ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070056 DeviceId deviceId = kryo.readObject(input, DeviceId.class, deviceIdSerializer());
Ray Milkey5154ec32014-10-22 10:51:18 -070057
58 @SuppressWarnings("unchecked")
Yuta HIGUCHI74ebeff12014-10-07 19:54:05 -070059 Timestamped<List<PortDescription>> portDescriptions
60 = (Timestamped<List<PortDescription>>) kryo.readClassAndObject(input);
Madan Jampanifef9b3a2014-10-07 18:38:17 -070061
62 return new InternalPortEvent(providerId, deviceId, portDescriptions);
63 }
64}