Skip to content

Commit d4a27ab

Browse files
authored
use u8 slice for read_xml instead of Bytes (#856)
1 parent 48fa5dc commit d4a27ab

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

sdk/storage/src/core/xml.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use azure_core::error::{Error, ErrorKind, ResultExt};
2-
use bytes::Bytes;
32

4-
/// Reads the XML from the Bytes.
5-
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &Bytes) -> Result<T, Error> {
6-
serde_xml_rs::from_reader(slice_bom(body).as_ref())
3+
/// The UTF8 [byte order marker](https://en.wikipedia.org/wiki/Byte_order_mark)
4+
const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF];
5+
6+
/// Reads the XML from bytes.
7+
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> Result<T, Error> {
8+
serde_xml_rs::from_reader(slice_bom(body))
79
.context(ErrorKind::DataConversion, "failed to deserialize xml")
810
}
911

10-
const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF];
11-
12-
/// Returns Bytes without the UTF-8 BOM.
13-
fn slice_bom(bytes: &Bytes) -> Bytes {
14-
if bytes.len() > 3 && bytes.slice(0..3).as_ref() == UTF8_BOM {
15-
bytes.slice(3..)
12+
/// Returns bytes without the UTF-8 BOM.
13+
fn slice_bom(bytes: &[u8]) -> &[u8] {
14+
if bytes.len() > 3 && bytes[0..3] == UTF8_BOM {
15+
&bytes[3..]
1616
} else {
17-
bytes.clone()
17+
bytes
1818
}
1919
}
2020

@@ -24,10 +24,10 @@ mod test {
2424

2525
#[test]
2626
fn test_slice_bom() {
27-
let bytes = Bytes::from_static(&[0xEF, 0xBB, 0xBF, 7]);
28-
assert_eq!(Bytes::from_static(&[7]), slice_bom(&bytes));
27+
let bytes = &[0xEF, 0xBB, 0xBF, 7];
28+
assert_eq!(&[7], slice_bom(bytes));
2929

30-
let bytes = Bytes::from_static(&[8]);
31-
assert_eq!(Bytes::from_static(&[8]), slice_bom(&bytes));
30+
let bytes = &[8];
31+
assert_eq!(&[8], slice_bom(bytes));
3232
}
3333
}

0 commit comments

Comments
 (0)