Skip to content

Game.Serialization.SerializationUtils

Assembly: Game
Namespace: Game.Serialization

Type: static class

Base: System.Object

Summary:
Utility helpers for working with buffer/compression formats used by the game's asset pipeline and serialization. Provides an extension to check whether a BufferFormat is a compressed format and a converter to map BufferFormat values to the corresponding CompressionFormat enum used by the serializer. These helpers reference BufferFormat (Colossal.AssetPipeline.Native) and CompressionFormat (Colossal.Serialization.Entities).


Fields

  • This type has no instance fields.
    The class is a static utility container and does not hold state.

Properties

  • This type declares no properties.

Constructors

  • This static class has no public constructors.
    Being a static utility class, it cannot be instantiated.

Methods

  • public static bool IsCompressed(this BufferFormat format)
    Extension method that returns true if the provided BufferFormat represents a compressed format. Currently returns true for:
  • BufferFormat.CompressedLZ4
  • BufferFormat.CompressedZStd

Usage notes: - Implemented as a simple conditional check; returns false for any other BufferFormat values. - As an extension method, call it directly on a BufferFormat value: format.IsCompressed().

  • public static CompressionFormat BufferToCompressionFormat(BufferFormat format)
    Converts a BufferFormat into the corresponding CompressionFormat:
  • BufferFormat.CompressedLZ4 => CompressionFormat.LZ4
  • BufferFormat.CompressedZStd => CompressionFormat.ZSTD

Throws: - FormatException if an unsupported or non-compressed BufferFormat is passed (i.e., any value other than the two compressed formats above).

Usage notes: - Useful when you need the CompressionFormat value required by serializer APIs that expect a CompressionFormat enum rather than a BufferFormat. - Uses a C# switch expression to map values and throw for invalid/unsupported inputs.

Usage Example

using Colossal.AssetPipeline.Native;
using Colossal.Serialization.Entities;
using Game.Serialization;

// Example BufferFormat value
BufferFormat format = BufferFormat.CompressedLZ4;

// Check if compressed
bool compressed = format.IsCompressed(); // true

// Convert to CompressionFormat
CompressionFormat compFmt = SerializationUtils.BufferToCompressionFormat(format); // CompressionFormat.LZ4

// Handling an unsupported format safely
BufferFormat other = BufferFormat.Uncompressed; // example non-compressed value
if (other.IsCompressed())
{
    CompressionFormat cf = SerializationUtils.BufferToCompressionFormat(other);
    // use cf...
}
else
{
    // handle uncompressed buffer case
}

Additional remarks: - BufferFormat and CompressionFormat enums are provided by the game's native/serialization libraries (Colossal.AssetPipeline.Native and Colossal.Serialization.Entities). Ensure your mod references those assemblies/namespaces. - BufferToCompressionFormat will throw a FormatException for non-compressed formats — validate with IsCompressed() beforehand if you need to avoid exceptions.