Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / AbstractOxmMetadataDeserializer.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
18
19 /**
20  * @author michal.polkorab
21  *
22  */
23 public abstract class AbstractOxmMetadataDeserializer extends AbstractOxmMatchEntryDeserializer
24         implements OFDeserializer<MatchEntries> {
25
26     @Override
27     public MatchEntries deserialize(ByteBuf input) {
28         MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
29         addMetadataAugmentation(builder, input);
30         if (builder.isHasMask()) {
31             OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
32         }
33         return builder.build();
34     }
35
36     private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf input) {
37         MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder();
38         byte[] metadataBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
39         input.readBytes(metadataBytes);
40         metadata.setMetadata(metadataBytes);
41         builder.addAugmentation(MetadataMatchEntry.class, metadata.build());
42     }
43 }