Future decode()

in functions_framework/lib/src/json_request_utils.dart [89:108]


  Future<({MediaType mimeType, Object? data})> decode() async {
    final type = mediaTypeFromRequest(this);
    final supportedType = SupportedContentTypes.values.singleWhere(
      (element) => element.value == type.mimeType,
      orElse: () => throw BadRequestException(
        400,
        'Unsupported encoding "$type". '
        'Supported types: '
        '${SupportedContentTypes.values.map((e) => '"${e.value}"').join(', ')}',
      ),
    );

    return (
      mimeType: type,
      data: switch (supportedType) {
        SupportedContentTypes.json => await decodeJson(),
        SupportedContentTypes.protobuf => await readBytes(),
      },
    );
  }