blob: 60d09fbe6566fb638f2e115bb3c09b7f9e015713 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070017
Marc De Leenheerbb382352015-04-23 18:20:34 -070018import org.onosproject.net.Annotations;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.DefaultPort;
20import org.onosproject.net.Element;
Marc De Leenheerbb382352015-04-23 18:20:34 -070021import org.onosproject.net.Port;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.PortNumber;
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070023
24import com.esotericsoftware.kryo.Kryo;
25import com.esotericsoftware.kryo.Serializer;
26import com.esotericsoftware.kryo.io.Input;
27import com.esotericsoftware.kryo.io.Output;
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070028
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070029/**
30 * Kryo Serializer for {@link DefaultPort}.
31 */
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070032public final class DefaultPortSerializer extends
33 Serializer<DefaultPort> {
34
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070035 /**
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070036 * Creates {@link DefaultPort} serializer instance.
Yuta HIGUCHIc7052012014-09-22 19:11:00 -070037 */
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070038 public DefaultPortSerializer() {
39 // non-null, immutable
40 super(false, true);
41 }
42
43 @Override
44 public void write(Kryo kryo, Output output, DefaultPort object) {
45 kryo.writeClassAndObject(output, object.element());
46 kryo.writeObject(output, object.number());
47 output.writeBoolean(object.isEnabled());
Marc De Leenheerbb382352015-04-23 18:20:34 -070048 kryo.writeObject(output, object.type());
49 output.writeLong(object.portSpeed());
50 kryo.writeClassAndObject(output, object.annotations());
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070051 }
52
53 @Override
Marc De Leenheerbb382352015-04-23 18:20:34 -070054 public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) {
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070055 Element element = (Element) kryo.readClassAndObject(input);
56 PortNumber number = kryo.readObject(input, PortNumber.class);
57 boolean isEnabled = input.readBoolean();
Marc De Leenheerbb382352015-04-23 18:20:34 -070058 Port.Type type = kryo.readObject(input, Port.Type.class);
59 long portSpeed = input.readLong();
60 Annotations annotations = (Annotations) kryo.readClassAndObject(input);
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070061
Marc De Leenheerbb382352015-04-23 18:20:34 -070062 return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations);
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070063 }
Marc De Leenheerbb382352015-04-23 18:20:34 -070064
Yuta HIGUCHI24a086b2014-09-21 23:28:41 -070065}