Source:
<code>public int writeSubscriptionBatch(final OutputStream os, final SubscriptionCursor cursor, final List<ConsumedEvent> events, final Optional<String> metadata) throws IOException { int byteCount = B_FIXED_BYTE_COUNT_SUBSCRIPTION; os.write(B_CURSOR_PARTITION_BEGIN); final byte[] partition = cursor.getPartition().getBytes(StandardCharsets.UTF_8); os.write(partition); byteCount += partition.length; os.write(B_OFFSET_BEGIN); final byte[] offset = cursor.getOffset().getBytes(StandardCharsets.UTF_8); os.write(offset); byteCount += offset.length; os.write(B_EVENT_TYPE_BEGIN); final byte[] eventType = cursor.getEventType().getBytes(StandardCharsets.UTF_8); os.write(eventType); byteCount += eventType.length; os.write(B_CURSOR_TOKEN_BEGIN); final byte[] cursorToken = cursor.getCursorToken().getBytes(StandardCharsets.UTF_8); os.write(cursorToken); byteCount += cursorToken.length; os.write(B_CURSOR_PARTITION_END); if (!events.isEmpty()) { os.write(B_EVENTS_ARRAY_BEGIN); for (int i = 0; i < events.size(); i++) { final byte[] event = events.get(i).getEvent().getBytes(StandardCharsets.UTF_8); os.write(event); byteCount += event.length; if (i < (events.size() - 1)) { os.write(B_COMMA_DELIM); } else { os.write(B_CLOSE_BRACKET); } } } if (metadata.isPresent()) { os.write(B_DEBUG_BEGIN); byteCount += B_DEBUG_BEGIN.length; final byte[] debug = metadata.get().getBytes(StandardCharsets.UTF_8); os.write(debug); <START> byteCount += debug.length; <END> os.write(B_DEBUG_END); byteCount += B_DEBUG_END.length; } os.write(B_CLOSE_CURLY_BRACKET); os.write(B_BATCH_SEPARATOR); return byteCount; }</code><technical_language>metadata event type name possibly escaped? (probably not, ensure checked debug calls)</technical_language>

Target:
public int writeSubscriptionBatch(final OutputStream os, final SubscriptionCursor cursor, final List<ConsumedEvent> events, final Optional<String> metadata) throws IOException { int byteCount = B_FIXED_BYTE_COUNT_SUBSCRIPTION; os.write(B_CURSOR_PARTITION_BEGIN); final byte[] partition = cursor.getPartition().getBytes(UTF_8); os.write(partition); byteCount += partition.length; os.write(B_OFFSET_BEGIN); final byte[] offset = cursor.getOffset().getBytes(UTF_8); os.write(offset); byteCount += offset.length; os.write(B_EVENT_TYPE_BEGIN); final byte[] eventType = cursor.getEventType().getBytes(UTF_8); os.write(eventType); byteCount += eventType.length; os.write(B_CURSOR_TOKEN_BEGIN); final byte[] cursorToken = cursor.getCursorToken().getBytes(UTF_8); os.write(cursorToken); byteCount += cursorToken.length; os.write(B_CURSOR_PARTITION_END); if (!events.isEmpty()) { os.write(B_EVENTS_ARRAY_BEGIN); for (int i = 0; i < events.size(); i++) { final byte[] event = events.get(i).getEvent(); os.write(event); byteCount += event.length; if (i < (events.size() - 1)) { os.write(B_COMMA_DELIM); } else { os.write(B_CLOSE_BRACKET); } } } if (metadata.isPresent()) { os.write(B_DEBUG_BEGIN); byteCount += B_DEBUG_BEGIN.length; final byte[] debug = metadata.get().getBytes(UTF_8); os.write(debug); byteCount += debug.length; os.write(B_DEBUG_END); byteCount += B_DEBUG_END.length; } os.write(B_CLOSE_CURLY_BRACKET); os.write(B_BATCH_SEPARATOR); os.flush(); return byteCount; }