Trait il2_iltags::tags::ILTagFactory [−][src]
pub trait ILTagFactory: Send + Sync {
fn create_tag(&self, tag_id: u64) -> Option<Box<dyn ILTag>>;
fn deserialize(&self, reader: &mut dyn Reader) -> Result<Box<dyn ILTag>>;
fn deserialize_into(
&self,
reader: &mut dyn Reader,
tag: &mut dyn ILTag
) -> Result<()>;
fn from_bytes(&self, raw_tag: &[u8]) -> Result<Box<dyn ILTag>> { ... }
}
Expand description
This trait must be implemented by all tag factories. Factories are used to deserialize tags into the most appropriate concreate implemetation that will handle a given tag id.
Required methods
Creates an empty tag for the given id.
Arguments:
tag_id
: The tag id;
Returns:
- Some(t): A boxed tag that implements the given tag id;
- None: If the tag id does not have a suitable implementation;
Deserializes a tag from a reader.
Arguments:
reader
: The reader that contains the tag;
Retunrs: The boxed deserialized tag or an error in case of failure.
Deserializes a tag from a reader and put the result into an existing tag instance if possible.
Arguments:
reader
: The reader that contains the tag;tag
: The tag instance that will receive the deserialized tag;
Retunrs:
- Ok(()): On success;
- Err(ErrorKind::UnexpectedTagType): If the tag types don’t match.
- Err(_): In case of failure;
New since 1.3.0.
Provided methods
Deserializes a tag from its serialized bytes. Internally it calls
Self::deserialize()
to perform this operation.
Arguments:
raw_tag
: The raw tag.
Returns the deserialized tag or an error if the deserialization is not possible or the deserialization does not use all bytes from raw.
New since 1.4.0.