@@ -461,6 +461,76 @@ impl<'a> SchemaModule<'a> {
461461 let ptr_size = mem:: size_of :: < ffi:: lysp_import > ( ) ;
462462 Array :: new ( self . context , array as * mut _ , ptr_size)
463463 }
464+
465+ /// Parse a schema module from a string
466+ pub fn parse_string (
467+ context : & ' a Context ,
468+ data : & str ,
469+ schema_input_format : SchemaInputFormat ,
470+ ) -> Result < Self > {
471+ let mut raw: * mut ffi:: lys_module = std:: ptr:: null_mut ( ) ;
472+ let data = CString :: new ( data) . unwrap ( ) ;
473+ let ret = unsafe {
474+ ffi:: lys_parse_mem (
475+ context. raw ,
476+ data. as_ptr ( ) ,
477+ schema_input_format as u32 ,
478+ & mut raw,
479+ )
480+ } ;
481+ if ret != ffi:: LY_ERR :: LY_SUCCESS {
482+ return Err ( Error :: new ( context) ) ;
483+ }
484+ Ok ( Self { context, raw } )
485+ }
486+
487+ /// Parse a schema module from a file
488+ #[ cfg( not( target_os = "windows" ) ) ]
489+ pub fn parse_file < F : std:: os:: unix:: io:: AsRawFd > (
490+ context : & ' a Context ,
491+ fd : F ,
492+ schema_input_format : SchemaInputFormat ,
493+ ) -> Result < Self > {
494+ let mut raw: * mut ffi:: lys_module = std:: ptr:: null_mut ( ) ;
495+ let ret = unsafe {
496+ ffi:: lys_parse_fd (
497+ context. raw ,
498+ fd. as_raw_fd ( ) ,
499+ schema_input_format as u32 ,
500+ & mut raw,
501+ )
502+ } ;
503+ if ret != ffi:: LY_ERR :: LY_SUCCESS {
504+ return Err ( Error :: new ( context) ) ;
505+ }
506+ Ok ( Self { context, raw } )
507+ }
508+
509+ /// Parse a schema module from a file
510+ #[ cfg( target_os = "windows" ) ]
511+ pub fn parse_file < F : std:: os:: unix:: io:: AsRawFd > (
512+ context : & ' a Context ,
513+ file : impl std:: os:: windows:: io:: AsRawHandle ,
514+ schema_input_format : SchemaInputFormat ,
515+ ) -> Result < Self > {
516+ use libc:: open_osfhandle;
517+ let raw_handle = file. as_raw_handle ( ) ;
518+ let fd = unsafe { open_osfhandle ( raw_handle as isize , 0 ) } ;
519+
520+ let mut raw: * mut ffi:: lys_module = std:: ptr:: null_mut ( ) ;
521+ let ret = unsafe {
522+ ffi:: lys_parse_fd (
523+ context. raw ,
524+ fd. as_raw_fd ( ) ,
525+ schema_input_format as u32 ,
526+ & mut raw,
527+ )
528+ } ;
529+ if ret != ffi:: LY_ERR :: LY_SUCCESS {
530+ return Err ( Error :: new ( context) ) ;
531+ }
532+ Ok ( Self { context, raw } )
533+ }
464534}
465535
466536unsafe impl < ' a > Binding < ' a > for SchemaModule < ' a > {
0 commit comments