blob: 6a3e242d0eaea0e4f5b12b7bdf6ab861110f8406 [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
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.DeviceId;
21import org.onosproject.net.device.DeviceDescription;
22import org.onosproject.net.provider.ProviderId;
23import org.onosproject.store.impl.Timestamped;
Madan Jampanifef9b3a2014-10-07 18:38:17 -070024import com.esotericsoftware.kryo.Kryo;
25import com.esotericsoftware.kryo.Serializer;
26import com.esotericsoftware.kryo.io.Input;
27import com.esotericsoftware.kryo.io.Output;
28
29/**
30 * Kryo Serializer for {@link InternalDeviceEvent}.
31 */
32public class InternalDeviceEventSerializer extends Serializer<InternalDeviceEvent> {
33
34 /**
35 * Creates a serializer for {@link InternalDeviceEvent}.
36 */
37 public InternalDeviceEventSerializer() {
38 // does not accept null
39 super(false);
40 }
41
42 @Override
43 public void write(Kryo kryo, Output output, InternalDeviceEvent event) {
44 kryo.writeClassAndObject(output, event.providerId());
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070045 kryo.writeObject(output, event.deviceId(), deviceIdSerializer());
Madan Jampanifef9b3a2014-10-07 18:38:17 -070046 kryo.writeClassAndObject(output, event.deviceDescription());
47 }
48
49 @Override
50 public InternalDeviceEvent read(Kryo kryo, Input input,
51 Class<InternalDeviceEvent> type) {
52 ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070053 DeviceId deviceId = kryo.readObject(input, DeviceId.class, deviceIdSerializer());
Ray Milkey5154ec32014-10-22 10:51:18 -070054
55 @SuppressWarnings("unchecked")
Yuta HIGUCHI74ebeff12014-10-07 19:54:05 -070056 Timestamped<DeviceDescription> deviceDescription
57 = (Timestamped<DeviceDescription>) kryo.readClassAndObject(input);
Madan Jampanifef9b3a2014-10-07 18:38:17 -070058
59 return new InternalDeviceEvent(providerId, deviceId, deviceDescription);
60 }
61}