blob: 6754aa2dfb49f81f91771cc979ab0fa2f3eb005b [file] [log] [blame]
Jonathan Hart4f60f982014-10-27 08:11:17 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Jonathan Hart4f60f982014-10-27 08:11:17 -07003 *
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;
Jonathan Hart4f60f982014-10-27 08:11:17 -070017
18import java.nio.ByteBuffer;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.DeviceId;
21import org.onosproject.net.flow.TrafficTreatment;
22import org.onosproject.net.packet.DefaultOutboundPacket;
Jonathan Hart4f60f982014-10-27 08:11:17 -070023
24import com.esotericsoftware.kryo.Kryo;
25import com.esotericsoftware.kryo.Serializer;
26import com.esotericsoftware.kryo.io.Input;
27import com.esotericsoftware.kryo.io.Output;
28
29/**
30 * Serializer for a default outbound packet.
31 */
32public 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}