Object parsing can be private now
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPMessageFactory.java
index 1bc18098700dd544dcfed15f98e7f9deb9e4cdaf..627b1673602c291a128cd1bf338f2ce4a8bfaae3 100644 (file)
@@ -10,11 +10,13 @@ package org.opendaylight.protocol.pcep.impl;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageSerializer;
 import org.opendaylight.protocol.util.ByteArray;
@@ -77,17 +79,20 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<Message>
                                        + (msgLength - COMMON_HEADER_LENGTH));
                }
 
+               final List<Message> errors = new ArrayList<>();
                Message msg = null;
 
                try {
-                       msg = this.registry.getMessageParser(type).parseMessage(msgBody);
+                       msg = this.registry.getMessageParser(type).parseMessage(msgBody, errors);
                } catch (final PCEPDeserializerException e) {
                        logger.debug("Unexpected deserializer problem", e);
                        throw new DeserializerException(e.getMessage(), e);
-               } catch (final PCEPDocumentedException e) {
-                       logger.debug("Documented deserializer problem", e);
-                       throw new DocumentedException(e.getMessage(), e);
                }
+
+               if (!errors.isEmpty()) {
+                       // FIXME: we have a bunch of error messages, how can we send them back?
+               }
+
                logger.debug("Message was parsed. {}", msg);
                return msg;
        }
@@ -104,7 +109,9 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<Message>
 
                serializer.serializeMessage(msg, buf);
 
-               final byte[] msgBody = buf.array();
+               final byte[] msgBody = new byte[buf.readableBytes()];
+
+               buf.getBytes(0, msgBody);
 
                final byte[] headerBytes = new byte[COMMON_HEADER_LENGTH];
 
@@ -115,13 +122,13 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<Message>
                headerBytes[TYPE_F_OFFSET] = (byte) serializer.getMessageType();
 
                // msgLength
-               System.arraycopy(ByteArray.intToBytes(msgBody.length), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, headerBytes, LENGTH_F_OFFSET,
-                               LENGTH_F_LENGTH);
+               System.arraycopy(ByteArray.intToBytes(msgBody.length + COMMON_HEADER_LENGTH), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH,
+                               headerBytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH);
 
                final byte[] retBytes = new byte[headerBytes.length + msgBody.length];
 
                ByteArray.copyWhole(headerBytes, retBytes, 0);
-               ByteArray.copyWhole(msgBody, retBytes, PCEPMessageHeader.COMMON_HEADER_LENGTH);
+               ByteArray.copyWhole(msgBody, retBytes, COMMON_HEADER_LENGTH);
 
                return retBytes;
        }