@@ -10,6 +10,7 @@ pub mod spring_errno;
1010pub mod spring_last_err;
1111mod spring_pipeline;
1212mod spring_sink_row;
13+ mod spring_source_row;
1314
1415use std:: {
1516 ffi:: { c_void, CStr } ,
@@ -25,6 +26,7 @@ use crate::{
2526 spring_last_err:: { update_last_error, LastError } ,
2627 spring_pipeline:: SpringPipeline ,
2728 spring_sink_row:: SpringSinkRow ,
29+ spring_source_row:: SpringSourceRow ,
2830} ;
2931use :: springql:: { error:: SpringError , SpringPipeline as Pipeline } ;
3032
@@ -212,14 +214,72 @@ pub unsafe extern "C" fn spring_pop_non_blocking(
212214 }
213215}
214216
215- /// Frees heap occupied by a `SpringRow`.
217+ /// Push a row into an in memory queue. This is a non-blocking function.
218+ ///
219+ /// # Returns
220+ ///
221+ /// - `Ok`: on success.
222+ /// - `Unavailable`: queue named `queue` does not exist.
223+ #[ no_mangle]
224+ pub unsafe extern "C" fn spring_push (
225+ pipeline : * const SpringPipeline ,
226+ queue : * const c_char ,
227+ row : * const SpringSourceRow ,
228+ ) -> SpringErrno {
229+ let pipeline = ( * pipeline) . as_pipeline ( ) ;
230+ let queue = CStr :: from_ptr ( queue) . to_string_lossy ( ) . into_owned ( ) ;
231+ let source_row = ( * row) . to_row ( ) ;
232+ let result = with_catch ( || pipeline. push ( & queue, source_row) ) ;
233+ match result {
234+ Ok ( ( ) ) => SpringErrno :: Ok ,
235+ Err ( e) => e,
236+ }
237+ }
238+
239+ /// Create a source row from JSON string
240+ ///
241+ /// # Returns
242+ ///
243+ /// - non-NULL: Successfully created a row.
244+ /// - NULL: Error occurred.
245+ ///
246+ /// # Errors
247+ ///
248+ /// - `InvalidFormat`: JSON string is invalid.
249+ #[ no_mangle]
250+ pub unsafe extern "C" fn spring_source_row_from_json ( json : * const c_char ) -> * mut SpringSourceRow {
251+ let json = CStr :: from_ptr ( json) . to_string_lossy ( ) . into_owned ( ) ;
252+ let res_source_row = with_catch ( || :: springql:: SpringSourceRow :: from_json ( & json) ) ;
253+ match res_source_row {
254+ Ok ( source_row) => SpringSourceRow :: new ( source_row) . into_ptr ( ) ,
255+ Err ( _) => ptr:: null_mut ( ) ,
256+ }
257+ }
258+
259+ /// Frees heap occupied by a `SpringSourceRow`.
260+ ///
261+ /// # Returns
262+ ///
263+ /// - `Ok`: on success.
264+ /// - `CNull`: `pipeline` is a NULL pointer.
265+ #[ no_mangle]
266+ pub extern "C" fn spring_source_row_close ( row : * mut SpringSourceRow ) -> SpringErrno {
267+ if row. is_null ( ) {
268+ SpringErrno :: CNull
269+ } else {
270+ SpringSourceRow :: drop ( row) ;
271+ SpringErrno :: Ok
272+ }
273+ }
274+
275+ /// Frees heap occupied by a `SpringSinkRow`.
216276///
217277/// # Returns
218278///
219279/// - `Ok`: on success.
220280/// - `CNull`: `pipeline` is a NULL pointer.
221281#[ no_mangle]
222- pub extern "C" fn spring_row_close ( row : * mut SpringSinkRow ) -> SpringErrno {
282+ pub extern "C" fn spring_sink_row_close ( row : * mut SpringSinkRow ) -> SpringErrno {
223283 if row. is_null ( ) {
224284 SpringErrno :: CNull
225285 } else {
0 commit comments