Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / VersionAssignableFactory.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.openflowjava.protocol.impl.util;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
12 import org.opendaylight.yangtools.yang.binding.DataContainer;
13 import org.opendaylight.yangtools.yang.common.Uint8;
14
15 /**
16  * Abstract factory class to support OF protocol version assigning and reading.
17  */
18 public abstract class VersionAssignableFactory<T extends DataContainer> implements OFDeserializer<T> {
19     private Uint8 version;
20
21     /**
22      * Assigns the version.
23      *
24      * @param newVersion OpenFlow protocol version
25      */
26     public void assignVersion(final @NonNull Uint8 newVersion) {
27         if (version != null) {
28             throw new IllegalStateException("Version already assigned: " + version);
29         }
30         version = newVersion;
31     }
32
33     /**
34      * Returns the OpenFlow protocol version.
35      */
36     protected final Uint8 getVersion() {
37         return this.version;
38     }
39 }