AyCode.Core/AyCode.Core/Serializers
Loretta 910b0deab8 [LOADED_DOCS: 2 files, no new loads]
Separate raw and framed streaming in AcBinarySerializer

Refactored AcBinarySerializer and AsyncPipeWriterOutput to support both raw (headerless) and multiplexed/framed ([201][UINT16][data]) streaming wire formats, controlled by a new flag and explicit APIs. Updated AsyncPipeReaderInput and AcBinaryDeserializer to match, with new constructor options and documentation. Expanded tests for both modes and added runtime type detection for flush strategy safety. Minor refactoring and doc improvements throughout.
2026-04-29 16:09:33 +02:00
..
Attributes Document AcBinary wire format, sync docs, update conventions 2026-03-29 09:11:57 +02:00
Binaries [LOADED_DOCS: 2 files, no new loads] 2026-04-29 16:09:33 +02:00
Expressions Document AcBinary wire format, sync docs, update conventions 2026-03-29 09:11:57 +02:00
Jsons Document AcBinary wire format, sync docs, update conventions 2026-03-29 09:11:57 +02:00
Toons [LOADED_DOCS: 4 files, no new loads] 2026-04-24 21:54:04 +02:00
AcSerializerCommon.cs Add polymorphic support for System.Object properties 2026-02-25 09:13:56 +01:00
AcSerializerContextBase.cs Polymorphic serialization: slot-based prefix system overhaul 2026-03-09 15:04:46 +01:00
AcSerializerOptions.cs Update defaults, docs, and internals for AcBinary serializer 2026-04-02 22:17:46 +02:00
DeserializationContextBase.cs Refactor serializer options, string fast paths & analysis 2026-01-25 16:40:40 +01:00
DeserializeChainBase.cs Refactor: Add high-performance Chain API for serializers 2025-12-29 22:41:28 +01:00
DeserializeCrossTypeBase.cs Refactor Toon serializer: modularize metadata & relations 2026-01-14 15:39:03 +01:00
DeserializeTypeMetadataBase.cs Refactor: unify metadata and tracking for serializer contexts 2026-01-18 15:31:45 +01:00
FnvHash.cs Enable cross-type deserialization via property hashes 2026-02-04 09:38:49 +01:00
IIdCollectionMergeHelper.cs Track buffer growth stats in DEBUG; disable IId merge helper 2026-01-29 09:41:53 +01:00
IdentityMap.cs Optimize serializer with write plan for interning & refs 2026-02-15 17:28:06 +01:00
PropertyAccessorBase.cs Refactor serializer options, string fast paths & analysis 2026-01-25 16:40:40 +01:00
PropertyMetadataBase.cs Improve string interning logic in AcBinarySerializer 2026-02-14 11:07:26 +01:00
PropertySetterBase.cs Refactor property metadata; add console perf profiler 2026-01-21 16:47:40 +01:00
README.md Document AcBinary wire format, sync docs, update conventions 2026-03-29 09:11:57 +02:00
ReferenceTracker.cs Refactor serialization/deserialization context base classes 2026-01-20 19:49:55 +01:00
SerializationContextBase.cs Optimize cache index assignment during scan pass 2026-02-06 15:48:48 +01:00
SerializeTypeMetadataBase.cs Refactor: unify metadata and tracking for serializer contexts 2026-01-18 15:31:45 +01:00
TypeMetadataBase.cs Per-type metadata control for binary serialization 2026-02-20 09:55:21 +01:00
TypeMetadataWrapper.cs Polymorphic serialization: slot-based prefix system overhaul 2026-03-09 15:04:46 +01:00

README.md

Serializers

High-performance serialization framework supporting three formats — Binary, JSON, and Toon — built on a shared infrastructure.

Folder Structure

Folder Purpose
Binaries/ High-performance binary serialization with two-phase scan+serialize
Jsons/ Custom JSON serialization using Utf8JsonWriter/Utf8JsonReader
Toons/ LLM-optimized Token-Oriented Object Notation with @meta/@data sections
Expressions/ Expression tree serialization (LINQ Expression ↔ DTO)
Attributes/ Source generator marker attributes

Shared Infrastructure (Root Files)

Core Base Classes

  • AcSerializerContextBase.cs — Generic base context AcSerializerContextBase<TMetadata, TOptions> with metadata caching, wrapper slot management, and context pooling. All three serializers derive from this.
  • AcSerializerOptions.cs — Base options: reference handling mode, max depth, custom property mapping, ThrowOnCircularReference.
  • TypeMetadataBase.cs — Cached type analysis: readable/writable properties, IId detection, complexity flags (HasComplexProperties, NeedsReferenceTracking, IsCollection).
  • TypeMetadataWrapper.cs — Wraps metadata with per-context tracking state: typed IdentityMap instances (Int32/Int64/Guid), SmallIdBitmap, polymorphic cache, source-gen reader/writer registry lookup.

Serialization/Deserialization Bases

  • SerializationContextBase.cs — Base for serialization contexts.
  • DeserializationContextBase.cs — Base for deserialization contexts.
  • SerializeTypeMetadataBase.cs — Base for format-specific serialize metadata.
  • DeserializeTypeMetadataBase.cs — Base for format-specific deserialize metadata.
  • DeserializeChainBase.cs — Deserialization chain pattern.
  • DeserializeCrossTypeBase.cs — Cross-type deserialization support.

Property Handling

  • PropertyAccessorBase.cs — Base for reading property values during serialization.
  • PropertySetterBase.cs — Base for writing property values during deserialization.
  • PropertyMetadataBase.cs — Base property metadata shared across formats.

Utilities

  • AcSerializerCommon.cs — Expression type checking, queryable type refs, ThreadLocal cache helpers, compiled constructor creation.
  • IdentityMap.cs — High-performance hash table optimized for small int keys (bitmap) + chaining for large keys. Used for reference tracking.
  • FnvHash.cs — Deterministic FNV-1a property name hashing (used in Binary UseMetadata mode).
  • ReferenceTracker.csReferenceEqualityComparer for object identity-based tracking dictionaries.
  • IIdCollectionMergeHelper.cs — Collection merge operations during PopulateMerge (handles orphaned item removal).

Architecture

Generic Specialization Pattern

AcSerializerContextBase<TMetadata, TOptions>
├─ BinarySerializationContext  <BinarySerializeTypeMetadata,  AcBinarySerializerOptions>
├─ JsonSerializationContext    <JsonSerializeTypeMetadata,     AcJsonSerializerOptions>
└─ ToonSerializationContext    <ToonSerializeTypeMetadata,     AcToonSerializerOptions>

Key Design Decisions

  • Sealed derived classes — All context implementations are sealed for JIT direct calling (no virtual dispatch on hot paths).
  • Context pooling — Contexts are reused across serializations via thread-safe pools. ResetTracking() clears reference maps on pool return.
  • Property ordering — Hierarchy-aware (base→derived) then alphabetical. Ensures stable property indices across type versions.
  • Typed reference access — No boxing for common ID types. Pre-cast delegates: RefIdGetterInt32, RefIdGetterInt64, RefIdGetterGuid.
  • Zero-allocation hot paths — Buffer owned by context, Span-based operations, ArrayPool for large allocations.
  • Global metadata cache — Thread-safe per TMetadata type, shared across all contexts of that serializer type.

Reference Handling Modes

Mode Description
None No tracking, fastest path
OnlyId Only IId<T> types tracked (Binary only)
All All reference types tracked (required for JSON $ref)