本文整理汇总了Java中org.msgpack.core.MessageUnpacker.readPayload方法的典型用法代码示例。如果您正苦于以下问题:Java MessageUnpacker.readPayload方法的具体用法?Java MessageUnpacker.readPayload怎么用?Java MessageUnpacker.readPayload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.core.MessageUnpacker
的用法示例。
在下文中一共展示了MessageUnpacker.readPayload方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSpanId
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
static SpanId readSpanId(MessageUnpacker unpacker) throws IOException {
int alen = unpacker.unpackBinaryHeader();
if (alen != SPAN_ID_BYTE_LENGTH) {
throw new IOException("Invalid length given for spanID array. " +
"Expected " + SPAN_ID_BYTE_LENGTH + "; got " + alen);
}
byte[] payload = new byte[SPAN_ID_BYTE_LENGTH];
unpacker.readPayload(payload);
return new SpanId(
((payload[ 7] & 0xffL) << 0) |
((payload[ 6] & 0xffL) << 8) |
((payload[ 5] & 0xffL) << 16) |
((payload[ 4] & 0xffL) << 24) |
((payload[ 3] & 0xffL) << 32) |
((payload[ 2] & 0xffL) << 40) |
((payload[ 1] & 0xffL) << 48) |
((payload[ 0] & 0xffL) << 56),
((payload[15] & 0xffL) << 0) |
((payload[14] & 0xffL) << 8) |
((payload[13] & 0xffL) << 16) |
((payload[12] & 0xffL) << 24) |
((payload[11] & 0xffL) << 32) |
((payload[10] & 0xffL) << 40) |
((payload[ 9] & 0xffL) << 48) |
((payload[ 8] & 0xffL) << 56)
);
}
示例2: next
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
@Override
public KeyValue next() throws IOException {
if (mReader.next(mKey, mValue)) {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(mKey.getBytes());
int mapSize = unpacker.unpackMapHeader();
long offset = 0;
long timestamp = -1;
byte[] keyBytes = EMPTY_BYTES;
for (int i = 0; i < mapSize; i++) {
int key = unpacker.unpackInt();
switch (key) {
case KAFKA_MESSAGE_OFFSET:
offset = unpacker.unpackLong();
break;
case KAFKA_MESSAGE_TIMESTAMP:
timestamp = unpacker.unpackLong();
break;
case KAFKA_HASH_KEY:
int keySize = unpacker.unpackBinaryHeader();
keyBytes = new byte[keySize];
unpacker.readPayload(keyBytes);
break;
}
}
unpacker.close();
return new KeyValue(offset, keyBytes, Arrays.copyOfRange(mValue.getBytes(), 0, mValue.getLength()), timestamp);
} else {
return null;
}
}
示例3: unpackByteBuffer
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
private static ByteBuffer unpackByteBuffer(MessageUnpacker unpack) throws IOException {
ByteBuffer bb = ByteBuffer.allocate(unpack.unpackBinaryHeader());
unpack.readPayload(bb);
bb.flip(); // prepare for read of byte buffer
return bb;
}