Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / InstructionSerializerRegistryHelper.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.util;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.InstructionChoice;
16 import org.opendaylight.yangtools.yang.common.Uint8;
17
18 /**
19  * Helper class for registering instruction serializers.
20  *
21  * @author michal.polkorab
22  */
23 public class InstructionSerializerRegistryHelper {
24
25     private final Uint8 version;
26     private final SerializerRegistry serializerRegistry;
27
28     /**
29      * Constructor.
30      *
31      * @param version Openflow wire version
32      * @param serializerRegistry registry to be filled with message serializers
33      */
34     public InstructionSerializerRegistryHelper(final Uint8 version, final SerializerRegistry serializerRegistry) {
35         this.version = requireNonNull(version);
36         this.serializerRegistry = serializerRegistry;
37     }
38
39     /**
40      * Registers given serializer.
41      *
42      * @param instructionType instruction type
43      * @param serializer serializer instance
44      */
45     public <T extends InstructionChoice> void registerSerializer(final Class<T> instructionType,
46             final OFGeneralSerializer serializer) {
47         serializerRegistry.registerSerializer(new InstructionSerializerKey<>(version, instructionType, null),
48             serializer);
49     }
50 }