Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 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; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 17 | |
| 18 | import java.nio.ByteBuffer; |
| 19 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.flow.TrafficTreatment; |
| 22 | import org.onosproject.net.packet.DefaultOutboundPacket; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -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; |
| 28 | |
| 29 | /** |
| 30 | * Serializer for a default outbound packet. |
| 31 | */ |
| 32 | public class DefaultOutboundPacketSerializer extends Serializer<DefaultOutboundPacket> { |
| 33 | |
| 34 | /** |
| 35 | * Creates {@link DefaultOutboundPacket} serializer instance. |
| 36 | */ |
| 37 | public DefaultOutboundPacketSerializer() { |
| 38 | // non-null, immutable |
| 39 | super(false, true); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public DefaultOutboundPacket read(Kryo kryo, Input input, |
| 44 | Class<DefaultOutboundPacket> type) { |
| 45 | DeviceId sendThrough = (DeviceId) kryo.readClassAndObject(input); |
| 46 | TrafficTreatment treatment = (TrafficTreatment) kryo.readClassAndObject(input); |
| 47 | byte[] data = (byte[]) kryo.readClassAndObject(input); |
| 48 | return new DefaultOutboundPacket(sendThrough, treatment, ByteBuffer.wrap(data)); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void write(Kryo kryo, Output output, DefaultOutboundPacket object) { |
| 53 | kryo.writeClassAndObject(output, object.sendThrough()); |
| 54 | kryo.writeClassAndObject(output, object.treatment()); |
| 55 | kryo.writeClassAndObject(output, object.data().array()); |
| 56 | } |
| 57 | |
| 58 | } |