flash_lso/amf3/custom_encoder.rs
1use crate::amf3::read::AMF3Decoder;
2
3use crate::amf3::write::AMF3Encoder;
4
5use crate::types::Element;
6use crate::types::*;
7
8use crate::nom_utils::AMFResult;
9use std::rc::Rc;
10
11/// A trait to define encoding for custom types for use with Externalized objects
12pub trait CustomEncoder {
13 /// This should implement the encoding of a given set of external elements for the given class definition
14 /// Access to the AMF3Encoder is given to allow access to caches
15 /// This implements the encoding side of externalized type support
16 fn encode<'a>(
17 &self,
18 elements: &'a [Element],
19 class_def: &Option<ClassDefinition>,
20 encoder: &AMF3Encoder,
21 ) -> Vec<u8>;
22}
23
24//TODO: combine with trait
25/// Type used for specifying a custom decoder for a AMF3 external type
26pub type ExternalDecoderFn =
27 Rc<Box<dyn for<'a> Fn(&'a [u8], &mut AMF3Decoder) -> AMFResult<'a, Vec<Element>>>>;