Added missing extension registration methods + keys (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / VendorInputMessageFactory.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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
19
20 /**
21  * Translates Vendor messages
22  * @author michal.polkorab
23  */
24 public class VendorInputMessageFactory implements OFSerializer<ExperimenterInput>,
25         SerializerRegistryInjector {
26
27     private SerializerRegistry registry;
28
29     @Override
30     public void serialize(ExperimenterInput message, ByteBuf outBuffer) {
31         long expId = message.getExperimenter().getValue();
32         OFSerializer<ExperimenterInput> serializer = registry.getSerializer(
33                 ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey(
34                         EncodeConstants.OF10_VERSION_ID, expId));
35         serializer.serialize(message, outBuffer);
36     }
37
38     @Override
39     public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
40         this.registry = serializerRegistry;
41     }
42 }