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;
+ (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;
}
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];
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;
}