@@ -109,12 +109,35 @@ struct ListBlobsResponseInternal {
109109 pub blobs : Blobs ,
110110}
111111
112- #[ derive( Debug , Clone , PartialEq , Eq , Deserialize ) ]
112+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Default ) ]
113113#[ serde( rename_all = "PascalCase" ) ]
114114pub struct Blobs {
115- pub blob_prefix : Option < Vec < BlobPrefix > > ,
116- #[ serde( rename = "Blob" , default ) ]
117- pub blobs : Vec < Blob > ,
115+ #[ serde( rename = "$value" , default ) ]
116+ pub items : Vec < BlobItem > ,
117+ }
118+
119+ impl Blobs {
120+ pub fn blobs ( & self ) -> impl Iterator < Item = & Blob > {
121+ self . items . iter ( ) . filter_map ( |item| match item {
122+ BlobItem :: Blob ( blob) => Some ( blob) ,
123+ _ => None ,
124+ } )
125+ }
126+
127+ pub fn prefixes ( & self ) -> impl Iterator < Item = & BlobPrefix > {
128+ self . items . iter ( ) . filter_map ( |item| match item {
129+ BlobItem :: BlobPrefix ( prefix) => Some ( prefix) ,
130+ _ => None ,
131+ } )
132+ }
133+ }
134+
135+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize ) ]
136+ #[ serde( rename_all = "PascalCase" ) ]
137+ #[ allow( clippy:: large_enum_variant) ]
138+ pub enum BlobItem {
139+ Blob ( Blob ) ,
140+ BlobPrefix ( BlobPrefix ) ,
118141}
119142
120143#[ derive( Debug , Clone , PartialEq , Eq , Deserialize ) ]
@@ -315,4 +338,90 @@ mod tests {
315338 let bytes = Bytes :: from ( S ) ;
316339 let _list_blobs_response_internal: ListBlobsResponseInternal = read_xml ( & bytes) . unwrap ( ) ;
317340 }
341+
342+ #[ test]
343+ fn parse_xml_with_blob_prefix ( ) {
344+ const XML : & [ u8 ] = br#"<?xml version="1.0" encoding="utf-8"?>
345+ <EnumerationResults ServiceEndpoint="https://sisuautomatedtest.blob.core.windows.net/" ContainerName="lowlatencyrequests">
346+ <Prefix>get-most-recent-key-5/</Prefix>
347+ <Delimiter>/</Delimiter>
348+ <Blobs>
349+ <Blob>
350+ <Name>get-most-recent-key-5/2021-08-04-testfile1</Name>
351+ <Properties>
352+ <Creation-Time>Tue, 13 Sep 2022 08:20:48 GMT</Creation-Time>
353+ <Last-Modified>Tue, 13 Sep 2022 08:20:48 GMT</Last-Modified>
354+ <Etag>0x8DA9560DD170CFD</Etag>
355+ <Content-Length>19</Content-Length>
356+ <Content-Type>text/plain</Content-Type>
357+ <Content-Encoding />
358+ <Content-Language />
359+ <Content-CRC64 />
360+ <Content-MD5>3X/+gWTy92gIJFXx57gLYA==</Content-MD5>
361+ <Cache-Control />
362+ <Content-Disposition />
363+ <BlobType>BlockBlob</BlobType>
364+ <AccessTier>Hot</AccessTier>
365+ <AccessTierInferred>true</AccessTierInferred>
366+ <LeaseStatus>unlocked</LeaseStatus>
367+ <LeaseState>available</LeaseState>
368+ <ServerEncrypted>true</ServerEncrypted>
369+ </Properties>
370+ <OrMetadata />
371+ </Blob>
372+ <BlobPrefix>
373+ <Name>get-most-recent-key-5/2021-08-04T21:48:48.592953Z-15839722113750148182/</Name>
374+ </BlobPrefix>
375+ <Blob>
376+ <Name>get-most-recent-key-5/2021-09-04-testfile2</Name>
377+ <Properties>
378+ <Creation-Time>Tue, 13 Sep 2022 08:07:01 GMT</Creation-Time>
379+ <Last-Modified>Tue, 13 Sep 2022 08:19:21 GMT</Last-Modified>
380+ <Etag>0x8DA9560A916932D</Etag>
381+ <Content-Length>19</Content-Length>
382+ <Content-Type>text/plain</Content-Type>
383+ <Content-Encoding />
384+ <Content-Language />
385+ <Content-CRC64 />
386+ <Content-MD5>b0CPJB6eDfKUzzW7dlboKQ==</Content-MD5>
387+ <Cache-Control />
388+ <Content-Disposition />
389+ <BlobType>BlockBlob</BlobType>
390+ <AccessTier>Hot</AccessTier>
391+ <AccessTierInferred>true</AccessTierInferred>
392+ <LeaseStatus>unlocked</LeaseStatus>
393+ <LeaseState>available</LeaseState>
394+ <ServerEncrypted>true</ServerEncrypted>
395+ </Properties>
396+ <OrMetadata />
397+ </Blob>
398+ <Blob>
399+ <Name>get-most-recent-key-5/2022-08-04-testfile3</Name>
400+ <Properties>
401+ <Creation-Time>Tue, 13 Sep 2022 08:07:01 GMT</Creation-Time>
402+ <Last-Modified>Tue, 13 Sep 2022 08:19:21 GMT</Last-Modified>
403+ <Etag>0x8DA9560A91F9296</Etag>
404+ <Content-Length>34</Content-Length>
405+ <Content-Type>text/plain</Content-Type>
406+ <Content-Encoding />
407+ <Content-Language />
408+ <Content-CRC64 />
409+ <Content-MD5>1F1MssyZOvhY4OZevHWEsw==</Content-MD5>
410+ <Cache-Control />
411+ <Content-Disposition />
412+ <BlobType>BlockBlob</BlobType>
413+ <AccessTier>Hot</AccessTier>
414+ <AccessTierInferred>true</AccessTierInferred>
415+ <LeaseStatus>unlocked</LeaseStatus>
416+ <LeaseState>available</LeaseState>
417+ <ServerEncrypted>true</ServerEncrypted>
418+ </Properties>
419+ <OrMetadata />
420+ </Blob>
421+ </Blobs>
422+ <NextMarker />
423+ </EnumerationResults>"# ;
424+
425+ let _list_blobs_response_internal: ListBlobsResponseInternal = read_xml ( XML ) . unwrap ( ) ;
426+ }
318427}
0 commit comments