Merge "Fix checkstyle warnings for impl/protocol package"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / instructions / WriteMetadataInstructionSerializer.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.util.EncodeConstants;
13 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
14 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata;
18
19 public class WriteMetadataInstructionSerializer extends AbstractInstructionSerializer {
20
21     @Override
22     public void serialize(Instruction input, ByteBuf outBuffer) {
23         super.serialize(input, outBuffer);
24         final WriteMetadata writeMetadata = WriteMetadataCase.class.cast(input).getWriteMetadata();
25         outBuffer.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
26         outBuffer.writeBytes(ByteUtil
27                 .convertBigIntegerToNBytes(writeMetadata.getMetadata(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
28         outBuffer.writeBytes(ByteUtil
29                 .convertBigIntegerToNBytes(writeMetadata.getMetadataMask(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
30     }
31
32     @Override
33     protected int getType() {
34         return InstructionConstants.WRITE_METADATA_TYPE;
35     }
36
37     @Override
38     protected int getLength() {
39         return InstructionConstants.WRITE_METADATA_LENGTH;
40     }
41
42 }