OapWriter
- Namespace: Turian.Engine.Core
- Source File: OapWriter.cs
Builds an Open Asset Package. Assets are added one at a time (compressed and encrypted eagerly), then Serialize lays the whole file out in memory and WriteToFile flushes it. Entries are emitted sorted by asset_id so readers can binary-search.
Properties
Count
(int): Gets the number of assets added so far.
Public Methods
SetKey
public void SetKey(ReadOnlySpan<byte> encryptionKey)
Sets the encryption key applied to assets added with a non-None codec. Derive one from a passphrase with DeriveKey.
Parameters:
encryptionKey(ReadOnlySpan): A 32-byte key.
SetManifest
public void SetManifest(ReadOnlySpan<byte> bytes)
Sets the package manifest (opaque bytes, UTF-8 JSON by convention). The bytes are copied.
Parameters:
bytes(ReadOnlySpan): The manifest bytes.
SetManifest
public void SetManifest(string json)
Sets the package manifest from a UTF-8 string.
Parameters:
json(string): The manifest text.
Add
public void Add(Guid id, ReadOnlySpan<byte> data, string virtualPath = "", byte assetType = 0, OapCompressChoice compression = default, OapEncryption encryption = OapEncryption.None, IReadOnlyList<Guid>? dependencies = null)
Adds an asset. Compresses and encrypts immediately and copies every input, so the caller's buffers can be reused right after.
Parameters:
id(Guid): The 128-bit asset identifier (primary key).data(ReadOnlySpan): The plaintext asset bytes. virtualPath(string): A human-readable path such astextures/hero.amtex. May be empty. (Default:"")assetType(byte): An application-defined category byte (0 = unknown). (Default:0)compression(OapCompressChoice): How to compress the asset. (Default:default)encryption(OapEncryption): The encryption codec; requires a key set viaSetKey. (Default:OapEncryption.None)dependencies(IReadOnlyList? ): Ids of assets this one depends on. Copied. (Default:null)
Serialize
public byte[] Serialize()
Lays the whole package out into a single freshly allocated array. Entries are emitted sorted by asset_id.
Returns: byte[]
- The complete
.oapbytes.
WriteToFile
public void WriteToFile(string path)
Serialises the package and writes it to path.
Parameters:
path(string): The destination file path.