Correct input buffer sizing
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPMessageHeaderDecoder.java
index 2645401c61e84fa91a188621055c9bcb5e43e741..bc1cf5b9c6ea32492eb7be9321ef3d42e137e863 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import io.netty.channel.FixedRecvByteBufAllocator;
 import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
 
 /**
@@ -26,6 +27,11 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
 
     private static final int EXTENDED_MAX_FRAME_SIZE = 65535;
 
+    // Allocators
+    private static final FixedRecvByteBufAllocator RECV_ALLOCATOR = new FixedRecvByteBufAllocator(MAX_FRAME_SIZE);
+    private static final FixedRecvByteBufAllocator EXTENDED_RECV_ALLOCATOR =
+            new FixedRecvByteBufAllocator(EXTENDED_MAX_FRAME_SIZE);
+
     /*
 
      0                   1                   2                   3
@@ -49,6 +55,14 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
         super(maxFrameSize, MARKER_SIZE, LENGTH_SIZE, -MARKER_SIZE - LENGTH_SIZE, 0);
     }
 
+    static FixedRecvByteBufAllocator getRecvAllocator() {
+        return RECV_ALLOCATOR;
+    }
+
+    static FixedRecvByteBufAllocator getExtendedRecvAllocator() {
+        return EXTENDED_RECV_ALLOCATOR;
+    }
+
     static BGPMessageHeaderDecoder getBGPMessageHeaderDecoder() {
         return new BGPMessageHeaderDecoder(MAX_FRAME_SIZE);
     }
@@ -56,6 +70,4 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
     static BGPMessageHeaderDecoder getExtendedBGPMessageHeaderDecoder() {
         return new BGPMessageHeaderDecoder(EXTENDED_MAX_FRAME_SIZE);
     }
-
-
 }