Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / MultipartRequestQueueStatsSerializer.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart;
9
10 import static java.util.Objects.requireNonNullElse;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
16 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStats;
19
20 public class MultipartRequestQueueStatsSerializer implements OFSerializer<MultipartRequestQueueStats> {
21     @Override
22     public void serialize(final MultipartRequestQueueStats multipartRequestQueueStats, final ByteBuf byteBuf) {
23         if (multipartRequestQueueStats.getNodeConnectorId() == null) {
24             byteBuf.writeInt(OFConstants.OFPP_ANY.intValue());
25         } else {
26             byteBuf.writeInt(InventoryDataServiceUtil
27                 .portNumberfromNodeConnectorId(
28                     OpenflowVersion.OF13,
29                     multipartRequestQueueStats.getNodeConnectorId()).intValue());
30         }
31
32         byteBuf.writeInt(requireNonNullElse(multipartRequestQueueStats.getQueueId(), new QueueId(OFConstants.OFPQ_ALL))
33                 .getValue().intValue());
34     }
35 }