Merge "Bump odlparent 2.0.2 to 2.0.4"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / tablefeatures / WriteActionsTablePropertySerializer.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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions;
20
21 public class WriteActionsTablePropertySerializer extends AbstractTablePropertySerializer<WriteActions> implements SerializerRegistryInjector {
22
23     private SerializerRegistry registry;
24
25     @Override
26     protected void serializeProperty(final WriteActions property, final ByteBuf byteBuf) {
27         property
28                 .getWriteActions()
29                 .getAction()
30                 .stream()
31                 .sorted(OrderComparator.build())
32                 .map(Action::getAction)
33                 .forEach(action -> ActionUtil
34                         .writeActionHeader(
35                                 action,
36                                 EncodeConstants.OF13_VERSION_ID,
37                                 registry,
38                                 byteBuf));
39     }
40
41     @Override
42     protected TableFeaturesPropType getType() {
43         return TableFeaturesPropType.OFPTFPTWRITEACTIONS;
44     }
45
46     @Override
47     protected Class<WriteActions> getClazz() {
48         return WriteActions.class;
49     }
50
51     @Override
52     public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
53         registry = serializerRegistry;
54     }
55
56 }