1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[macro_use] extern crate failure;
extern crate byteorder;
mod serialization;
mod deserialization;
mod errors;
pub use serialization::serialize;
pub use deserialization::deserialize;
pub use errors::{Amf0DeserializationError, Amf0SerializationError};
use std::collections::HashMap;
#[derive(PartialEq, Debug, Clone)]
pub enum Amf0Value {
Number(f64),
Boolean(bool),
Utf8String(String),
Object(HashMap<String, Amf0Value>),
Null,
Undefined,
}
impl Amf0Value {
pub fn get_number(self) -> Option<f64> {
match self {
Amf0Value::Number(value) => Some(value),
_ => None,
}
}
pub fn get_boolean(self) -> Option<bool> {
match self {
Amf0Value::Boolean(value) => Some(value),
_ => None,
}
}
pub fn get_string(self) -> Option<String> {
match self {
Amf0Value::Utf8String(value) => Some(value),
_ => None,
}
}
pub fn get_object_properties(self) -> Option<HashMap<String, Amf0Value>> {
match self {
Amf0Value::Object(properties) => Some(properties),
_ => None,
}
}
}
mod markers {
pub const NUMBER_MARKER: u8 = 0;
pub const BOOLEAN_MARKER: u8 = 1;
pub const STRING_MARKER: u8 = 2;
pub const OBJECT_MARKER: u8 = 3;
pub const NULL_MARKER: u8 = 5;
pub const UNDEFINED_MARKER: u8 = 6;
pub const ECMA_ARRAY_MARKER: u8 = 8;
pub const OBJECT_END_MARKER: u8 = 9;
pub const UTF_8_EMPTY_MARKER: u16 = 0;
}