pub struct SerializedFile {
pub version: u32,
pub unity_version: String,
pub unity: UnityVersion,
pub target_platform: i32,
pub big_endian: bool,
pub types: Vec<SerializedType>,
pub objects: Vec<ObjectInfo>,
pub script_types: Vec<(i32, i64)>,
pub externals: Vec<External>,
pub ref_types: Vec<SerializedType>,
pub user_information: String,
/* private fields */
}Expand description
A parsed SerializedFile: its header fields, type table, object table, script references and external files, with the file’s bytes kept so objects can be read from it.
Fields§
§version: u32The container version (21 or 22: see VERSIONS).
unity_version: StringThe Unity version string the file was built with (2019.4.20f1).
unity: UnityVersionSerializedFile::unity_version, parsed.
target_platform: i32Unity’s BuildTarget number the file was built for.
big_endian: boolWhether the metadata and the objects’ bytes are big-endian.
types: Vec<SerializedType>The type table.
objects: Vec<ObjectInfo>The object table, in file order.
script_types: Vec<(i32, i64)>Script references: (file index, path id).
externals: Vec<External>The files this file’s pointers can name (file id = index + 1).
ref_types: Vec<SerializedType>The table of types of managed references ([SerializeReference]).
user_information: StringThe user string at the end of the metadata.
Implementations§
Source§impl SerializedFile
impl SerializedFile
Sourcepub fn looks_like(bytes: &[u8]) -> bool
pub fn looks_like(bytes: &[u8]) -> bool
Whether bytes start like a SerializedFile of a supported version (to tell them from other files).
Sourcepub fn container_version(bytes: &[u8]) -> Option<u32>
pub fn container_version(bytes: &[u8]) -> Option<u32>
The container version of bytes when they are a SerializedFile of any version, supported or not: a supported
version by its field alone (a damaged file of it is for SerializedFile::parse to refuse), another version
only when the header’s own size fields agree with bytes.len(), so that other files (streamed resources,
configs) are not taken for one. None for bytes that are no SerializedFile.
Sourcepub fn parse(data: Vec<u8>) -> Result<Self>
pub fn parse(data: Vec<u8>) -> Result<Self>
Parse the SerializedFile data. The header’s sizes must match data, the object table must lie inside it and
the metadata must end exactly where the header says; a version outside VERSIONS, a duplicate path id and
every length that runs past the bytes are refused with an Error that names what was found. A file that
stores its type trees is read whole, but a string of the engine’s common string table that a tree names is
refused as Error::Unsupported: SerializedFile::parse_with reads such files.
Sourcepub fn parse_with(
data: Vec<u8>,
package: Option<&TypeTreePackage>,
) -> Result<Self>
pub fn parse_with( data: Vec<u8>, package: Option<&TypeTreePackage>, ) -> Result<Self>
As SerializedFile::parse, reading the common strings of embedded type trees from package (the table of the
file’s own Unity version).
Sourcepub fn from_bundle(
bundle: &Arc<Bundle>,
path: &str,
package: Option<&TypeTreePackage>,
) -> Result<Self>
pub fn from_bundle( bundle: &Arc<Bundle>, path: &str, package: Option<&TypeTreePackage>, ) -> Result<Self>
Read the file path of bundle without reading its objects: the header and metadata are read, each object’s
bytes later, by range, when SerializedFile::bytes asks for them. path must name a serialized node.
Sourcepub fn object(&self, path_id: i64) -> Option<&ObjectInfo>
pub fn object(&self, path_id: i64) -> Option<&ObjectInfo>
The object with this path id, if the file has one.
Sourcepub fn tree_of(&self, o: &ObjectInfo) -> Option<&Arc<TypeTree>>
pub fn tree_of(&self, o: &ObjectInfo) -> Option<&Arc<TypeTree>>
The type tree the file stores for the type of o; None for a file that stores none (a player’s).
Sourcepub fn bytes(&self, o: &ObjectInfo) -> Result<Cow<'_, [u8]>>
pub fn bytes(&self, o: &ObjectInfo) -> Result<Cow<'_, [u8]>>
The bytes of an object of this file. o should come from this file’s own SerializedFile::objects: an
ObjectInfo of another file that names bytes outside this one is an error naming the object and its range.
A file read from memory lends its bytes; one read from a bundle (SerializedFile::from_bundle) reads them
from the bundle, decompressing the blocks they lie in.
Sourcepub fn bundle(&self) -> Option<(&Arc<Bundle>, &BundleNode)>
pub fn bundle(&self) -> Option<(&Arc<Bundle>, &BundleNode)>
The bundle and node this file was read from (SerializedFile::from_bundle); None for a file read from
memory.
Sourcepub fn decode_with(&self, o: &ObjectInfo, tree: &TypeTree) -> Result<Decoded>
pub fn decode_with(&self, o: &ObjectInfo, tree: &TypeTree) -> Result<Decoded>
Decode an object’s bytes from its start with tree (its class’s type tree), reporting the bytes after what the
tree covers in Decoded::rest (see Decoded::covered).
Sourcepub fn decode(
&self,
o: &ObjectInfo,
package: &TypeTreePackage,
) -> Result<Decoded>
pub fn decode( &self, o: &ObjectInfo, package: &TypeTreePackage, ) -> Result<Decoded>
Decode an object with its class’s type tree from package. The tree must cover the object’s bytes, but for a
MonoBehaviour, whose script fields follow its base fields.