Rework parser infrastructure to support partial message processing
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPKeepAliveMessageParser.java
index accfb46d19b6b525b04dcc6fe85bd91ad55a8814..6c8e6dc6cc7bb57c10e7063f0ecf3af18dbfb553 100644 (file)
@@ -9,17 +9,21 @@ package org.opendaylight.protocol.pcep.impl.message;
 
 import io.netty.buffer.ByteBuf;
 
+import java.util.List;
+
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
 
 /**
  * Parser for {@link KeepaliveMessage}
  */
 public class PCEPKeepAliveMessageParser extends AbstractMessageParser {
-
+       private static final KeepaliveMessage MESSAGE = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
        public static final int TYPE = 2;
 
        public PCEPKeepAliveMessageParser(final ObjectHandlerRegistry registry) {
@@ -30,18 +34,20 @@ public class PCEPKeepAliveMessageParser extends AbstractMessageParser {
        public void serializeMessage(final Message message, final ByteBuf buffer) {
                if (!(message instanceof KeepaliveMessage)) {
                        throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
-                                       + ". Nedded KeepaliveMessage.");
+                                       + ". Need KeepaliveMessage.");
                }
                buffer.writeBytes(new byte[0]);
        }
 
        @Override
-       public KeepaliveMessage parseMessage(final byte[] buffer) {
-               return new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
+       public int getMessageType() {
+               return TYPE;
        }
 
        @Override
-       public int getMessageType() {
-               return TYPE;
+       protected KeepaliveMessage validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
+               // FIXME: keepalive shouldn't have objects
+
+               return MESSAGE;
        }
 }