@@ -514,6 +514,27 @@ fn debug_js_to_clrepr_to_js(mut cx: FunctionContext) -> JsResult<JsValue> {
514514
515515//============ sql orchestrator ===================
516516
517+ fn json_to_array_buffer < ' a , C > (
518+ mut cx : C ,
519+ json_data : Result < String , anyhow:: Error > ,
520+ ) -> JsResult < ' a , JsArrayBuffer >
521+ where
522+ C : Context < ' a > ,
523+ {
524+ match json_data {
525+ Ok ( json_data) => {
526+ let json_bytes = json_data. as_bytes ( ) ;
527+ let mut js_buffer = cx. array_buffer ( json_bytes. len ( ) ) ?;
528+ {
529+ let buffer = js_buffer. as_mut_slice ( & mut cx) ;
530+ buffer. copy_from_slice ( json_bytes) ;
531+ }
532+ Ok ( js_buffer)
533+ }
534+ Err ( err) => cx. throw_error ( err. to_string ( ) ) ,
535+ }
536+ }
537+
517538fn parse_cubestore_ws_result_message ( mut cx : FunctionContext ) -> JsResult < JsPromise > {
518539 let msg = cx. argument :: < JsBuffer > ( 0 ) ?;
519540 let msg_data = msg. as_slice ( & cx) . to_vec ( ) ;
@@ -617,20 +638,7 @@ fn final_cubestore_result(mut cx: FunctionContext) -> JsResult<JsPromise> {
617638 Err ( err) => Err ( anyhow:: Error :: from ( err) ) ,
618639 }
619640 } )
620- . promise ( move |mut cx, json_string| match json_string {
621- Ok ( json_string) => {
622- let json_bytes = json_string. as_bytes ( ) ;
623-
624- let mut js_buffer = cx. array_buffer ( json_bytes. len ( ) ) ?;
625- {
626- let buffer = js_buffer. as_mut_slice ( & mut cx) ;
627- buffer. copy_from_slice ( json_bytes) ;
628- }
629-
630- Ok ( js_buffer)
631- }
632- Err ( err) => cx. throw_error ( err. to_string ( ) ) ,
633- } ) ;
641+ . promise ( move |cx, json_data| json_to_array_buffer ( cx, json_data) ) ;
634642
635643 Ok ( promise)
636644}
@@ -679,20 +687,7 @@ fn final_cubestore_result_array(mut cx: FunctionContext) -> JsResult<JsPromise>
679687 Err ( err) => Err ( anyhow:: Error :: from ( err) ) ,
680688 }
681689 } )
682- . promise ( move |mut cx, json_data| match json_data {
683- Ok ( json_data) => {
684- let json_bytes = json_data. as_bytes ( ) ;
685-
686- let mut js_buffer = cx. array_buffer ( json_bytes. len ( ) ) ?;
687- {
688- let buffer = js_buffer. as_mut_slice ( & mut cx) ;
689- buffer. copy_from_slice ( json_bytes) ;
690- }
691-
692- Ok ( js_buffer)
693- }
694- Err ( err) => cx. throw_error ( err. to_string ( ) ) ,
695- } ) ;
690+ . promise ( move |cx, json_data| json_to_array_buffer ( cx, json_data) ) ;
696691
697692 Ok ( promise)
698693}
@@ -733,20 +728,7 @@ fn final_cubestore_result_multi(mut cx: FunctionContext) -> JsResult<JsPromise>
733728 Err ( err) => Err ( anyhow:: Error :: from ( err) ) ,
734729 }
735730 } )
736- . promise ( move |mut cx, json_data| match json_data {
737- Ok ( json_data) => {
738- let json_bytes = json_data. as_bytes ( ) ;
739-
740- let mut js_buffer = cx. array_buffer ( json_bytes. len ( ) ) ?;
741- {
742- let buffer = js_buffer. as_mut_slice ( & mut cx) ;
743- buffer. copy_from_slice ( json_bytes) ;
744- }
745-
746- Ok ( js_buffer)
747- }
748- Err ( err) => cx. throw_error ( err. to_string ( ) ) ,
749- } ) ;
731+ . promise ( move |cx, json_data| json_to_array_buffer ( cx, json_data) ) ;
750732
751733 Ok ( promise)
752734}
0 commit comments