mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 08:36:31 +00:00
Buffer: ser: don't panick if not readable
This commit is contained in:
parent
693121bc55
commit
d856fedf06
1 changed files with 5 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
use serde::ser;
|
||||
use serde::ser::{Serialize, Serializer, SerializeStruct};
|
||||
use serde_bytes::{Bytes, ByteBuf};
|
||||
|
||||
|
@ -25,7 +26,9 @@ impl<'a> Serialize for BufferRef {
|
|||
buffer.serialize_field("offset_end", &self.get_offset_end())?;
|
||||
buffer.serialize_field("flags", &self.get_flags())?;
|
||||
{
|
||||
let data = self.map_readable().unwrap();
|
||||
let data = self
|
||||
.map_readable()
|
||||
.ok_or_else(|| ser::Error::custom("Couldn't map `buffer` as readable"))?;
|
||||
buffer.serialize_field("buffer", &Bytes::new(data.as_slice()))?;
|
||||
}
|
||||
buffer.end()
|
||||
|
@ -68,7 +71,7 @@ impl From<BufferDe> for Buffer {
|
|||
impl<'de> Deserialize<'de> for Buffer {
|
||||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
BufferDe::deserialize(deserializer)
|
||||
.and_then(|buffer_de| Ok(buffer_de.into()))
|
||||
.map(|buffer_de| buffer_de.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue