Merge "Migrate uint/ByteBuf interactions"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / RoleRequestInputMessageFactory.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium 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.factories;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint64;
12
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder;
19
20 /**
21  * Translates RoleRequestInput messages.
22  *
23  * @author giuseppex.petralia@intel.com
24  */
25 public class RoleRequestInputMessageFactory implements OFDeserializer<RoleRequestInput> {
26
27     private static final byte PADDING = 4;
28
29     @Override
30     public RoleRequestInput deserialize(ByteBuf rawMessage) {
31         RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
32         builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
33         builder.setXid(readUint32(rawMessage));
34         builder.setRole(ControllerRole.forValue(rawMessage.readInt()));
35         rawMessage.skipBytes(PADDING);
36         builder.setGenerationId(readUint64(rawMessage));
37         return builder.build();
38     }
39 }