Add multipart request message serializers
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / tablefeatures / matchfield / AbstractMatchFieldSerializer.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.matchfield;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
14
15 public abstract class AbstractMatchFieldSerializer implements OFSerializer<SetFieldMatch> {
16
17     @Override
18     public void serialize(final SetFieldMatch setFieldMatch, final ByteBuf byteBuf) {
19         byteBuf.writeShort(getOxmClassCode());
20
21         int fieldAndMask = getOxmFieldCode() << 1;
22         int length = getValueLength();
23
24         if (setFieldMatch.isHasMask()) {
25             fieldAndMask |= 1;
26             length *= 2;
27         }
28
29         byteBuf.writeByte(fieldAndMask);
30         byteBuf.writeByte(length);
31     }
32
33     protected abstract int getOxmClassCode();
34     protected abstract int getOxmFieldCode();
35     protected abstract int getValueLength();
36
37 }