Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / instruction / WriteMetadataInstructionDeserializer.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 package org.opendaylight.openflowplugin.impl.protocol.deserialization.instruction;
9
10 import io.netty.buffer.ByteBuf;
11 import java.math.BigInteger;
12 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
16
17 public class WriteMetadataInstructionDeserializer extends AbstractInstructionDeserializer {
18     @Override
19     public Instruction deserialize(ByteBuf message) {
20         processHeader(message);
21         message.skipBytes(InstructionConstants.PADDING_IN_WRITE_METADATA);
22
23         final byte[] meta = new byte[Long.BYTES];
24         message.readBytes(meta);
25         final byte[] metaMask = new byte[Long.BYTES];
26         message.readBytes(metaMask);
27
28         return new WriteMetadataCaseBuilder()
29                 .setWriteMetadata(new WriteMetadataBuilder()
30                         .setMetadata(new BigInteger(1, meta))
31                         .setMetadataMask(new BigInteger(1, metaMask))
32                         .build())
33                 .build();
34     }
35
36     @Override
37     public Instruction deserializeHeader(ByteBuf message) {
38         processHeader(message);
39         return new WriteMetadataCaseBuilder().build();
40     }
41 }