17e2e9c0cSopenharmony_ciuse serde::de::{Deserializer, Error, SeqAccess, Visitor};
27e2e9c0cSopenharmony_ciuse std::fmt;
37e2e9c0cSopenharmony_ci
47e2e9c0cSopenharmony_cipub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
57e2e9c0cSopenharmony_ciwhere
67e2e9c0cSopenharmony_ci    D: Deserializer<'de>,
77e2e9c0cSopenharmony_ci{
87e2e9c0cSopenharmony_ci    deserializer.deserialize_byte_buf(ByteBufVisitor)
97e2e9c0cSopenharmony_ci}
107e2e9c0cSopenharmony_ci
117e2e9c0cSopenharmony_cistruct ByteBufVisitor;
127e2e9c0cSopenharmony_ci
137e2e9c0cSopenharmony_ciimpl<'de> Visitor<'de> for ByteBufVisitor {
147e2e9c0cSopenharmony_ci    type Value = Vec<u8>;
157e2e9c0cSopenharmony_ci
167e2e9c0cSopenharmony_ci    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
177e2e9c0cSopenharmony_ci        formatter.write_str("byte array")
187e2e9c0cSopenharmony_ci    }
197e2e9c0cSopenharmony_ci
207e2e9c0cSopenharmony_ci    fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
217e2e9c0cSopenharmony_ci    where
227e2e9c0cSopenharmony_ci        V: SeqAccess<'de>,
237e2e9c0cSopenharmony_ci    {
247e2e9c0cSopenharmony_ci        let mut values = Vec::new();
257e2e9c0cSopenharmony_ci        while let Some(value) = visitor.next_element()? {
267e2e9c0cSopenharmony_ci            values.push(value);
277e2e9c0cSopenharmony_ci        }
287e2e9c0cSopenharmony_ci        Ok(values)
297e2e9c0cSopenharmony_ci    }
307e2e9c0cSopenharmony_ci
317e2e9c0cSopenharmony_ci    fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
327e2e9c0cSopenharmony_ci    where
337e2e9c0cSopenharmony_ci        E: Error,
347e2e9c0cSopenharmony_ci    {
357e2e9c0cSopenharmony_ci        Ok(v.to_vec())
367e2e9c0cSopenharmony_ci    }
377e2e9c0cSopenharmony_ci
387e2e9c0cSopenharmony_ci    fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
397e2e9c0cSopenharmony_ci    where
407e2e9c0cSopenharmony_ci        E: Error,
417e2e9c0cSopenharmony_ci    {
427e2e9c0cSopenharmony_ci        Ok(v)
437e2e9c0cSopenharmony_ci    }
447e2e9c0cSopenharmony_ci
457e2e9c0cSopenharmony_ci    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
467e2e9c0cSopenharmony_ci    where
477e2e9c0cSopenharmony_ci        E: Error,
487e2e9c0cSopenharmony_ci    {
497e2e9c0cSopenharmony_ci        Ok(v.as_bytes().to_vec())
507e2e9c0cSopenharmony_ci    }
517e2e9c0cSopenharmony_ci
527e2e9c0cSopenharmony_ci    fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
537e2e9c0cSopenharmony_ci    where
547e2e9c0cSopenharmony_ci        E: Error,
557e2e9c0cSopenharmony_ci    {
567e2e9c0cSopenharmony_ci        Ok(v.into_bytes())
577e2e9c0cSopenharmony_ci    }
587e2e9c0cSopenharmony_ci}
59