public ByteBuffer readPayload() throws IOException { int length = unpacker.unpackBinaryHeader(); ByteBuffer buffer = ByteBuffer.allocate(length); unpacker.readPayload(buffer); return buffer; } }
public byte[] parsePayload() throws IOException { int length = unpacker.unpackBinaryHeader(); return unpacker.readPayload(length); }
@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; } }
/** * Reads payload bytes of binary, extension, or raw string types. * * This consumes specified amount of bytes into the specified byte array. * * <p> * This method is equivalent to <code>readPayload(dst, 0, dst.length)</code>. * * @param dst the byte array into which the data is read * @throws IOException when underlying input throws IOException */ public void readPayload(byte[] dst) throws IOException { readPayload(dst, 0, dst.length); }
/** * Reads payload bytes of binary, extension, or raw string types. * * This method allocates a new byte array and consumes specified amount of bytes into the byte array. * * <p> * This method is equivalent to <code>readPayload(new byte[length])</code>. * * @param length number of bytes to be read * @return the new byte array * @throws IOException when underlying input throws IOException */ public byte[] readPayload(int length) throws IOException { byte[] newArray = new byte[length]; readPayload(newArray); return newArray; }
length = unpacker.unpackBinaryHeader(); dst = new byte[length]; unpacker.readPayload(dst); break; case ARRAY: unpacker.readPayload(dst); ByteBuffer bf = ByteBuffer.wrap(dst, 0, extension.getLength()); long epochSeconds = bf.getLong();
/** * Reads payload bytes of binary, extension, or raw string types. * * This consumes specified amount of bytes into the specified byte array. * * @param dst the byte array into which the data is read * @param off the offset in the dst array * @param len the number of bytes to read * @throws IOException when underlying input throws IOException */ public void readPayload(byte[] dst, int off, int len) throws IOException { readPayload(MessageBuffer.wrap(dst), off, len); }
/** * Reads payload bytes of binary, extension, or raw string types as a reference to internal buffer. * * <p> * This consumes specified amount of bytes and returns its reference or copy. This method tries to * return reference as much as possible because it is faster. However, it may copy data to a newly * allocated buffer if reference is not applicable. * * @param length number of bytes to be read * @throws IOException when underlying input throws IOException */ public MessageBuffer readPayloadAsReference(int length) throws IOException { int bufferRemaining = buffer.size() - position; if (bufferRemaining >= length) { MessageBuffer slice = buffer.slice(position, length); position += length; return slice; } MessageBuffer dst = MessageBuffer.allocate(length); readPayload(dst, 0, length); return dst; }
case STRING: { int length = unpackRawStringHeader(); var.setStringValue(readPayload(length)); return var; var.setBinaryValue(readPayload(length)); return var; var.setExtensionValue(extHeader.getType(), readPayload(extHeader.getLength())); return var;
length = unpacker.unpackBinaryHeader(); dst = new byte[length]; unpacker.readPayload(dst); break; case ARRAY: unpacker.readPayload(dst); ByteBuffer bf = ByteBuffer.wrap(dst, 0, extension.getLength()); long epochSeconds = bf.getLong();
type = Type.BYTES; int len = messageUnpacker.unpackBinaryHeader(); bytesValue = messageUnpacker.readPayload(len); if (parsingContext.inObject() && _currToken != JsonToken.FIELD_NAME) { parsingContext.setCurrentName(new String(bytesValue, MessagePack.UTF8)); type = Type.EXT; ExtensionTypeHeader header = messageUnpacker.unpackExtensionTypeHeader(); extensionTypeValue = new MessagePackExtensionType(header.getType(), messageUnpacker.readPayload(header.getLength())); nextToken = JsonToken.VALUE_EMBEDDED_OBJECT; break;
case STRING: { int length = unpackRawStringHeader(); return ValueFactory.newString(readPayload(length), true); return ValueFactory.newBinary(readPayload(length), true); return ValueFactory.newExtension(extHeader.getType(), readPayload(extHeader.getLength()));
byte[] payload = messageUnpacker.readPayload(messageUnpacker.unpackBinaryHeader()); messageUnpacker = MessagePack.newDefaultUnpacker(payload); while (messageUnpacker.hasNext()) {
case BINARY: int len = unpacker.unpackBinaryHeader(); value.setData(unpacker.readPayload(len)); break; case BOOLEAN: