@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; } }
if (!unpacker.hasNext()) { return 0; leftEntries = unpacker.unpackMapHeader(); fieldNumber = unpacker.unpackInt(); String name = unpacker.unpackString(); fieldNumber = schema.getFieldNumber(name); if (unpacker.hasNext() && unpacker.getNextFormat().getValueType().isArrayType()) leftItems = unpacker.unpackArrayHeader(); lastNumber = fieldNumber;
public boolean parseBoolean() throws IOException { return unpacker.unpackBoolean(); }
public byte[] parsePayload() throws IOException { int length = unpacker.unpackBinaryHeader(); return unpacker.readPayload(length); }
while (unpacker.hasNext() && amount < readAmount) { MessageFormat format = unpacker.getNextFormat(); ValueType type = format.getValueType(); int length; switch (type) { case NIL: unpacker.unpackNil(); break; case BOOLEAN: o = unpacker.unpackBoolean(); break; case INTEGER: switch (format) { case UINT64: o = unpacker.unpackBigInteger(); break; case INT64: case UINT32: o = unpacker.unpackLong(); break; default: o = unpacker.unpackInt(); break; o = unpacker.unpackDouble(); break; case STRING: o = unpacker.unpackString();
MessageFormat mf = getNextFormat(); switch (mf.getValueType()) { case NIL: readByte(); return ValueFactory.newNil(); case BOOLEAN: return ValueFactory.newBoolean(unpackBoolean()); case INTEGER: switch (mf) { case UINT64: return ValueFactory.newInteger(unpackBigInteger()); default: return ValueFactory.newInteger(unpackLong()); return ValueFactory.newFloat(unpackDouble()); case STRING: { int length = unpackRawStringHeader(); return ValueFactory.newString(readPayload(length), true); int length = unpackBinaryHeader(); return ValueFactory.newBinary(readPayload(length), true); int size = unpackArrayHeader(); Value[] array = new Value[size]; for (int i = 0; i < size; i++) { array[i] = unpackValue(); int size = unpackMapHeader(); Value[] kvs = new Value[size * 2];
switch (format.getValueType()) { case BINARY: int len = unpacker.unpackBinaryHeader(); value.setData(unpacker.readPayload(len)); break; case BOOLEAN: value.setData(unpacker.unpackBoolean()); break; case FLOAT: if (format == MessageFormat.FLOAT64) { value.setData(unpacker.unpackDouble()); } else { value.setData(unpacker.unpackFloat()); value.setData(unpacker.unpackByte()); } else if (format == MessageFormat.INT16 || format == MessageFormat.UINT8) { value.setData(unpacker.unpackShort()); } else if (format == MessageFormat.UINT32 || format == MessageFormat.INT64 || format == MessageFormat.UINT64) { value.setData(unpacker.unpackLong()); } else { value.setData(unpacker.unpackInt()); unpacker.unpackNil(); break; case STRING: value.setData(unpacker.unpackString()); break; default:
@Theory public void testWithoutAckResponse(final boolean sslEnabled) throws Throwable { Exception exception = new ConfigurableTestServer(sslEnabled).run( clientSocket -> { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream()); assertEquals(3, unpacker.unpackArrayHeader()); assertEquals("foo.bar", unpacker.unpackString()); ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue(); Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(1, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt()); unpacker.close(); }, serverPort -> { FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd(); builder.setSslEnabled(sslEnabled); try (Fluency fluency = builder.build(serverPort)) { fluency.emit("foo.bar", new HashMap<>()); } }, 5000); assertNull(exception); }
assertEquals(3, messageUnpacker.unpackArrayHeader()); String tag = messageUnpacker.unpackString(); byte[] payload = messageUnpacker.readPayload(messageUnpacker.unpackBinaryHeader()); messageUnpacker = MessagePack.newDefaultUnpacker(payload); while (messageUnpacker.hasNext()) { assertEquals(2, messageUnpacker.unpackArrayHeader()); ImmutableValue timestamp = messageUnpacker.unpackValue(); int size = messageUnpacker.unpackMapHeader(); assertEquals(3, size); Map<String, Object> data = new HashMap<>(); for (int i = 0; i < size; i++) { String key = messageUnpacker.unpackString(); ImmutableValue value = messageUnpacker.unpackValue(); if (value.isStringValue()) { data.put(key, value.asStringValue().asString());
/** * Create corresponding InfluxDBException from the message pack error body. * @param messagePackErrorBody * @return */ public static InfluxDBException buildExceptionForErrorState(final InputStream messagePackErrorBody) { try { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(messagePackErrorBody); ImmutableMapValue mapVal = (ImmutableMapValue) unpacker.unpackValue(); return InfluxDBException.buildExceptionFromErrorMessage( mapVal.map().get(new ImmutableStringValueImpl("error")).toString()); } catch (Exception e) { return new InfluxDBException(e); } } }
@Override public <T> T deserialize( ModuleDescriptor module, ValueType valueType, InputStream state ) { try( MessageUnpacker unpacker = MessagePack.newDefaultUnpacker( state ) ) { if( !unpacker.hasNext() ) { return null; } ImmutableValue value = unpacker.unpackValue(); return doDeserialize( module, valueType, value ); } catch( IOException ex ) { throw new SerializationException( "Unable to deserialize " + valueType, ex ); } }
ImmutableValue value; try { if (!unpacker.hasNext()) { break; value = unpacker.unpackValue(); LOG.trace("Received a value: local.port={}, remote.port={}", acceptSocket.getLocalPort(), acceptSocket.getPort()); while (eventsUnpacker.hasNext()) { ImmutableArrayValue arrayValue = eventsUnpacker.unpackValue().asArrayValue(); assertEquals(2, arrayValue.size()); Value timestampValue = arrayValue.get(0); unpacker.close();
/** * 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); }
private BObject unpackMap(MessageUnpacker unpacker) throws IOException { var result = this.getFactory().newObject(); int size = unpacker.unpackMapHeader(); for (int i = 0; i < size; i++) { var key = unpacker.unpackString(); var value = unpackAny(unpacker); result.putAny(key, value); } return result; }
public long parseLong() throws IOException { return unpacker.unpackLong(); }
public boolean hasNext() throws IOException { return unpacker.hasNext(); }
public double parseDouble() throws IOException { return unpacker.unpackDouble(); }
private BArray unpackArray(MessageUnpacker unpacker) throws IOException { var result = this.getFactory().newArray(); int size = unpacker.unpackArrayHeader(); for (int i = 0; i < size; i++) { result.addAny(this.unpackAny(unpacker)); } return result; }
private BElement unpackAny(MessageUnpacker unpacker) throws IOException { var format = unpacker.getNextFormat(); switch (format.getValueType()) { case ARRAY: return unpackArray(unpacker); case MAP: return unpackMap(unpacker); case BINARY: case BOOLEAN: case FLOAT: case INTEGER: case NIL: case STRING: return unpackValue(format, unpacker); case EXTENSION: default: break; } throw new InvalidTypeException("Cannot deserialize as BElement for format: " + format); }
tokenPosition = messageUnpacker.getTotalReadBytes(); if (!messageUnpacker.hasNext()) { return null; MessageFormat format = messageUnpacker.getNextFormat(); ValueType valueType = messageUnpacker.getNextFormat().getValueType(); messageUnpacker.unpackNil(); nextToken = JsonToken.VALUE_NULL; break; case BOOLEAN: boolean b = messageUnpacker.unpackBoolean(); if (parsingContext.inObject() && _currToken != JsonToken.FIELD_NAME) { parsingContext.setCurrentName(Boolean.toString(b)); switch (format) { case UINT64: BigInteger bi = messageUnpacker.unpackBigInteger(); if (0 <= bi.compareTo(LONG_MIN) && bi.compareTo(LONG_MAX) <= 0) { type = Type.LONG; long l = messageUnpacker.unpackLong(); if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) { type = Type.INT; case FLOAT: type = Type.DOUBLE; doubleValue = messageUnpacker.unpackDouble();