.
- * When someone calls "lookupName('ContainerName')", we return a nested DataSource
- * that acts like a string.
+ * A DataSource that parses "model_binding_data" from the host.
+ *
+ * Dispatches based on content_type:
+ *
+ * - "application/x-protobuf" with source "AzureKafkaRecord" — Protobuf deserialization to KafkaRecord
+ * - all other — JSON parsing into Map<String,String> (legacy behavior)
+ *
*/
public class RpcModelBindingDataSource extends DataSource {
private static final Logger LOGGER = WorkerLogManager.getSystemLogger();
private static final Gson GSON = new Gson();
- // This holds the parsed key-value pairs from the model_binding_data.content JSON
+ // This holds the parsed key-value pairs from the model_binding_data.content JSON (null for Protobuf path)
private final Map contentMap;
+ // Precomputed KafkaRecord for Protobuf path (null for JSON path)
+ private final KafkaRecord kafkaRecord;
+
public RpcModelBindingDataSource(String name, ModelBindingData modelData) {
super(name, modelData, MODEL_BINDING_DATA_OPERATIONS);
- // Parse the JSON in modelData.getContent() => Map
- String jsonString = modelData.getContent().toStringUtf8();
- if (jsonString == null || jsonString.isEmpty()) {
- throw new IllegalArgumentException(
- "model_binding_data.content is empty or missing for name: " + name
- );
- }
+ String contentType = modelData.getContentType();
+ String source = modelData.getSource();
- Map parsed = null;
- try {
- Type mapType = new TypeToken