#![allow(dead_code)]
use std::ffi::{CStr, c_char};
use blazen_llm::compute::{
AudioResult as InnerAudioResult, ImageResult as InnerImageResult,
ThreeDResult as InnerThreeDResult, TranscriptionResult as InnerTranscriptionResult,
TranscriptionSegment as InnerTranscriptionSegment, VideoResult as InnerVideoResult,
VoiceHandle as InnerVoiceHandle,
};
use blazen_uniffi::errors::BlazenError as InnerError;
use crate::error::BlazenError;
use crate::string::alloc_cstring;
fn write_internal_err(out_err: *mut *mut BlazenError, message: String) {
if out_err.is_null() {
return;
}
unsafe {
*out_err = BlazenError::from(InnerError::Internal { message }).into_ptr();
}
}
unsafe fn read_json_input<'a>(
json: *const c_char,
fn_name: &str,
out_err: *mut *mut BlazenError,
) -> Option<&'a str> {
if json.is_null() {
write_internal_err(out_err, format!("{fn_name}: json pointer is null"));
return None;
}
let cstr = unsafe { CStr::from_ptr(json) };
match cstr.to_str() {
Ok(s) => Some(s),
Err(e) => {
write_internal_err(out_err, format!("{fn_name}: input is not valid UTF-8: {e}"));
None
}
}
}
fn alloc_json_cstring(value: &serde_json::Value) -> *mut c_char {
match serde_json::to_string(value) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[repr(C)]
pub struct BlazenTranscriptionSegment(pub(crate) InnerTranscriptionSegment);
impl BlazenTranscriptionSegment {
pub(crate) fn into_ptr(self) -> *mut BlazenTranscriptionSegment {
Box::into_raw(Box::new(self))
}
}
impl From<InnerTranscriptionSegment> for BlazenTranscriptionSegment {
fn from(inner: InnerTranscriptionSegment) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_segment_text(
handle: *const BlazenTranscriptionSegment,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let s = unsafe { &*handle };
alloc_cstring(&s.0.text)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_segment_start(
handle: *const BlazenTranscriptionSegment,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let s = unsafe { &*handle };
s.0.start
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_segment_end(
handle: *const BlazenTranscriptionSegment,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let s = unsafe { &*handle };
s.0.end
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_segment_speaker(
handle: *const BlazenTranscriptionSegment,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let s = unsafe { &*handle };
match &s.0.speaker {
Some(v) => alloc_cstring(v),
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_segment_free(
handle: *mut BlazenTranscriptionSegment,
) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenImageResult(pub(crate) InnerImageResult);
impl BlazenImageResult {
pub(crate) fn into_ptr(self) -> *mut BlazenImageResult {
Box::into_raw(Box::new(self))
}
}
impl From<InnerImageResult> for BlazenImageResult {
fn from(inner: InnerImageResult) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_images_count(
handle: *const BlazenImageResult,
) -> usize {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.images.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_images_get_json(
handle: *const BlazenImageResult,
idx: usize,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match r.0.images.get(idx) {
Some(img) => match serde_json::to_string(img) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_image_count(handle: *const BlazenImageResult) -> u32 {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.image_count
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_cost(handle: *const BlazenImageResult) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.cost.unwrap_or(0.0)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_has_cost(handle: *const BlazenImageResult) -> bool {
if handle.is_null() {
return false;
}
let r = unsafe { &*handle };
r.0.cost.is_some()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_metadata_json(
handle: *const BlazenImageResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_json_cstring(&r.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_timing_json(
handle: *const BlazenImageResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match serde_json::to_string(&r.0.timing) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_usage_json(
handle: *const BlazenImageResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.usage {
Some(u) => match serde_json::to_string(u) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_free(handle: *mut BlazenImageResult) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenVideoResult(pub(crate) InnerVideoResult);
impl BlazenVideoResult {
pub(crate) fn into_ptr(self) -> *mut BlazenVideoResult {
Box::into_raw(Box::new(self))
}
}
impl From<InnerVideoResult> for BlazenVideoResult {
fn from(inner: InnerVideoResult) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_videos_count(
handle: *const BlazenVideoResult,
) -> usize {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.videos.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_videos_get_json(
handle: *const BlazenVideoResult,
idx: usize,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match r.0.videos.get(idx) {
Some(v) => match serde_json::to_string(v) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_video_seconds(
handle: *const BlazenVideoResult,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.video_seconds
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_cost(handle: *const BlazenVideoResult) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.cost.unwrap_or(0.0)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_has_cost(handle: *const BlazenVideoResult) -> bool {
if handle.is_null() {
return false;
}
let r = unsafe { &*handle };
r.0.cost.is_some()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_metadata_json(
handle: *const BlazenVideoResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_json_cstring(&r.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_timing_json(
handle: *const BlazenVideoResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match serde_json::to_string(&r.0.timing) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_usage_json(
handle: *const BlazenVideoResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.usage {
Some(u) => match serde_json::to_string(u) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_free(handle: *mut BlazenVideoResult) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenAudioResult(pub(crate) InnerAudioResult);
impl BlazenAudioResult {
pub(crate) fn into_ptr(self) -> *mut BlazenAudioResult {
Box::into_raw(Box::new(self))
}
}
impl From<InnerAudioResult> for BlazenAudioResult {
fn from(inner: InnerAudioResult) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_audio_count(
handle: *const BlazenAudioResult,
) -> usize {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.audio.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_audio_get_json(
handle: *const BlazenAudioResult,
idx: usize,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match r.0.audio.get(idx) {
Some(a) => match serde_json::to_string(a) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_audio_seconds(
handle: *const BlazenAudioResult,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.audio_seconds
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_cost(handle: *const BlazenAudioResult) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.cost.unwrap_or(0.0)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_has_cost(handle: *const BlazenAudioResult) -> bool {
if handle.is_null() {
return false;
}
let r = unsafe { &*handle };
r.0.cost.is_some()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_metadata_json(
handle: *const BlazenAudioResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_json_cstring(&r.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_timing_json(
handle: *const BlazenAudioResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match serde_json::to_string(&r.0.timing) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_usage_json(
handle: *const BlazenAudioResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.usage {
Some(u) => match serde_json::to_string(u) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_free(handle: *mut BlazenAudioResult) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenThreeDResult(pub(crate) InnerThreeDResult);
impl BlazenThreeDResult {
pub(crate) fn into_ptr(self) -> *mut BlazenThreeDResult {
Box::into_raw(Box::new(self))
}
}
impl From<InnerThreeDResult> for BlazenThreeDResult {
fn from(inner: InnerThreeDResult) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_models_count(
handle: *const BlazenThreeDResult,
) -> usize {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.models.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_models_get_json(
handle: *const BlazenThreeDResult,
idx: usize,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match r.0.models.get(idx) {
Some(m) => match serde_json::to_string(m) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_cost(handle: *const BlazenThreeDResult) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.cost.unwrap_or(0.0)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_has_cost(handle: *const BlazenThreeDResult) -> bool {
if handle.is_null() {
return false;
}
let r = unsafe { &*handle };
r.0.cost.is_some()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_metadata_json(
handle: *const BlazenThreeDResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_json_cstring(&r.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_timing_json(
handle: *const BlazenThreeDResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match serde_json::to_string(&r.0.timing) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_usage_json(
handle: *const BlazenThreeDResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.usage {
Some(u) => match serde_json::to_string(u) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_free(handle: *mut BlazenThreeDResult) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenTranscriptionResult(pub(crate) InnerTranscriptionResult);
impl BlazenTranscriptionResult {
pub(crate) fn into_ptr(self) -> *mut BlazenTranscriptionResult {
Box::into_raw(Box::new(self))
}
}
impl From<InnerTranscriptionResult> for BlazenTranscriptionResult {
fn from(inner: InnerTranscriptionResult) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_text(
handle: *const BlazenTranscriptionResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_cstring(&r.0.text)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_segments_count(
handle: *const BlazenTranscriptionResult,
) -> usize {
if handle.is_null() {
return 0;
}
let r = unsafe { &*handle };
r.0.segments.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_segments_get(
handle: *const BlazenTranscriptionResult,
idx: usize,
) -> *mut BlazenTranscriptionSegment {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match r.0.segments.get(idx) {
Some(seg) => BlazenTranscriptionSegment(seg.clone()).into_ptr(),
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_language(
handle: *const BlazenTranscriptionResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.language {
Some(s) => alloc_cstring(s),
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_audio_seconds(
handle: *const BlazenTranscriptionResult,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.audio_seconds
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_cost(
handle: *const BlazenTranscriptionResult,
) -> f64 {
if handle.is_null() {
return 0.0;
}
let r = unsafe { &*handle };
r.0.cost.unwrap_or(0.0)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_has_cost(
handle: *const BlazenTranscriptionResult,
) -> bool {
if handle.is_null() {
return false;
}
let r = unsafe { &*handle };
r.0.cost.is_some()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_metadata_json(
handle: *const BlazenTranscriptionResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
alloc_json_cstring(&r.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_timing_json(
handle: *const BlazenTranscriptionResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match serde_json::to_string(&r.0.timing) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_usage_json(
handle: *const BlazenTranscriptionResult,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let r = unsafe { &*handle };
match &r.0.usage {
Some(u) => match serde_json::to_string(u) {
Ok(s) => alloc_cstring(&s),
Err(_) => std::ptr::null_mut(),
},
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_free(handle: *mut BlazenTranscriptionResult) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[repr(C)]
pub struct BlazenVoiceHandle(pub(crate) InnerVoiceHandle);
impl BlazenVoiceHandle {
pub(crate) fn into_ptr(self) -> *mut BlazenVoiceHandle {
Box::into_raw(Box::new(self))
}
}
impl From<InnerVoiceHandle> for BlazenVoiceHandle {
fn from(inner: InnerVoiceHandle) -> Self {
Self(inner)
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_id(handle: *const BlazenVoiceHandle) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
alloc_cstring(&v.0.id)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_name(handle: *const BlazenVoiceHandle) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
alloc_cstring(&v.0.name)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_provider(
handle: *const BlazenVoiceHandle,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
alloc_cstring(&v.0.provider)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_language(
handle: *const BlazenVoiceHandle,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
match &v.0.language {
Some(s) => alloc_cstring(s),
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_description(
handle: *const BlazenVoiceHandle,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
match &v.0.description {
Some(s) => alloc_cstring(s),
None => std::ptr::null_mut(),
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_metadata_json(
handle: *const BlazenVoiceHandle,
) -> *mut c_char {
if handle.is_null() {
return std::ptr::null_mut();
}
let v = unsafe { &*handle };
alloc_json_cstring(&v.0.metadata)
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_free(handle: *mut BlazenVoiceHandle) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_audio_result_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenAudioResult {
let Some(s) = (unsafe { read_json_input(json, "blazen_audio_result_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerAudioResult>(s) {
Ok(inner) => BlazenAudioResult(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_audio_result_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_image_result_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenImageResult {
let Some(s) = (unsafe { read_json_input(json, "blazen_image_result_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerImageResult>(s) {
Ok(inner) => BlazenImageResult(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_image_result_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_video_result_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenVideoResult {
let Some(s) = (unsafe { read_json_input(json, "blazen_video_result_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerVideoResult>(s) {
Ok(inner) => BlazenVideoResult(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_video_result_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_three_d_result_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenThreeDResult {
let Some(s) = (unsafe { read_json_input(json, "blazen_three_d_result_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerThreeDResult>(s) {
Ok(inner) => BlazenThreeDResult(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_three_d_result_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_transcription_result_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenTranscriptionResult {
let Some(s) =
(unsafe { read_json_input(json, "blazen_transcription_result_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerTranscriptionResult>(s) {
Ok(inner) => BlazenTranscriptionResult(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_transcription_result_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenVoiceHandle {
let Some(s) = (unsafe { read_json_input(json, "blazen_voice_handle_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<InnerVoiceHandle>(s) {
Ok(inner) => BlazenVoiceHandle(inner).into_ptr(),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_voice_handle_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[repr(C)]
pub struct BlazenVoiceHandleArray {
pub(crate) inner: Vec<InnerVoiceHandle>,
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_array_from_json(
json: *const c_char,
out_err: *mut *mut BlazenError,
) -> *mut BlazenVoiceHandleArray {
let Some(s) =
(unsafe { read_json_input(json, "blazen_voice_handle_array_from_json", out_err) })
else {
return std::ptr::null_mut();
};
match serde_json::from_str::<Vec<InnerVoiceHandle>>(s) {
Ok(inner) => Box::into_raw(Box::new(BlazenVoiceHandleArray { inner })),
Err(e) => {
write_internal_err(
out_err,
format!("blazen_voice_handle_array_from_json: deserialize failed: {e}"),
);
std::ptr::null_mut()
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_array_len(
handle: *const BlazenVoiceHandleArray,
) -> usize {
if handle.is_null() {
return 0;
}
let a = unsafe { &*handle };
a.inner.len()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_array_take(
handle: *mut BlazenVoiceHandleArray,
idx: usize,
) -> *mut BlazenVoiceHandle {
if handle.is_null() {
return std::ptr::null_mut();
}
let a = unsafe { &mut *handle };
if idx >= a.inner.len() {
return std::ptr::null_mut();
}
let inner = a.inner.remove(idx);
BlazenVoiceHandle(inner).into_ptr()
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn blazen_voice_handle_array_free(handle: *mut BlazenVoiceHandleArray) {
if handle.is_null() {
return;
}
drop(unsafe { Box::from_raw(handle) });
}