scuffle_amf0/
lib.rs

1//! A pure-rust implementation of AMF0 encoder and decoder.
2//!
3//! This crate provides serde support for serialization and deserialization of AMF0 data.
4//!
5//! ## Specification
6//!
7//! | Name | Version | Link | Comments |
8//! | --- | --- | --- | --- |
9//! | Action Message Format -- AMF 0 | - | <https://rtmp.veriskope.com/pdf/amf0-file-format-specification.pdf> | Refered to as 'AMF0 spec' in this documentation |
10//!
11//! ## Limitations
12//!
13//! - Does not support AMF0 references.
14//! - Does not support the AVM+ Type Marker. (see AMF 0 spec, 3.1)
15//!
16//! ## Example
17//!
18//! ```rust
19//! # fn test() -> Result<(), Box<dyn std::error::Error>> {
20//! # let bytes = &[0x02, 0, 1, b'a'];
21//! # let mut writer = Vec::new();
22//! // Decode a string value from bytes
23//! let value: String = scuffle_amf0::from_slice(bytes)?;
24//!
25//! // .. do something with the value
26//!
27//! // Encode a value into a writer
28//! scuffle_amf0::to_writer(&mut writer, &value)?;
29//! # assert_eq!(writer, bytes);
30//! # Ok(())
31//! # }
32//! # test().expect("test failed");
33//! ```
34//!
35//! ## Status
36//!
37//! This crate is currently under development and is not yet stable.
38//!
39//! Unit tests are not yet fully implemented. Use at your own risk.
40//!
41//! ## License
42//!
43//! This project is licensed under the [MIT](./LICENSE.MIT) or [Apache-2.0](./LICENSE.Apache-2.0) license.
44//! You can choose between one of them if you use this work.
45//!
46//! `SPDX-License-Identifier: MIT OR Apache-2.0`
47#![cfg_attr(docsrs, feature(doc_cfg))]
48#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
49#![deny(missing_docs)]
50#![deny(unsafe_code)]
51#![deny(unreachable_pub)]
52
53#[cfg(feature = "serde")]
54#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
55pub mod de;
56pub mod decoder;
57pub mod encoder;
58pub mod error;
59#[cfg(feature = "serde")]
60#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
61pub mod ser;
62pub mod value;
63
64#[cfg(feature = "serde")]
65#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
66pub use de::{from_buf, from_reader, from_slice};
67pub use decoder::Amf0Decoder;
68pub use encoder::Amf0Encoder;
69pub use error::{Amf0Error, Result};
70#[cfg(feature = "serde")]
71#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
72pub use ser::{to_bytes, to_writer};
73pub use value::{Amf0Array, Amf0Object, Amf0Value};
74
75/// AMF0 marker types.
76///
77/// Defined by:
78/// - AMF 0 spec, 2.1.
79#[derive(Debug, PartialEq, Eq, Clone, Copy, num_derive::FromPrimitive)]
80#[repr(u8)]
81pub enum Amf0Marker {
82    /// number-marker
83    Number = 0x00,
84    /// boolean-marker
85    Boolean = 0x01,
86    /// string-marker
87    String = 0x02,
88    /// object-marker
89    Object = 0x03,
90    /// movieclip-marker
91    ///
92    /// reserved, not supported
93    MovieClipMarker = 0x04,
94    /// null-marker
95    Null = 0x05,
96    /// undefined-marker
97    Undefined = 0x06,
98    /// reference-marker
99    Reference = 0x07,
100    /// ecma-array-marker
101    EcmaArray = 0x08,
102    /// object-end-marker
103    ObjectEnd = 0x09,
104    /// strict-array-marker
105    StrictArray = 0x0a,
106    /// date-marker
107    Date = 0x0b,
108    /// long-string-marker
109    LongString = 0x0c,
110    /// unsupported-marker
111    Unsupported = 0x0d,
112    /// recordset-marker
113    ///
114    /// reserved, not supported
115    Recordset = 0x0e,
116    /// xml-document-marker
117    XmlDocument = 0x0f,
118    /// typed-object-marker
119    TypedObject = 0x10,
120    /// avmplus-object-marker
121    ///
122    /// AMF3 marker
123    AVMPlusObject = 0x11,
124}