Extensibility support (deserialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / RoleReplyMessageFactory.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.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.math.BigInteger;
14
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder;
20
21 /**
22  * Translates RoleReply messages
23  * @author timotej.kubas
24  * @author michal.polkorab
25  */
26 public class RoleReplyMessageFactory implements OFDeserializer<RoleRequestOutput>{
27
28     private static final byte PADDING_IN_ROLE_REPLY_HEADER = 4;
29
30     @Override
31     public RoleRequestOutput deserialize(ByteBuf rawMessage) {
32         RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
33         builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
34         builder.setXid(rawMessage.readUnsignedInt());
35         builder.setRole(ControllerRole.forValue((int) rawMessage.readUnsignedInt()));
36         rawMessage.skipBytes(PADDING_IN_ROLE_REPLY_HEADER);
37         byte[] generationID = new byte[8];
38         rawMessage.readBytes(generationID);
39         builder.setGenerationId(new BigInteger(1, generationID));
40         return builder.build();
41     }
42 }