Add multipart request message serializers
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / tablefeatures / MatchTablePropertySerializer.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.OFSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
15 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match;
21
22 public class MatchTablePropertySerializer extends AbstractTablePropertySerializer<Match> implements SerializerRegistryInjector {
23
24     private SerializerRegistry registry;
25
26     @Override
27     protected void serializeProperty(final Match property, final ByteBuf byteBuf) {
28         property
29             .getMatchSetfield()
30             .getSetFieldMatch()
31             .forEach(setFieldMatch -> registry
32                 .<MatchField, OFSerializer<SetFieldMatch>>getSerializer(
33                     new MessageTypeKey<>(
34                         EncodeConstants.OF13_VERSION_ID,
35                         setFieldMatch.getMatchType()))
36                 .serialize(setFieldMatch, byteBuf));
37     }
38
39     @Override
40     protected TableFeaturesPropType getType() {
41         return TableFeaturesPropType.OFPTFPTMATCH;
42     }
43
44     @Override
45     protected Class<Match> getClazz() {
46         return Match.class;
47     }
48
49     @Override
50     public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
51         registry = serializerRegistry;
52     }
53
54 }