{"id":34935406,"url":"https://github.com/hexaengine/hexaengine.sappho","last_synced_at":"2025-12-26T18:03:14.350Z","repository":{"id":324032990,"uuid":"1095680402","full_name":"HexaEngine/HexaEngine.Sappho","owner":"HexaEngine","description":"A high-performance, source-generated binary serialization library for .NET","archived":false,"fork":false,"pushed_at":"2025-11-13T13:09:45.000Z","size":229,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-13T13:25:09.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HexaEngine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"junameinhold","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2025-11-13T11:26:57.000Z","updated_at":"2025-11-13T13:09:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/HexaEngine/HexaEngine.Sappho","commit_stats":null,"previous_names":["hexaengine/hexaengine.sappho"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/HexaEngine/HexaEngine.Sappho","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HexaEngine%2FHexaEngine.Sappho","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HexaEngine%2FHexaEngine.Sappho/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HexaEngine%2FHexaEngine.Sappho/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HexaEngine%2FHexaEngine.Sappho/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HexaEngine","download_url":"https://codeload.github.com/HexaEngine/HexaEngine.Sappho/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HexaEngine%2FHexaEngine.Sappho/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28057674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-26T18:02:52.738Z","updated_at":"2025-12-26T18:03:14.341Z","avatar_url":"https://github.com/HexaEngine.png","language":"C#","funding_links":["https://ko-fi.com/junameinhold"],"categories":[],"sub_categories":[],"readme":"﻿# HexaEngine.Sappho\n\nA high-performance, source-generated binary serialization library for .NET with support for polymorphism, cyclic references, and efficient memory management. Part of the [HexaEngine](https://github.com/HexaEngine/HexaEngine) game engine ecosystem.\n\n## Overview\n\nHexaEngine.Sappho is a specialized serialization library designed for game development scenarios where performance is critical. Originally developed as a submodule for the HexaEngine game engine, it provides efficient binary serialization suitable for:\n\n- **Game State Persistence**: Save/load game states with complex object graphs\n- **Network Communication**: Fast serialization for multiplayer game data\n- **Asset Management**: Efficient binary formats for game assets\n- **Scene Serialization**: Handling complex game object hierarchies with circular references\n\nWhile designed for game engines, Sappho is a standalone library suitable for any .NET application requiring high-performance binary serialization.\n\n## Features\n\n- **🚀 High Performance**: Optimized for speed with unsafe code and minimal allocations\n- **🔄 Cyclic References**: Automatic handling of circular object references\n- **🎭 Polymorphism**: First-class support for polymorphic serialization and deserialization\n- **⚙️ Source Generation**: Uses C# source generators for compile-time serialization code generation\n- **🔧 Flexible**: Support for primitives, strings, enums, structs, and complex object graphs\n- **💾 Efficient**: Binary format with endian-aware operations\n- **🎯 Type-Safe**: Strongly-typed serialization with compile-time validation\n\n## Installation\n\n```bash\ndotnet add package HexaEngine.Sappho\n```\n\n## Quick Start\n\n### 1. Mark Your Classes\n\nUse the `[SapphoObject]` attribute to mark classes or structs for serialization:\n\n```csharp\nusing HexaEngine.Sappho;\n\n[SapphoObject]\npublic partial class Person\n{\n    public string Name { get; set; }\n    public int Age { get; set; }\n    public float Height { get; set; }\n}\n```\n\n\u003e **Note**: Classes must be marked as `partial` to allow the source generator to add serialization code.\n\n### 2. Serialize and Deserialize\n\n```csharp\n// Create a serialization context\nvar context = new SapphoSerializationContext();\n\n// Create an object\nvar person = new Person \n{ \n    Name = \"John Doe\", \n    Age = 30, \n    Height = 5.9f \n};\n\n// Serialize\nusing var writer = new SapphoWriter(context);\nwriter.WriteObject(person);\n\n// Deserialize\nvar reader = new SapphoReader(writer.Buffer, writer.Count, context);\nvar deserializedPerson = reader.ReadObject\u003cPerson\u003e();\n```\n\n## Advanced Features\n\n### Polymorphic Serialization\n\nUse the `[SapphoPolymorphic]` attribute to enable polymorphic serialization:\n\n```csharp\n[SapphoObject]\npublic partial class Animal\n{\n    public string Name { get; set; }\n}\n\n[SapphoObject]\npublic partial class Dog : Animal\n{\n    public string Breed { get; set; }\n}\n\n[SapphoObject]\npublic partial class Cat : Animal\n{\n    public int LivesRemaining { get; set; }\n}\n\n[SapphoObject]\npublic partial class Zoo\n{\n    [SapphoPolymorphic]\n    public Animal[] Animals { get; set; }\n}\n```\n\nWhen using polymorphic types, register them with the serialization context:\n\n```csharp\ncontext.RegisterType\u003cAnimal\u003e(Animal.SapphoTypeId);\ncontext.RegisterType\u003cDog\u003e(Dog.SapphoTypeId);\ncontext.RegisterType\u003cCat\u003e(Cat.SapphoTypeId);\n\nvar zoo = new Zoo\n{\n    Animals = new Animal[]\n    {\n        new Dog { Name = \"Buddy\", Breed = \"Golden Retriever\" },\n        new Cat { Name = \"Whiskers\", LivesRemaining = 9 }\n    }\n};\n```\n\n### Cyclic References\n\nThe library automatically handles cyclic references:\n\n```csharp\n[SapphoObject]\npublic partial class Node\n{\n    public string Name { get; set; }\n    public Node? Next { get; set; }\n}\n\nvar node1 = new Node { Name = \"Node 1\" };\nvar node2 = new Node { Name = \"Node 2\" };\nnode1.Next = node2;\nnode2.Next = node1; // Cyclic reference\n\n// Serialization will handle this correctly\n```\n\n### Ignoring Properties\n\nUse `[SapphoIgnore]` to exclude properties from serialization:\n\n```csharp\n[SapphoObject]\npublic partial class CachedData\n{\n    public string Data { get; set; }\n    \n    [SapphoIgnore]\n    public string CachedValue { get; set; } // Not serialized\n}\n```\n\n### Custom Member Attributes\n\nUse `[SapphoMember]` for fine-grained control over serialization:\n\n```csharp\n[SapphoObject]\npublic partial class CustomClass\n{\n    [SapphoMember]\n    public string ImportantField { get; set; }\n}\n```\n\n## Supported Types\n\n- **Primitives**: `byte`, `sbyte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `float`, `double`, `bool`, `char`\n- **Strings**: UTF-8 encoded with automatic null handling\n- **Enums**: All enum types with any underlying integral type\n- **Structs**: Value types that implement `ISapphoSerializable\u003cT\u003e`\n- **Classes**: Reference types with automatic reference tracking\n- **Arrays**: Single-dimensional arrays of supported types\n- **Nullable Types**: Full support for nullable reference and value types\n\n## Performance\n\nHexaEngine.Sappho is designed for high-performance scenarios:\n\n```csharp\n// From the Example project:\n// Average serialization time: ~XXX ns (depends on object complexity)\n```\n\nThe library uses:\n- Unsafe code for direct memory access\n- Stack allocations for small buffers\n- Efficient buffer management with dynamic resizing\n- Endian-aware binary format\n\n## Architecture\n\n### Core Components\n\n- **SapphoWriter**: Handles serialization to a binary buffer\n- **SapphoReader**: Handles deserialization from a binary buffer\n- **SapphoSerializationContext**: Manages type registration and reference tracking\n- **Source Generator**: Automatically generates serialization code at compile time\n\n### Interfaces\n\n- **`ISapphoSerializable\u003cT\u003e`**: Base interface for serializable types\n- **`ISapphoSerializer\u003cT\u003e`**: Custom serializer interface\n- **`ISapphoInstanceId`**: Optional interface for custom instance ID tracking\n\n## Project Structure\n\n```\nHexaEngine.Sappho/\n├── HexaEngine.Sappho/           # Core serialization library\n├── HexaEngine.Sappho.Analyzer/  # Source generator\n├── HexaEngine.Sappho.Tests/     # Unit tests\n└── Example/                      # Example usage\n```\n\n## Requirements\n\n- **.NET 9.0** or later (core library)\n- **.NET Standard 2.0** or later (analyzer)\n- **C# 12** or later (for source generation features)\n\n## Building\n\n```bash\ndotnet build\n```\n\n## Testing\n\n```bash\ndotnet test\n```\n\nThe test suite includes comprehensive tests for:\n- Primitive type serialization\n- String handling (including Unicode and empty strings)\n- Enum serialization\n- Struct serialization\n- Polymorphic serialization\n- Cyclic reference handling\n- Null value handling\n\n## Contributing\n\nContributions are welcome! Please ensure:\n- All tests pass\n- Code follows existing conventions\n- New features include appropriate tests\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/HexaEngine/HexaEngine.Sappho/blob/main/LICENSE.txt) file for more details.\n\n## Credits\n\nPart of the HexaEngine ecosystem.\n\nDeveloped as a submodule for [HexaEngine](https://github.com/HexaEngine/HexaEngine) - a modern game engine for .NET.\n\n## See Also\n\n- [HexaEngine](https://github.com/HexaEngine/HexaEngine) - The main game engine project\n- [Hexa.NET.Utilities](https://github.com/HexaEngine/Hexa.NET.Utilities) - Utility library used by Sappho\n\n---\n\n**Do you listen to girl in red?**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexaengine%2Fhexaengine.sappho","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexaengine%2Fhexaengine.sappho","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexaengine%2Fhexaengine.sappho/lists"}