public byte[] serialize(String topic, Bytes data) { if (data == null) return null; return data.get(); }
@Override public boolean equals(Object other) { if (this == other) return true; if (other == null) return false; // we intentionally use the function to compute hashcode here if (this.hashCode() != other.hashCode()) return false; if (other instanceof Bytes) return Arrays.equals(this.bytes, ((Bytes) other).get()); return false; }
@Override public Optional<Formatter> maybeGetFormatter( final String topicName, final ConsumerRecord<String, Bytes> record, final KafkaAvroDeserializer avroDeserializer, final DateFormat dateFormat) { try { avroDeserializer.deserialize(topicName, record.value().get()); return Optional.of(createFormatter(topicName, avroDeserializer, dateFormat)); } catch (final Throwable t) { return Optional.empty(); } }
value = ((Bytes) value).get();
private long computeRecordSize(final Bytes key, final ContextualRecord value) { long size = 0L; size += 8; // buffer time size += key.get().length; if (value != null) { size += value.sizeBytes(); } return size; } }
long size() { return key.get().length + 8 + // entry 8 + // previous 8 + // next entry.size(); }
public static Bytes toStoreKeyBinary(final Bytes key, final long timestamp, final int seqnum) { final byte[] serializedKey = key.get(); return toStoreKeyBinary(serializedKey, timestamp, seqnum); }
@Override public long segmentTimestamp(final Bytes key) { return WindowKeySchema.extractStoreTimestamp(key.get()); }
@SuppressWarnings("unchecked") @Override public synchronized void put(final Bytes key, final byte[] value) { Objects.requireNonNull(key, "key cannot be null"); validateStoreOpen(); putInternal(key.get(), value); }
@Override public Long peekNextKey() { return WindowKeySchema.extractStoreTimestamp(bytesIterator.peekNextKey().get()); }
@Override public synchronized byte[] get(final Bytes key) { validateStoreOpen(); return getInternal(key.get()); }
public static byte[] toBinary(final Windowed<Bytes> sessionKey) { final byte[] bytes = sessionKey.key().get(); final ByteBuffer buf = ByteBuffer.allocate(bytes.length + 2 * TIMESTAMP_SIZE); buf.put(bytes); buf.putLong(sessionKey.window().end()); buf.putLong(sessionKey.window().start()); return buf.array(); } }
@Override public KeyValue<Windowed<K>, V> next() { final KeyValue<Bytes, byte[]> next = bytesIterator.next(); final long timestamp = WindowKeySchema.extractStoreTimestamp(next.key.get()); final K key = WindowKeySchema.extractStoreKey(next.key.get(), serdes); final V value = serdes.valueFrom(next.value); return KeyValue.pair( new Windowed<>(key, WindowKeySchema.timeWindowForSize(timestamp, windowSize)), value ); }
public static Windowed<Bytes> from(final Bytes bytesKey) { final byte[] binaryKey = bytesKey.get(); final Window window = extractWindow(binaryKey); return new Windowed<>(Bytes.wrap(extractKeyBytes(binaryKey)), window); }
public static Bytes toStoreKeyBinary(final Windowed<Bytes> timeKey, final int seqnum) { final byte[] bytes = timeKey.key().get(); return toStoreKeyBinary(bytes, timeKey.window().start(), seqnum); }
@Override public Windowed<K> peekNextKey() { final byte[] nextKey = bytesIterator.peekNextKey().get(); final long timestamp = WindowKeySchema.extractStoreTimestamp(nextKey); final K key = WindowKeySchema.extractStoreKey(nextKey, serdes); return new Windowed<>(key, WindowKeySchema.timeWindowForSize(timestamp, windowSize)); }
@Override Windowed<Bytes> deserializeCacheKey(final Bytes cacheKey) { final byte[] binaryKey = cacheFunction.key(cacheKey).get(); final byte[] keyBytes = SessionKeySchema.extractKeyBytes(binaryKey); final Window window = SessionKeySchema.extractWindow(binaryKey); return new Windowed<>(Bytes.wrap(keyBytes), window); }
@Override public KeyValue<Windowed<K>, V> next() { final KeyValue<Bytes, byte[]> next = bytesIterator.next(); return KeyValue.pair(SessionKeySchema.from(next.key.get(), serdes.keyDeserializer(), serdes.topic()), serdes.valueFrom(next.value)); }
@Override public void apply(final List<ThreadCache.DirtyEntry> entries) { for (final ThreadCache.DirtyEntry entry : entries) { final byte[] binaryWindowKey = cacheFunction.key(entry.key()).get(); final long timestamp = WindowKeySchema.extractStoreTimestamp(binaryWindowKey); final Windowed<K> windowedKey = WindowKeySchema.fromStoreKey(binaryWindowKey, windowSize, serdes); final Bytes key = Bytes.wrap(WindowKeySchema.extractStoreKeyBytes(binaryWindowKey)); maybeForward(entry, key, windowedKey, (InternalProcessorContext) context); underlying.put(key, entry.newValue(), timestamp); } } });