Repository: pinpoint-apm/pinpoint
Issue: Buffer API enhancement
Labels: enhancement

[Buffer](https://github.com/naver/pinpoint/blob/master/commons/src/main/java/com/navercorp/pinpoint/common/buffer/Buffer.java) API enhancement
- add remaining()
- add hasRemaining()
- add wrapByteBuffer()
- deprecated limit()
- change put($Type) -> put$Type()
- change putVar($Type) -> putV$Type()
- change readVar$Type() -> readV$Type();
- fixed incorrect buffer expend multiplier : multiplier 4 -> multiplier 2


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/buffer/AutomaticBuffer.java b/commons/src/main/java/com/navercorp/pinpoint/common/buffer/AutomaticBuffer.java
index 92da68ec55c8..e29676de9c2b 100644
--- a/commons/src/main/java/com/navercorp/pinpoint/common/buffer/AutomaticBuffer.java
+++ b/commons/src/main/java/com/navercorp/pinpoint/common/buffer/AutomaticBuffer.java
@@ -58,7 +58,7 @@ protected void checkExpand(final int size) {
     protected int computeExpandedBufferSize(final int size, int length, int remain) {
         int expandedBufferSize = 0;
         while (remain < size) {
-            length <<= 2;
+            length <<= 1;
             expandedBufferSize = length;
             remain = expandedBufferSize - offset;
         }


Test patch:
diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java
index c27508507097..9b2b66c82c1b 100644
--- a/commons/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java
+++ b/commons/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java
@@ -308,7 +308,7 @@ public void testUdp() throws Exception {
     }
 
     @Test
-    public void test_remaining() throws Exception {
+    public void testRemaining() throws Exception {
         final byte[] bytes = new byte[BytesUtils.INT_BYTE_LENGTH];
         Buffer buffer = new AutomaticBuffer(bytes);
         Assert.assertEquals(buffer.remaining(), 4);
@@ -326,4 +326,43 @@ public void test_remaining() throws Exception {
 
     }
 
+
+    @Test
+    public void testExpendMultiplier_2multiplier() throws Exception {
+        int bufferSize = 4;
+        Buffer buffer = new AutomaticBuffer(bufferSize);
+
+        buffer.putBytes(new byte[8]);
+        logger.debug("bufferSize:{} offset:{}", buffer.getInternalBuffer().length, buffer.getOffset());
+        Assert.assertEquals(buffer.getInternalBuffer().length, 8);
+
+        buffer.putBytes(new byte[8]);
+
+        logger.debug("bufferSize:{} offset:{}", buffer.getInternalBuffer().length, buffer.getOffset());
+        Assert.assertEquals(buffer.getInternalBuffer().length, 16);
+
+
+        buffer.putBytes(new byte[8]);
+        logger.debug("bufferSize:{} offset:{}", buffer.getInternalBuffer().length, buffer.getOffset());
+        Assert.assertEquals(buffer.getInternalBuffer().length, 32);
+    }
+
+    @Test
+    public void testExpendMultiplier_4multiplier() throws Exception {
+        int bufferSize = 4;
+        Buffer buffer = new AutomaticBuffer(bufferSize);
+
+        buffer.putBytes(new byte[5*4]);
+
+        logger.debug("bufferSize:{} offset:{}", buffer.getInternalBuffer().length, buffer.getOffset());
+        Assert.assertEquals(buffer.getInternalBuffer().length, 32);
+
+        buffer.putBytes(new byte[8*4]);
+
+        logger.debug("bufferSize:{} offset:{}", buffer.getInternalBuffer().length, buffer.getOffset());
+        Assert.assertEquals(buffer.getInternalBuffer().length, 64);
+
+
+    }
+
 }