Read data directly into a local array 31/20531/1
authorRobert Varga <rovarga@cisco.com>
Fri, 15 May 2015 15:28:27 +0000 (17:28 +0200)
committerRobert Varga <rovarga@cisco.com>
Fri, 15 May 2015 15:36:08 +0000 (17:36 +0200)
Do not instantiate an implied ByteBuf -- just allocate it explicitly and
pass it on.

Change-Id: Ib76e03dbf154cd7525aa5cd3e75cb9d3c45cd727
Signed-off-by: Robert Varga <rovarga@cisco.com>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10PacketInMessageFactory.java

index 3de0288bb7aa924c32649b61c23738f416326f9d..b3819445341ab4e3bdd2506b8edb78f3d3e4bd6d 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
@@ -25,7 +24,7 @@ public class OF10PacketInMessageFactory implements OFDeserializer<PacketInMessag
     private static final byte PADDING_IN_PACKET_IN_HEADER = 1;
 
     @Override
-    public PacketInMessage deserialize(ByteBuf rawMessage) {
+    public PacketInMessage deserialize(final ByteBuf rawMessage) {
         PacketInMessageBuilder builder = new PacketInMessageBuilder();
         builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
         builder.setXid(rawMessage.readUnsignedInt());
@@ -36,7 +35,9 @@ public class OF10PacketInMessageFactory implements OFDeserializer<PacketInMessag
         rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
         int remainingBytes = rawMessage.readableBytes();
         if (remainingBytes > 0) {
-            builder.setData(rawMessage.readBytes(remainingBytes).array());
+            final byte[] buf = new byte[remainingBytes];
+            rawMessage.readBytes(buf);
+            builder.setData(buf);
         }
         return builder.build();
     }