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