本文整理汇总了Java中org.msgpack.core.MessageUnpacker.unpackMapHeader方法的典型用法代码示例。如果您正苦于以下问题:Java MessageUnpacker.unpackMapHeader方法的具体用法?Java MessageUnpacker.unpackMapHeader怎么用?Java MessageUnpacker.unpackMapHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.core.MessageUnpacker
的用法示例。
在下文中一共展示了MessageUnpacker.unpackMapHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: Message
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
Message(byte[] bytes) throws IOException {
MessageUnpacker messageUnpacker = MessagePack.newDefaultUnpacker(bytes);
int arrayLen = messageUnpacker.unpackArrayHeader();
log.info("Got array size of: " + arrayLen);
this.type = messageUnpacker.unpackString();
log.info("Message type is:" + this.type);
this.typeEnum = TypeEnum.valueOf(this.type);
if (messageUnpacker.getNextFormat() != MessageFormat.NIL) {
int numMapElems = messageUnpacker.unpackMapHeader();
log.info("Num Data elems" + numMapElems);
this.data = new HashMap<String, Object>();
String key = null;
while (numMapElems > 0) {
if (messageUnpacker.getNextFormat() == MessageFormat.NIL) {
log.info("Key is null");
messageUnpacker.unpackNil();
} else {
key = messageUnpacker.unpackString();
log.info("Key is " + key);
}
MessageFormat messageFormat = messageUnpacker.getNextFormat();
Object value;
switch (messageFormat.getValueType()) {
case BOOLEAN:
value = messageUnpacker.unpackBoolean();
break;
case FLOAT:
value = messageUnpacker.unpackFloat();
break;
case INTEGER:
value = messageUnpacker.unpackInt();
break;
case NIL:
value = null;
messageUnpacker.unpackNil();
break;
case STRING:
value = messageUnpacker.unpackString();
break;
default:
throw new IOException("Message received unsupported type: " + messageFormat.getValueType());
}
log.info("Value is : " + value);
this.data.put(key, value);
numMapElems--;
}
} else {
this.data = null;
}
if (messageUnpacker.getNextFormat() != MessageFormat.NIL) {
this.nodeId = messageUnpacker.unpackString();
} else {
messageUnpacker.unpackNil();
this.nodeId = null;
}
}
示例3: Message
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
protected Message(byte[] bytes) throws IOException {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes);
int arrayHeader = unpacker.unpackArrayHeader();
this.type = unpacker.unpackString();
// unpack data
if (unpacker.getNextFormat() != MessageFormat.NIL) {
int mapSize = unpacker.unpackMapHeader();
this.data = new HashMap<String, Object>(6);
while (mapSize > 0) {
String key = null;
// unpack key
if (unpacker.getNextFormat() == MessageFormat.NIL) {
unpacker.unpackNil();
} else {
key = unpacker.unpackString();
}
// unpack value
MessageFormat messageFormat = unpacker.getNextFormat();
Object value;
switch (messageFormat.getValueType()) {
case BOOLEAN:
value = unpacker.unpackBoolean();
break;
case FLOAT:
value = unpacker.unpackFloat();
break;
case INTEGER:
value = unpacker.unpackInt();
break;
case NIL:
value = null;
unpacker.unpackNil();
break;
case STRING:
value = unpacker.unpackString();
break;
default:
throw new IOException("Message received unsupported type: " + messageFormat.getValueType());
}
if (null != key) {
this.data.put(key, value);
}
mapSize--;
}
} else {
this.data = null;
}
if (unpacker.getNextFormat() != MessageFormat.NIL) {
this.nodeID = unpacker.unpackString();
} else {
unpacker.unpackNil();
this.nodeID = null;
}
unpacker.close();
}
示例4: readSpan
import org.msgpack.core.MessageUnpacker; //导入方法依赖的package包/类
/**
* Read a span. Used in unit tests. Not optimized.
*/
static Span readSpan(MessageUnpacker unpacker) throws IOException {
int numEntries = unpacker.unpackMapHeader();
MilliSpan.Builder builder = new MilliSpan.Builder();
while (--numEntries >= 0) {
String key = unpacker.unpackString();
if (key.length() != 1) {
throw new IOException("Unknown key " + key);
}
switch (key.charAt(0)) {
case 'a':
builder.spanId(readSpanId(unpacker));
break;
case 'b':
builder.begin(unpacker.unpackLong());
break;
case 'e':
builder.end(unpacker.unpackLong());
break;
case 'd':
builder.description(unpacker.unpackString());
break;
case 'r':
builder.tracerId(unpacker.unpackString());
break;
case 'p':
int numParents = unpacker.unpackArrayHeader();
SpanId[] parents = new SpanId[numParents];
for (int i = 0; i < numParents; i++) {
parents[i] = readSpanId(unpacker);
}
builder.parents(parents);
break;
case 'n':
int mapEntries = unpacker.unpackMapHeader();
HashMap<String, String> entries =
new HashMap<String, String>(mapEntries);
for (int i = 0; i < mapEntries; i++) {
String k = unpacker.unpackString();
String v = unpacker.unpackString();
entries.put(k, v);
}
builder.traceInfo(entries);
break;
case 't':
int listEntries = unpacker.unpackArrayHeader();
ArrayList<TimelineAnnotation> list =
new ArrayList<TimelineAnnotation>(listEntries);
for (int i = 0; i < listEntries; i++) {
int timelineObjectSize = unpacker.unpackMapHeader();
long time = 0;
String msg = "";
for (int j = 0; j < timelineObjectSize; j++) {
String tlKey = unpacker.unpackString();
if (tlKey.length() != 1) {
throw new IOException("Unknown timeline map key " + tlKey);
}
switch (tlKey.charAt(0)) {
case 't':
time = unpacker.unpackLong();
break;
case 'm':
msg = unpacker.unpackString();
break;
default:
throw new IOException("Unknown timeline map key " + tlKey);
}
}
list.add(new TimelineAnnotation(time, msg));
}
builder.timeline(list);
break;
default:
throw new IOException("Unknown key " + key);
}
}
return builder.build();
}