Skip to content

Commit

Permalink
VTX-3411: fix serializatio for multi part field
Browse files Browse the repository at this point in the history
  • Loading branch information
fsdvh committed Dec 6, 2023
1 parent 6562f11 commit d08d9c6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion object_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ walkdir = "2"
# Cloud storage support
base64 = { version = "0.21", default-features = false, features = ["std"], optional = true }
hyper = { version = "0.14", default-features = false, optional = true }
quick-xml = { version = "0.30.0", features = ["serialize", "overlapped-lists"], optional = true }
quick-xml = { git = "https://github.com/tafia/quick-xml.git", rev="db8546a", features = ["serialize", "overlapped-lists"], optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
Expand Down
50 changes: 46 additions & 4 deletions object_store/src/aws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use crate::aws::checksum::Checksum;
use crate::aws::credential::{AwsCredential, CredentialExt};
use crate::aws::{
AwsCredentialProvider, S3CopyIfNotExists, STORE, STRICT_ENCODE_SET, STRICT_PATH_ENCODE_SET,
AwsCredentialProvider, S3CopyIfNotExists, STORE, STRICT_ENCODE_SET,
STRICT_PATH_ENCODE_SET,
};
use crate::client::get::GetClient;
use crate::client::list::ListClient;
Expand Down Expand Up @@ -152,14 +153,24 @@ struct CompleteMultipart {
part: Vec<MultipartPart>,
}

#[derive(Debug, Serialize)]
#[derive(Debug)]
struct MultipartPart {
#[serde(rename = "ETag")]
e_tag: String,
#[serde(rename = "PartNumber")]
part_number: usize,
}

impl Serialize for MultipartPart {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut s = serializer.serialize_struct("MultipartPart", 2)?;
s.serialize_field("ETag", format!("\"{}\"", &self.e_tag).as_str())?;
s.serialize_field("PartNumber", &self.part_number)?;
s.end()
}
}

#[derive(Deserialize)]
#[serde(rename_all = "PascalCase", rename = "DeleteResult")]
struct BatchDeleteResponse {
Expand Down Expand Up @@ -668,3 +679,34 @@ impl ListClient for S3Client {
fn encode_path(path: &Path) -> PercentEncode<'_> {
utf8_percent_encode(path.as_ref(), &STRICT_PATH_ENCODE_SET)
}

#[cfg(test)]
mod tests {

#[test]
fn test_multipart_serializrtion() {
let request = CompleteMultipart {
part: vec![
MultipartPart {
e_tag: "1".to_string(),
part_number: 1,
},
MultipartPart {
e_tag: "2".to_string(),
part_number: 2,
},
MultipartPart {
e_tag: "3".to_string(),
part_number: 3,
},
],
};

let body = quick_xml::se::to_string(&request).unwrap();

assert_eq!(
body,
r#"<CompleteMultipartUpload><Part><ETag>"1"</ETag><PartNumber>1</PartNumber></Part><Part><ETag>"2"</ETag><PartNumber>2</PartNumber></Part><Part><ETag>"3"</ETag><PartNumber>3</PartNumber></Part></CompleteMultipartUpload>"#
)
}
}

0 comments on commit d08d9c6

Please sign in to comment.