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
49#[cfg(feature = "serde")]
50pub mod de;
51pub mod decoder;
52pub mod encoder;
53pub mod error;
54#[cfg(feature = "serde")]
55pub mod ser;
56pub mod value;
57
58#[cfg(feature = "serde")]
59pub use de::{from_buf, from_reader, from_slice};
60pub use decoder::Amf0Decoder;
61pub use encoder::Amf0Encoder;
62pub use error::{Amf0Error, Result};
63#[cfg(feature = "serde")]
64pub use ser::{to_bytes, to_writer};
65pub use value::{Amf0Array, Amf0Object, Amf0Value};
66
67/// AMF0 marker types.
68///
69/// Defined by:
70/// - AMF 0 spec, 2.1.
71#[derive(Debug, PartialEq, Eq, Clone, Copy, num_derive::FromPrimitive)]
72#[repr(u8)]
73pub enum Amf0Marker {
74    /// number-marker
75    Number = 0x00,
76    /// boolean-marker
77    Boolean = 0x01,
78    /// string-marker
79    String = 0x02,
80    /// object-marker
81    Object = 0x03,
82    /// movieclip-marker
83    ///
84    /// reserved, not supported
85    MovieClipMarker = 0x04,
86    /// null-marker
87    Null = 0x05,
88    /// undefined-marker
89    Undefined = 0x06,
90    /// reference-marker
91    Reference = 0x07,
92    /// ecma-array-marker
93    EcmaArray = 0x08,
94    /// object-end-marker
95    ObjectEnd = 0x09,
96    /// strict-array-marker
97    StrictArray = 0x0a,
98    /// date-marker
99    Date = 0x0b,
100    /// long-string-marker
101    LongString = 0x0c,
102    /// unsupported-marker
103    Unsupported = 0x0d,
104    /// recordset-marker
105    ///
106    /// reserved, not supported
107    Recordset = 0x0e,
108    /// xml-document-marker
109    XmlDocument = 0x0f,
110    /// typed-object-marker
111    TypedObject = 0x10,
112    /// avmplus-object-marker
113    ///
114    /// AMF3 marker
115    AVMPlusObject = 0x11,
116}
117
118/// Changelogs generated by [scuffle_changelog]
119#[cfg(feature = "docs")]
120#[scuffle_changelog::changelog]
121pub mod changelog {}