Content.fromInteractionInput constructor

Content.fromInteractionInput(
  1. InteractionInput? interactionInput,
  2. String contentType,
  3. ContentSerdes contentSerdes,
  4. DataSchema? dataSchema,
)

Creates a new Content object from an interactionInput.

If the interactionInput is not a StreamInput, it will be converted to a Stream by the referenced contentSerdes if it supports the specified contentType. In this case, the optional dataSchema will be used for validation before the conversion.

Implementation

factory Content.fromInteractionInput(
  InteractionInput? interactionInput,
  String contentType,
  ContentSerdes contentSerdes,
  DataSchema? dataSchema,
) {
  if (interactionInput == null) {
    return Content(contentType, const Stream.empty());
  }

  switch (interactionInput) {
    case DataSchemaValueInput():
      return contentSerdes.valueToContent(
        interactionInput.dataSchemaValue,
        dataSchema,
        contentType,
      );
    case StreamInput():
      return Content(contentType, interactionInput.byteStream);
  }
}