@@ -403,6 +403,43 @@ impl ArrayParts {
403403 } )
404404 }
405405
406+ /// Returns the buffer lengths as stored in the flatbuffer metadata.
407+ ///
408+ /// This reads the buffer descriptors from the flatbuffer, which contain the
409+ /// serialized length of each buffer. This is useful for displaying buffer sizes
410+ /// without needing to access the actual buffer data.
411+ pub fn buffer_lengths ( & self ) -> Vec < usize > {
412+ let fb_array = root :: < fba:: Array > ( self . flatbuffer . as_ref ( ) )
413+ . vortex_expect ( "ArrayParts flatbuffer must be a valid Array" ) ;
414+ fb_array
415+ . buffers ( )
416+ . map ( |buffers| buffers. iter ( ) . map ( |b| b. length ( ) as usize ) . collect ( ) )
417+ . unwrap_or_default ( )
418+ }
419+
420+ /// Create an [`ArrayParts`] from a raw array tree flatbuffer (metadata only).
421+ ///
422+ /// This constructor creates an `ArrayParts` with no buffer data, useful for
423+ /// inspecting the metadata when the actual buffer data is not needed
424+ /// (e.g., displaying buffer sizes from inlined array tree metadata).
425+ ///
426+ /// Note: Calling `buffer()` on the returned `ArrayParts` will fail since
427+ /// no actual buffer data is available.
428+ pub fn from_array_tree ( array_tree : impl Into < ByteBuffer > ) -> VortexResult < Self > {
429+ let fb_buffer = FlatBuffer :: align_from ( array_tree. into ( ) ) ;
430+ let fb_array = root :: < fba:: Array > ( fb_buffer. as_ref ( ) ) ?;
431+ let fb_root = fb_array
432+ . root ( )
433+ . ok_or_else ( || vortex_err ! ( "Array must have a root node" ) ) ?;
434+ let flatbuffer_loc = fb_root. _tab . loc ( ) ;
435+
436+ Ok ( ArrayParts {
437+ flatbuffer : fb_buffer,
438+ flatbuffer_loc,
439+ buffers : Arc :: new ( [ ] ) ,
440+ } )
441+ }
442+
406443 /// Returns the root ArrayNode flatbuffer.
407444 fn flatbuffer ( & self ) -> fba:: ArrayNode < ' _ > {
408445 unsafe { fba:: ArrayNode :: follow ( self . flatbuffer . as_ref ( ) , self . flatbuffer_loc ) }
0 commit comments