当前位置: 首页>>代码示例>>Java>>正文


Java DrillBuf.writeByte方法代码示例

本文整理汇总了Java中io.netty.buffer.DrillBuf.writeByte方法的典型用法代码示例。如果您正苦于以下问题:Java DrillBuf.writeByte方法的具体用法?Java DrillBuf.writeByte怎么用?Java DrillBuf.writeByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.DrillBuf的用法示例。


在下文中一共展示了DrillBuf.writeByte方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeVLong

import io.netty.buffer.DrillBuf; //导入方法依赖的package包/类
/**
 * Serializes a long to a binary stream with zero-compressed encoding.
 * For -112 <= i <= 127, only one byte is used with the actual value.
 * For other values of i, the first byte value indicates whether the
 * long is positive or negative, and the number of bytes that follow.
 * If the first byte value v is between -113 and -120, the following long
 * is positive, with number of bytes that follow are -(v+112).
 * If the first byte value v is between -121 and -128, the following long
 * is negative, with number of bytes that follow are -(v+120). Bytes are
 * stored in the high-non-zero-byte-first order.
 *
 * @param buffer DrillBuf to write to
 * @param i Long to be serialized
 */
public static void writeVLong(DrillBuf buffer, int start, int end, long i) {
  int availableBytes = (end-start);
  if (availableBytes < getVIntSize(i)) {
    throw new NumberFormatException("Expected " + getVIntSize(i) + " bytes but the buffer '"
        + DrillStringUtils.toBinaryString(buffer, start, end) + "' has only "
        + availableBytes + " bytes.");
  }
  buffer.writerIndex(start);

  if (i >= -112 && i <= 127) {
    buffer.writeByte((byte)i);
    return;
  }

  int len = -112;
  if (i < 0) {
    i ^= -1L; // take one's complement'
    len = -120;
  }

  long tmp = i;
  while (tmp != 0) {
    tmp = tmp >> 8;
    len--;
  }

  buffer.writeByte((byte)len);

  len = (len < -120) ? -(len + 120) : -(len + 112);

  for (int idx = len; idx != 0; idx--) {
    int shiftbits = (idx - 1) * 8;
    long mask = 0xFFL << shiftbits;
    buffer.writeByte((byte)((i & mask) >> shiftbits));
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:51,代码来源:ByteBufUtil.java


注:本文中的io.netty.buffer.DrillBuf.writeByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。