BUG-612 : switched PCEP XRO subobject serializers to ByteBuf
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / AbstractXROWithSubobjectsParser.java
index 25d8bdc3712c44cfdd6abd802290a875d3129bfb..e1a5f94e1a35a2dbfa7c60b67a8d5091698cf8a6 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.impl.object;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 
 import io.netty.buffer.ByteBuf;
@@ -61,24 +60,9 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
         return subs;
     }
 
-    protected final byte[] serializeSubobject(final List<Subobject> subobjects) {
-        final List<byte[]> result = Lists.newArrayList();
-        int finalLength = 0;
+    protected final void serializeSubobject(final List<Subobject> subobjects, final ByteBuf buffer) {
         for (final Subobject subobject : subobjects) {
-            final byte[] bytes = this.subobjReg.serializeSubobject(subobject);
-            if (bytes == null) {
-                LOG.warn("Could not find serializer for subobject type: {}. Skipping subobject.", subobject.getSubobjectType());
-            } else {
-                finalLength += bytes.length;
-                result.add(bytes);
-            }
-        }
-        final byte[] resultBytes = new byte[finalLength];
-        int byteOffset = 0;
-        for (final byte[] b : result) {
-            System.arraycopy(b, 0, resultBytes, byteOffset, b.length);
-            byteOffset += b.length;
+            this.subobjReg.serializeSubobject(subobject, buffer);
         }
-        return resultBytes;
     }
 }