Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 17 | |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 18 | import org.onosproject.net.Annotations; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.DefaultPort; |
| 20 | import org.onosproject.net.Element; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 21 | import org.onosproject.net.Port; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 23 | |
| 24 | import com.esotericsoftware.kryo.Kryo; |
| 25 | import com.esotericsoftware.kryo.Serializer; |
| 26 | import com.esotericsoftware.kryo.io.Input; |
| 27 | import com.esotericsoftware.kryo.io.Output; |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 28 | |
Yuta HIGUCHI | c705201 | 2014-09-22 19:11:00 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Kryo Serializer for {@link DefaultPort}. |
| 31 | */ |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 32 | public final class DefaultPortSerializer extends |
| 33 | Serializer<DefaultPort> { |
| 34 | |
Yuta HIGUCHI | c705201 | 2014-09-22 19:11:00 -0700 | [diff] [blame] | 35 | /** |
Yuta HIGUCHI | 03fec1f | 2014-10-03 09:13:50 -0700 | [diff] [blame] | 36 | * Creates {@link DefaultPort} serializer instance. |
Yuta HIGUCHI | c705201 | 2014-09-22 19:11:00 -0700 | [diff] [blame] | 37 | */ |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 38 | 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 Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 48 | kryo.writeObject(output, object.type()); |
| 49 | output.writeLong(object.portSpeed()); |
| 50 | kryo.writeClassAndObject(output, object.annotations()); |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 54 | public DefaultPort read(Kryo kryo, Input input, Class<DefaultPort> aClass) { |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 55 | Element element = (Element) kryo.readClassAndObject(input); |
| 56 | PortNumber number = kryo.readObject(input, PortNumber.class); |
| 57 | boolean isEnabled = input.readBoolean(); |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 58 | Port.Type type = kryo.readObject(input, Port.Type.class); |
| 59 | long portSpeed = input.readLong(); |
| 60 | Annotations annotations = (Annotations) kryo.readClassAndObject(input); |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 61 | |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 62 | return new DefaultPort(element, number, isEnabled, type, portSpeed, annotations); |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 63 | } |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 64 | |
Yuta HIGUCHI | 24a086b | 2014-09-21 23:28:41 -0700 | [diff] [blame] | 65 | } |