BGPCEP-768: Fix switch case
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPMessageToByteEncoder.java
index 633d232788d609e95e8087c5760da9e13244e8fa..58c35513e2cf83f5c4d885e92cbf37d3c9c6145c 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
 
 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.protocol.util.ByteArray;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,15 +28,16 @@ final class BGPMessageToByteEncoder extends MessageToByteEncoder<Notification> {
     private final MessageRegistry registry;
 
     BGPMessageToByteEncoder(final MessageRegistry registry) {
-        this.registry = Preconditions.checkNotNull(registry);
+        this.registry = requireNonNull(registry);
     }
 
     @Override
     protected void encode(final ChannelHandlerContext ctx, final Notification msg, final ByteBuf out) {
         LOG.trace("Encoding message: {}", msg);
-        final byte[] bytes = this.registry.serializeMessage(msg);
-        LOG.trace("Encoded message: {}", ByteArray.bytesToHexString(bytes));
-        out.writeBytes(bytes);
+        this.registry.serializeMessage(msg, out);
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Encoded message: {}", ByteBufUtil.hexDump(out));
+        }
         LOG.debug("Message sent to output: {}", msg);
     }
 }