Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.opencord.igmpproxy.impl; |
| 17 | |
| 18 | import com.esotericsoftware.kryo.Kryo; |
| 19 | import com.esotericsoftware.kryo.Serializer; |
| 20 | import com.esotericsoftware.kryo.io.Input; |
| 21 | import com.esotericsoftware.kryo.io.Output; |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.opencord.igmpproxy.statemachine.StateMachineId; |
| 25 | |
| 26 | /** |
| 27 | * Custom serializer for {@link SingleStateMachine}. |
| 28 | */ |
| 29 | public class SingleStateMachineSerializer extends Serializer<SingleStateMachine> { |
| 30 | /** |
| 31 | * Creates serializer instance. |
| 32 | */ |
| 33 | public SingleStateMachineSerializer() { |
| 34 | // non-null, immutable |
| 35 | super(false, true); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void write(Kryo kryo, Output output, SingleStateMachine singleStateMachine) { |
| 40 | kryo.writeClassAndObject(output, singleStateMachine.getStateMachineId()); |
| 41 | kryo.writeClassAndObject(output, singleStateMachine.getSrcIp()); |
| 42 | kryo.writeClassAndObject(output, singleStateMachine.getUpLinkPort()); |
| 43 | kryo.writeClassAndObject(output, singleStateMachine.getTimeOut()); |
| 44 | kryo.writeObject(output, singleStateMachine.currentState()); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public SingleStateMachine read(Kryo kryo, Input input, Class<SingleStateMachine> aClass) { |
| 49 | StateMachineId stateMachineId = (StateMachineId) kryo.readClassAndObject(input); |
| 50 | Ip4Address srcIp = (Ip4Address) kryo.readClassAndObject(input); |
| 51 | PortNumber uplinkPort = (PortNumber) kryo.readClassAndObject(input); |
| 52 | Integer timeout = (Integer) kryo.readClassAndObject(input); |
| 53 | int currentState = kryo.readObject(input, int.class); |
| 54 | return new SingleStateMachine(stateMachineId, srcIp, uplinkPort, currentState, timeout); |
| 55 | } |
| 56 | |
| 57 | } |