Bug 4827: Extend ByteToMessage decoder to support peer constraints
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPMessageToByteEncoder.java
index 4cd331ec2111b7f919de270b04436369f33c066a..7d576920e5c8bfcfd0aa6e101e75fdeb3d36d2ef 100644 (file)
@@ -7,33 +7,36 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.ChannelHandler.Sharable;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.MessageToByteEncoder;
-
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 /**
  *
  */
 @Sharable
 final class BGPMessageToByteEncoder extends MessageToByteEncoder<Notification> {
-       private static final Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
-       private final MessageRegistry registry;
+    private static final Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
+    private final MessageRegistry registry;
 
-       BGPMessageToByteEncoder(final MessageRegistry registry) {
-               this.registry = Preconditions.checkNotNull(registry);
-       }
+    BGPMessageToByteEncoder(final MessageRegistry registry) {
+        this.registry = Preconditions.checkNotNull(registry);
+    }
 
-       @Override
-       protected void encode(final ChannelHandlerContext ctx, final Notification msg, final ByteBuf out) throws Exception {
-               LOG.debug("Sent to encode : {}", msg);
-               out.writeBytes(this.registry.serializeMessage(msg));
-       }
+    @Override
+    protected void encode(final ChannelHandlerContext ctx, final Notification msg, final ByteBuf out) {
+        LOG.trace("Encoding message: {}", msg);
+        this.registry.serializeMessage(msg, out);
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Encoded message: {}", ByteBufUtil.hexDump(out));
+        }
+        LOG.debug("Message sent to output: {}", msg);
+    }
 }