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