【问题标题】:ByteBuf will be cleared when changing the capacity of it in Netty4ByteBuf 在 Netty4 中改变容量时会被清除
【发布时间】:2013-09-10 02:13:25
【问题描述】:

调整此缓冲区的容量。如果 {@code newCapacity} 是 小于当前容量,这个缓冲区的内容是 截断。如果 {@code newCapacity} 大于当前 容量,缓冲区附加未指定的数据,其长度为 {@code (newCapacity - currentCapacity)}。

从上面显示的 ByteBuf.capacity(int newCapacity) 上的 cmets, 我们只是在这个方法之前的一个 ByteBuf 的内容在展开之后会保留下来。但是这个测试用例失败了。

ByteBuf bb =
    PooledByteBufAllocator.DEFAULT.directBuffer().order(
        ByteOrder.nativeOrder());

bb.setInt(4, 333);
TestCase.assertEquals(333, bb.getInt(4)); // passed
bb.capacity(4096);
TestCase.assertEquals(333, bb.getInt(4)); // failed

我们得到一个断言失败。

junit.framework.AssertionFailedError: expected:<333> but was:<0>

谁能解释一下,告诉我如何在不改变内容的情况下放大 ByteBuf?

谢谢, 最小

【问题讨论】:

    标签: netty bytebuffer


    【解决方案1】:

    我认为它与此错误报告有关...我们目前正在调查它: https://github.com/netty/netty/issues/1800

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多