Prowl.Echo is designed to be extended at two distinct levels.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Echo/llms.txt
Use this file to discover all available pages before exploring further.
ISerializationFormat lets you intercept the object-to-EchoObject conversion for specific .NET types, giving you full control over how a type is represented in the intermediate tree. IFileFormat operates one layer above that, controlling how a completed EchoObject tree is encoded to and decoded from bytes — whether that’s a custom binary layout, a domain-specific text format, or anything else.
ISerializationFormat — Type-Level Handlers
The ISerializationFormat interface sits at the heart of Echo’s serialization pipeline. When Echo encounters a type it needs to serialize or deserialize, it walks its list of registered formats and delegates to the first one that claims the type via CanHandle.
Method Responsibilities
CanHandle(Type type)
Return
true if this format is responsible for the given type. Keep this check fast — it is called for every type resolution. Checking type == typeof(MyType) or type.IsAssignableTo(typeof(ISomeInterface)) are both fine patterns.Serialize(Type targetType, object value, SerializationContext context)
Convert
value into an EchoObject and return it. The targetType is the declared field type (not necessarily the runtime type). Use context to recursively serialize nested values via Serializer.Serialize(fieldType, fieldValue, context).Deserialize(EchoObject value, Type targetType, SerializationContext context)
Reconstruct and return an object from the provided
EchoObject. Use context to recursively deserialize nested values via Serializer.Deserialize(echo, fieldType, context).Registering a Custom Format
CallSerializer.RegisterFormat with an instance of your format. Registered formats are inserted at the front of the pipeline, giving them higher priority than all built-in formats except AnyObjectFormat, which is always kept last as the fallback.
Calling
RegisterFormat clears the internal format cache, forcing re-resolution on the next serialization call for each type. This is expected — registration is an infrequent operation that typically happens once at startup.Example: Custom Vector2 Format
The following format handles a hypothetical Vector2 struct, serializing its two components as a compact list rather than the default compound object.
Built-In Format Precedence
Echo registers these formats in order, withAnyObjectFormat always anchored at the end:
| Priority | Format | Handles |
|---|---|---|
| 1 | PrimitiveFormat | int, float, bool, string, etc. |
| 2 | NullableFormat | Nullable<T> |
| 3 | DateTimeFormat | DateTime |
| 4 | DateTimeOffsetFormat | DateTimeOffset |
| 5 | TimeSpanFormat | TimeSpan |
| 6 | GuidFormat | Guid |
| 7 | UriFormat | Uri |
| 8 | VersionFormat | Version |
| 9 | EnumFormat | All enum types |
| 10 | TupleFormat | Tuple types |
| 11 | AnonymousTypeFormat | Anonymous types |
| 12 | HashSetFormat | HashSet<T> |
| 13 | ArrayFormat | Arrays |
| 14 | ListFormat | List<T> |
| 15 | QueueFormat | Queue<T> |
| 16 | StackFormat | Stack<T> |
| 17 | LinkedListFormat | LinkedList<T> |
| 18 | CollectionFormat | Other ICollection<T> |
| 19 | DictionaryFormat | IDictionary types |
| 20 | FixedStructureFormat | [FixedEchoStructure] types |
| Last | AnyObjectFormat | Everything else (field reflection) |
RegisterFormat are prepended before index 1, making them the highest priority.
IFileFormat — Output Encoding
IFileFormat defines how a completed EchoObject tree is written to and read from a Stream. This is the layer for custom binary layouts, proprietary text formats, or any encoding not already provided by Echo.
Extension Methods
Once you implementIFileFormat, a full set of convenience methods is available automatically via FileFormatExtensions:
| Method | Description |
|---|---|
WriteToString(EchoObject tag) | Writes to a UTF-8 string (best for text formats) |
ReadFromString(string input) | Reads from a UTF-8 string |
WriteToBytes(EchoObject tag) | Writes to a byte[] (works for text and binary) |
ReadFromBytes(byte[] data) | Reads from a byte[] |
WriteToFile(EchoObject tag, string path) | Writes to a file at the given path |
ReadFromFile(string path) | Reads from a file at the given path |
WriteTo/ReadFrom methods — you only need to implement those two.
Example: Key=Value Text Format
The following format encodes a flat compoundEchoObject as a simple key=value text file. It demonstrates the full IFileFormat contract.
IFileFormat operates on the EchoObject tree, not on raw .NET objects. Serialization (object → EchoObject) and encoding (EchoObject → bytes) are always separate steps in Echo’s pipeline.Built-In File Formats
Echo ships with several ready-to-useIFileFormat implementations:
EchoBinaryFormat
Echo’s native binary format. Supports
BinaryEncodingMode.Performance (fixed-width integers) and BinaryEncodingMode.Size (LEB128 + LZW string compression). Recommended for production I/O.EchoTextFormat
Human-readable text format. Good for debugging and hand-editing saved data.
JsonFileFormat
JSON encoding via
WriteToJson() / ReadFromJson() on EchoObject.YamlFileFormat
YAML encoding via
WriteToYaml() / ReadFromYaml() on EchoObject.XmlFileFormat
XML encoding via
WriteToXml() / ReadFromXml() on EchoObject.BsonFileFormat
BSON binary encoding via
WriteToBson() / ReadFromBson() on EchoObject.