AyCode.Core/AyCode.Core/Serializers/Binaries
Loretta 67589f6b6f [LOADED_DOCS: 3 files, no new loads]
Move DrainFromAsync to tests, add in-memory benchmarks

- Moved AsyncPipeReaderInputExtensions.DrainFromAsync from the main framework to test-only assembly; no longer public API.
- Removed AcBinaryDeserializer.DeserializeFromPipeReaderAsync<T> from public API; tests now inline drain+deserialize logic.
- Added AcBinaryInMemoryPipeBenchmark and AcBinaryInMemoryRawByteArrayBenchmark to complete 2x2 transport × wire-format benchmark matrix.
- Refactored benchmark runner for interactive menu, settings, and CLI parsing.
- Expanded XML docs for AsyncPipeReaderInput and AsyncPipeWriterOutput to clarify push-pattern and real-world usage.
- Updated BINARY_ASYNCPIPE_TODO.md and related docs to reflect these changes.
2026-05-02 15:51:07 +02:00
..
AcBinaryDeserializationException.cs Refactor serialization reference tracking and contexts 2026-01-17 10:06:46 +01:00
AcBinaryDeserializer.BinaryDeserializationContext.Read.cs Refactor BenchmarkTestDataProvider for flexibility & clarity 2026-04-07 14:27:12 +02:00
AcBinaryDeserializer.BinaryDeserializationContext.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00
AcBinaryDeserializer.BinaryDeserializeTypeMetadata.cs Optimize AcBinary hot paths with pre-cached type wrappers 2026-02-14 01:41:54 +01:00
AcBinaryDeserializer.CrossType.cs Zero-copy SignalR: direct object response, no SignalData 2026-04-06 22:45:00 +02:00
AcBinaryDeserializer.Populate.cs Improve circular reference handling in binary serializer 2026-02-23 16:01:37 +01:00
AcBinaryDeserializer.cs [LOADED_DOCS: 3 files, no new loads] 2026-05-02 15:51:07 +02:00
AcBinarySerializer.BinarySerializationContext.PropertyWriters.cs Optimize serialization lookups; add SignalR binary toggle 2026-04-04 23:22:47 +02:00
AcBinarySerializer.BinarySerializationContext.cs Improve string serialization and buffer preallocation 2026-04-08 09:50:46 +02:00
AcBinarySerializer.BinarySerializationResult.cs
AcBinarySerializer.BinarySerializeTypeMetadata.cs Add unsafe write methods and MinWriteSize for serialization 2026-02-21 19:41:37 +01:00
AcBinarySerializer.ScanPass.cs Optimize string interning and context state checks 2026-03-01 13:31:45 +01:00
AcBinarySerializer.cs [LOADED_DOCS: 3 files, no new loads] 2026-05-02 15:51:07 +02:00
AcBinarySerializerOptions.cs [LOADED_DOCS: 3 files, no new loads] 2026-04-28 20:23:07 +02:00
AcStringInternAttribute.cs Refactor string interning to use enum and attribute 2026-01-26 11:04:25 +01:00
ArrayBinaryInput.cs Refactor SequenceBinaryInput: zero-copy, docs, issues 2026-04-07 10:33:38 +02:00
ArrayBinaryOutput.cs Improve string serialization and buffer preallocation 2026-04-08 09:50:46 +02:00
ArrayPooledBufferWriter.cs Refactor: move buffer/position to context for zero dispatch 2026-02-11 13:02:24 +01:00
AsyncPipeReaderInput.cs [LOADED_DOCS: 3 files, no new loads] 2026-05-02 15:51:07 +02:00
AsyncPipeReaderInputAdapter.cs [LOADED_DOCS: 3 files, no new loads] 2026-04-28 20:23:07 +02:00
AsyncPipeWriterOutput.cs [LOADED_DOCS: 3 files, no new loads] 2026-05-02 15:51:07 +02:00
BinaryOutputBase.cs Replace Newtonsoft.Json benchmark with AcBinary BufferWriter 2026-02-11 17:29:19 +01:00
BinaryPropertyAccessorBase.cs Polymorphic serialization: slot-based prefix system overhaul 2026-03-09 15:04:46 +01:00
BinaryPropertyFilterContext.cs Support nested types in source gen; improve prop filtering 2026-02-17 21:07:19 +01:00
BinaryPropertySetterBase.cs Optimize bool/enum serialization and ASCII string decoding 2026-02-15 10:37:12 +01:00
BinaryTypeCode.cs SignalR: Add streaming & zero-copy binary protocol 2026-04-04 00:47:48 +02:00
BufferWriterBinaryOutput.cs Improve string serialization and buffer preallocation 2026-04-08 09:50:46 +02:00
IBinaryInputBase.cs Refactor SequenceBinaryInput: zero-copy, docs, issues 2026-04-07 10:33:38 +02:00
IGeneratedBinaryReader.cs Add ReadProperties to binary reader for inline deserialization 2026-03-02 06:43:30 +01:00
IGeneratedBinaryWriter.cs Source-generated scan pass for SGen binary serialization 2026-02-19 16:40:16 +01:00
README.md [LOADED_DOCS: 4 files, no new loads] 2026-04-24 21:54:04 +02:00
SegmentBufferReader.cs [LOADED_DOCS: 2 files, no new loads] 2026-04-28 14:18:27 +02:00
SegmentBufferReaderInput.cs [LOADED_DOCS: 2 files, no new loads] 2026-04-28 14:18:27 +02:00
SequenceBinaryInput.cs Refactor BenchmarkTestDataProvider for flexibility & clarity 2026-04-07 14:27:12 +02:00
StringInterningMode.cs Refactor string interning to use enum and attribute 2026-01-26 11:04:25 +01:00
TypeConversionInfo.cs Refactor serialization reference tracking and contexts 2026-01-17 10:06:46 +01:00

README.md

Binaries

High-performance binary serialization/deserialization. Two-phase processing, multiple wire modes, string interning, source generation. Primary goal: speed.

Implementation details (zero virtual dispatch, buffer management): ../../docs/BINARY/BINARY_IMPLEMENTATION.md Output writers (ArrayBinaryOutput, BufferWriterBinaryOutput, chunk sizing): ../../docs/BINARY/BINARY_WRITERS.md Source generation (SGen architecture, hybrid model, bridge methods): ../../docs/BINARY/BINARY_SGEN.md

Architecture

Two-Phase Serialization

  1. Scan (ScanPass.cs) — walks graph, detects multi-ref objects, builds reference table
  2. Serialize (BinarySerializationContext.cs) — writes binary using reference table

Generic over TOutput for strategy selection (ArrayBinaryOutput vs BufferWriterBinaryOutput).

Root Dispatch

Two root paths in AcBinarySerializer.Serialize<T>:

Path Condition Dispatch depth
SGen fast UseGeneratedCode + GeneratedWriter != null 3 checks → WriteObject directly
Full runtime No GeneratedWriter or UseGeneratedCode=false IQueryable → Expression → TryWritePrimitive → WriteValueNonPrimitive → WriteObject

SGen fast path skips: is IQueryable, IsExpressionType, TryWritePrimitive (GetTypeCode + 15-case switch), WriteValueNonPrimitive (4 interface checks). Wire format identical. Details: ../../docs/BINARY/BINARY_SGEN.md.

Wire Format

BinaryTypeCode.cs — 100+ type markers:

Range Purpose
063 FixObj — compiled type slot indices
6471 Complex — Object, ObjectRef, Array, Dictionary, ByteArray
7275 Polymorphic — ObjectWithTypeName/TypeIndex (±RefFirst)
7690 Primitives — Null, Bool, Int864, Float3264, Decimal, Char
9194 Strings — String, StringInterned, StringEmpty, StringInternFirst
9598 Date/Time — DateTime, DateTimeOffset, TimeSpan, Guid
99102 Other — Enum, Legacy, PropertySkip
103134 FixStr — short strings (length in marker)
144+ Headers — Metadata, RefHandling, CacheCount
192255 Tiny ints — single-byte -16..47

Full spec: docs/BINARY/BINARY_FORMAT.md

Key Files

Serialization

  • AcBinarySerializer.cs — entry point, context pool
  • ...BinarySerializationContext.cs — core logic, graph traversal, type writing
  • ...PropertyWriters.cs — per-type property write methods
  • ...BinarySerializationResult.cs — result wrapper
  • ...BinarySerializeTypeMetadata.cs — cached type metadata
  • ...ScanPass.cs — reference scanning

Deserialization

  • AcBinaryDeserializer.cs — entry point
  • ...BinaryDeserializationContext.cs — core logic
  • ...BinaryDeserializationContext.Read.cs — primitive reads
  • ...BinaryDeserializeTypeMetadata.cs — cached type metadata
  • ...CrossType.cs — schema evolution
  • ...Populate.cs — object population/merge

I/O

  • BinaryOutputBase.cs — output interface
  • ArrayBinaryOutput.cs — ArrayPool-backed, fastest for byte[]
  • BufferWriterBinaryOutput.cs — IBufferWriter-backed, zero-copy streaming. Context mode (serializer) + standalone mode (direct writes, e.g. AcBinaryHubProtocol)
  • ArrayPooledBufferWriter.cs — concrete IBufferWriter
  • IBinaryInputBase.cs / ArrayBinaryInput.cs / SequenceBinaryInput.cs — input strategies

Config & Types

  • AcBinarySerializerOptions.cs — options, presets
  • BinaryTypeCode.cs — wire format markers
  • StringInterningMode.cs — None/Attribute/All
  • AcStringInternAttribute.cs — property-level interning
  • TypeConversionInfo.cs — cross-type tracking
  • BinaryPropertyFilterContext.cs — instance-dependent filtering

Property Handling

  • BinaryPropertyAccessorBase.cs / BinaryPropertySetterBase.cs

Source Generation

  • IGeneratedBinaryWriter.cs / IGeneratedBinaryReader.cs

Exceptions

  • AcBinaryDeserializationException.cs — rich exception with binary offset

Config Options

Key wire-format options: WireMode (Compact/Fast), ReferenceHandling (None/OnlyId/All), UseMetadata, UseStringInterning (None/Attribute/All), MaxDepth, UseCompression, PropertyFilter.

ReferenceHandling=None + UseStringInterning=None = no scan pass (single-phase, fastest).

Presets: Default, FastMode, ShallowCopy, WasmOptimized. Details: docs/BINARY/BINARY_OPTIONS.md.

Dependencies

  • Base classes: parent Serializers/ (AcSerializerContextBase, TypeMetadataBase, IdentityMap)
  • System.Buffers (ArrayPool, IBufferWriter)
  • LZ4 (optional compression)