@@ -14,6 +14,8 @@ use anyhow::anyhow;
1414use anyhow:: Error ;
1515use anyhow:: Result ;
1616use cxx:: SharedPtr ;
17+ use cxx:: UniquePtr ;
18+ use iobuf:: IOBuf ;
1719use storemodel:: FileAuxData as ScmStoreFileAuxData ;
1820use types:: fetch_cause:: FetchCause ;
1921use types:: fetch_mode:: FetchMode ;
@@ -105,15 +107,6 @@ pub(crate) mod ffi {
105107 files : Vec < String > ,
106108 }
107109
108- pub struct Blob {
109- pub ( crate ) bytes : Vec < u8 > ,
110- }
111-
112- pub struct OptionalBlob {
113- present : bool ,
114- blob : Box < Blob > ,
115- }
116-
117110 pub struct FileAuxData {
118111 total_size : u64 ,
119112 content_sha1 : [ u8 ; 20 ] ,
@@ -123,6 +116,9 @@ pub(crate) mod ffi {
123116 unsafe extern "C++" {
124117 include ! ( "eden/scm/lib/backingstore/include/ffi.h" ) ;
125118
119+ #[ namespace = "folly" ]
120+ type IOBuf = iobuf:: IOBuf ;
121+
126122 type GetTreeBatchResolver ;
127123 type GetTreeAuxBatchResolver ;
128124 type GetBlobBatchResolver ;
@@ -146,7 +142,7 @@ pub(crate) mod ffi {
146142 resolve_state : SharedPtr < GetBlobBatchResolver > ,
147143 index : usize ,
148144 error : String ,
149- blob : Box < Blob > ,
145+ blob : UniquePtr < IOBuf > ,
150146 ) ;
151147
152148 unsafe fn sapling_backingstore_get_file_aux_batch_handler (
@@ -202,7 +198,7 @@ pub(crate) mod ffi {
202198 store : & BackingStore ,
203199 node : & [ u8 ] ,
204200 fetch_mode : FetchMode ,
205- ) -> Result < OptionalBlob > ;
201+ ) -> Result < UniquePtr < IOBuf > > ;
206202
207203 pub fn sapling_backingstore_get_blob_batch (
208204 store : & BackingStore ,
@@ -403,20 +399,14 @@ pub fn sapling_backingstore_get_blob(
403399 store : & BackingStore ,
404400 node : & [ u8 ] ,
405401 fetch_mode : ffi:: FetchMode ,
406- ) -> Result < ffi :: OptionalBlob > {
402+ ) -> Result < UniquePtr < IOBuf > > {
407403 // the cause is not propagated for this API
408404 match store. get_blob (
409405 FetchContext :: new_with_cause ( FetchMode :: from ( fetch_mode) , FetchCause :: EdenUnknown ) ,
410406 node,
411407 ) ? {
412- Some ( blob) => Ok ( ffi:: OptionalBlob {
413- blob : Box :: new ( ffi:: Blob { bytes : blob } ) ,
414- present : true ,
415- } ) ,
416- None => Ok ( ffi:: OptionalBlob {
417- blob : Box :: new ( ffi:: Blob { bytes : Vec :: new ( ) } ) ,
418- present : false ,
419- } ) ,
408+ Some ( blob) => Ok ( blob. into_iobuf ( ) . into ( ) ) ,
409+ None => Ok ( UniquePtr :: null ( ) ) ,
420410 }
421411}
422412
@@ -436,11 +426,8 @@ pub fn sapling_backingstore_get_blob_batch(
436426 let result = result. and_then ( |opt| opt. ok_or_else ( || Error :: msg ( "no blob found" ) ) ) ;
437427 let resolver = resolver. clone ( ) ;
438428 let ( error, blob) = match result {
439- Ok ( blob) => ( String :: default ( ) , Box :: new ( ffi:: Blob { bytes : blob } ) ) ,
440- Err ( error) => (
441- format ! ( "{:?}" , error) ,
442- Box :: new ( ffi:: Blob { bytes : vec ! [ ] } ) ,
443- ) ,
429+ Ok ( blob) => ( String :: default ( ) , blob. into_iobuf ( ) . into ( ) ) ,
430+ Err ( error) => ( format ! ( "{:?}" , error) , UniquePtr :: null ( ) ) ,
444431 } ;
445432 unsafe { ffi:: sapling_backingstore_get_blob_batch_handler ( resolver, idx, error, blob) } ;
446433 } ,
0 commit comments