本文整理汇总了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));
}
}