Skip to main content

flash_lso/types/
value.rs

1use super::{ClassDefinition, Element, ObjectId, Reference};
2
3/// The data contained within a Value of type Object
4#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5#[derive(Debug, Clone, PartialEq)]
6pub struct ObjectValue {
7    /// The child elements of this Object
8    pub elements: Vec<Element>,
9
10    /// The class definition for this object, if it exists
11    pub class_definition: Option<ClassDefinition>,
12}
13
14/// Represents the contents of a Custom object
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16#[derive(Debug, Clone, PartialEq)]
17pub struct CustomObjectValue {
18    /// The external elements
19    pub elements: Vec<Element>,
20    /// The dynamic elements
21    pub dynamic_elements: Vec<Element>,
22
23    /// The ClassDefinition assigned to this Custom object
24    pub class_definition: ClassDefinition,
25}
26
27/// The data contained within a Dictionary
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29#[derive(Debug, Clone, PartialEq)]
30pub struct DictionaryObjectValue {
31    /// The contents of this Dictionary
32    pub elements: Vec<DictionaryEntry>,
33
34    /// Are the keys of this Dictionary weakly referenced
35    pub weak_keys: bool,
36}
37
38/// Represents a Key-Value pair in an AMF Dictionary
39#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
40#[derive(Debug, Clone, PartialEq)]
41pub struct DictionaryEntry {
42    /// The key
43    pub key: Value,
44
45    /// The value
46    pub value: Value,
47}
48
49/// An AMF vector of a some subtype
50#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
51#[derive(Debug, Clone, PartialEq)]
52pub struct VectorPrimitiveValue<T> {
53    /// The contents of this Vector
54    pub values: Vec<T>,
55
56    /// Is this vector of a fixed length
57    pub fixed_length: bool,
58}
59
60/// An AMF vector of Objects
61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
62#[derive(Debug, Clone, PartialEq)]
63pub struct VectorObjectValue {
64    /// The contents of this Vector
65    pub values: Vec<Value>,
66
67    /// The name of the class this is a vector of
68    pub object_type_name: String,
69
70    /// Is this vector of a fixed length
71    pub fixed_length: bool,
72}
73
74/// The contents of a ECMAArray object
75#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
76#[derive(Debug, Clone, PartialEq)]
77pub struct ECMAArrayObjectValue {
78    /// The dense component of this ECMAArray
79    pub dense: Vec<Value>,
80
81    /// The non-dense component of this ECMAArray
82    pub elements: Vec<Element>,
83
84    /// The length of the array in AMF0, this can differ from the actual number of elements
85    pub length: u32,
86}
87
88//TODO: should amf3 assoc arrays be their own type with a dense and assoc section
89/// A single or compound value
90#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
91#[derive(Debug, Clone, PartialEq)]
92pub enum Value {
93    /// Represent the type number (amf0) and double (amf3)
94    Number(f64),
95
96    /// Represents the type boolean (amf0) and both the true/false type (amf3)
97    Bool(bool),
98
99    /// Represent both the string (amf0/3) and long string type (amf0)
100    String(String),
101
102    /// Represents the object type in both amf0 and amf3, class definition are only available with amf3
103    Object {
104        /// The unique id that will be used to refer back to this Object
105        id: ObjectId,
106
107        /// The data within this value
108        data: ObjectValue,
109    },
110
111    /// Represent the null type
112    Null,
113
114    /// Represent the undefined type
115    Undefined,
116
117    /// Represent ECMA-Arrays (amf0) and associative arrays (amf3, even if they contain a dense part)
118    ECMAArray {
119        /// A unique identifier that will be used to refer back to this ECMAArray
120        id: ObjectId,
121
122        /// The data within this ECMAArray
123        data: ECMAArrayObjectValue,
124    },
125
126    /// Represent a strict array (amf0) or a dense array (amf3)
127    StrictArray {
128        /// A unique identifier that will be used to refer back to this StrictArray
129        id: ObjectId,
130
131        /// The data within this StrictArray
132        values: Vec<Value>,
133    },
134
135    /// Represent a timestamp
136    Date {
137        /// Number of seconds since the epoch
138        time: f64,
139
140        /// The timezone identifier or UTC if missing
141        timezone_or_utc: Option<u16>,
142    },
143
144    /// Represent the unsupported type
145    Unsupported,
146
147    /// Represent the XML type, (value, is_string)
148    XML {
149        /// The XML data
150        value: String,
151        /// Is this XML a string
152        is_string: bool,
153    },
154
155    #[cfg(feature = "amf3")]
156    /// Represent an amf3 element embedded in an AMF0 file
157    AMF3(Box<Value>),
158
159    // AMF3
160    /// Represent the integer type (u29) (amf3)
161    Integer(i32),
162
163    /// Represent the bytearray type (amf3)
164    ByteArray(Vec<u8>),
165
166    /// Represent the int vector type (amf3)
167    VectorInt(VectorPrimitiveValue<i32>),
168
169    /// Represent the unsigned int vector type (amf3)
170    VectorUInt(VectorPrimitiveValue<u32>),
171
172    /// Represent the double vector type (amf3)
173    VectorDouble(VectorPrimitiveValue<f64>),
174
175    /// Represent the object vector type (amf3)
176    VectorObject {
177        /// A unique identifier that will be used to refer back to this VectorObject
178        id: ObjectId,
179
180        /// The data in this Vector
181        data: VectorObjectValue,
182    },
183
184    /// Represent the dictionary type (amf3)
185    Dictionary {
186        /// A unique identifier that will be used to refer back to this Dictionary
187        id: ObjectId,
188
189        /// The data contained within this Dictionary
190        data: DictionaryObjectValue,
191    },
192
193    /// Represent an external object, such as from flex
194    /// (custom_elements, regular elements, class def)
195    Custom(CustomObjectValue),
196
197    /// Represent an existing value, stored by reference, the value here should be considered opaque
198    Reference(Reference),
199
200    /// A reference to a previously parsed element
201    ///
202    /// While traversing the graph of `Value` instances you should maintain a mapping of `ObjectId` to your internal
203    /// representation of a value and consider this a reference to the exact same value.
204    ///
205    /// As `Value` graphs can contain cycles which are best handled by garbage collected structures
206    /// we leave the handling of this to the user, sorry
207    Amf3ObjectReference(ObjectId),
208}