ee76b05ebf999c06a3e5bdd390d5162e84145135
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / instructions / AbstractInstructionSerializer.java
1 /*
2  * Copyright (c) 2016 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.instructions;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
16
17 public abstract class AbstractInstructionSerializer<T extends Instruction> implements OFSerializer<T>,
18         HeaderSerializer<T> {
19
20     @Override
21     public void serialize(T input, ByteBuf outBuffer) {
22         outBuffer.writeShort(getType());
23         outBuffer.writeShort(getLength());
24     }
25
26     @Override
27     public void serializeHeader(T input, ByteBuf outBuffer) {
28         outBuffer.writeShort(getType());
29         outBuffer.writeShort(InstructionConstants.INSTRUCTION_IDS_LENGTH);
30     }
31
32     /**
33      * Get type.
34      *
35      * @return numeric representation of instruction type.
36      */
37     protected abstract int getType();
38
39     /**
40      * Get length.
41      *
42      * @return instruction length.
43      */
44     protected abstract int getLength();
45
46 }