gvas/properties/
object_property.rs1use std::io::{Cursor, Read, Seek, Write};
2
3use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
4
5use crate::{
6    cursor_ext::{ReadExt, WriteExt},
7    error::Error,
8};
9
10use super::{impl_read, impl_read_header, impl_write, PropertyOptions, PropertyTrait};
11
12#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct ObjectProperty {
16    pub value: String,
18}
19
20impl From<&str> for ObjectProperty {
21    #[inline]
22    fn from(value: &str) -> Self {
23        ObjectProperty::new(value.into())
24    }
25}
26
27impl ObjectProperty {
28    #[inline]
30    pub fn new(value: String) -> Self {
31        ObjectProperty { value }
32    }
33
34    impl_read!();
35    impl_read_header!();
36
37    #[inline]
38    fn read_body<R: Read + Seek>(cursor: &mut R) -> Result<Self, Error> {
39        let value = cursor.read_string()?;
40        Ok(ObjectProperty { value })
41    }
42}
43
44impl PropertyTrait for ObjectProperty {
45    impl_write!(ObjectProperty);
46
47    #[inline]
48    fn write_body<W: Write>(
49        &self,
50        cursor: &mut W,
51        _: &mut PropertyOptions,
52    ) -> Result<usize, Error> {
53        cursor.write_string(&self.value)
54    }
55}