public Bytes deserialize(String topic, byte[] data) { if (data == null) return null; return new Bytes(data); }
public static Bytes wrap(byte[] bytes) { if (bytes == null) return null; return new Bytes(bytes); }
private Result getFormatter(final byte[] data) { final ConsumerRecord<String, Bytes> record = new ConsumerRecord<>( "some-topic", 1, 1, "key", new Bytes(data)); final RecordFormatter formatter = new RecordFormatter(schemaRegistryClient, "some-topic"); final ConsumerRecords<String, Bytes> records = new ConsumerRecords<>( ImmutableMap.of(new TopicPartition("some-topic", 1), ImmutableList.of(record))); final List<String> formatted = formatter.format(records); assertThat("Only expect one line", formatted, hasSize(1)); return new Result(formatter.getFormat(), formatted.get(0)); }
private KeyValue<Bytes, byte[]> getKeyValue() { return new KeyValue<>(new Bytes(iter.key()), iter.value()); }
/** * Attempts to convert the object to the same type as the serialized class specified */ protected Object tryConvertToSerializedType(Exchange exchange, Object object, String serializerClass) { Object answer = null; if (KafkaConstants.KAFKA_DEFAULT_SERIALIZER.equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange, object); } else if ("org.apache.kafka.common.serialization.ByteArraySerializer".equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(byte[].class, exchange, object); } else if ("org.apache.kafka.common.serialization.ByteBufferSerializer".equals(serializerClass)) { answer = exchange.getContext().getTypeConverter().tryConvertTo(ByteBuffer.class, exchange, object); } else if ("org.apache.kafka.common.serialization.BytesSerializer".equals(serializerClass)) { // we need to convert to byte array first byte[] array = exchange.getContext().getTypeConverter().tryConvertTo(byte[].class, exchange, object); if (array != null) { answer = new Bytes(array); } } return answer != null ? answer : object; }