Pier | 3e79375 | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
| 17 | package org.onosproject.segmentrouting.mcast; |
| 18 | |
| 19 | |
| 20 | import com.esotericsoftware.kryo.Kryo; |
| 21 | import com.esotericsoftware.kryo.Serializer; |
| 22 | import com.esotericsoftware.kryo.io.Input; |
| 23 | import com.esotericsoftware.kryo.io.Output; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | |
| 28 | /** |
| 29 | * Custom serializer for {@link McastStoreKey}. |
| 30 | */ |
| 31 | class McastStoreKeySerializer extends Serializer<McastStoreKey> { |
| 32 | |
| 33 | /** |
| 34 | * Creates {@link McastStoreKeySerializer} serializer instance. |
| 35 | */ |
| 36 | McastStoreKeySerializer() { |
| 37 | // non-null, immutable |
| 38 | super(false, true); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public void write(Kryo kryo, Output output, McastStoreKey object) { |
| 43 | kryo.writeClassAndObject(output, object.mcastIp()); |
| 44 | output.writeString(object.deviceId().toString()); |
| 45 | kryo.writeClassAndObject(output, object.vlanId()); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public McastStoreKey read(Kryo kryo, Input input, Class<McastStoreKey> type) { |
| 50 | IpAddress mcastIp = (IpAddress) kryo.readClassAndObject(input); |
| 51 | final String str = input.readString(); |
| 52 | DeviceId deviceId = DeviceId.deviceId(str); |
| 53 | VlanId vlanId = (VlanId) kryo.readClassAndObject(input); |
| 54 | return new McastStoreKey(mcastIp, deviceId, vlanId); |
| 55 | } |
| 56 | } |