BinaryConverter
Provides async object-to-byte and byte-to-object conversion using Ceras for performance, with a fallback to JSON serialization for compatibility. Supports JToken through a custom converter (Important for Account and DataHandler systems especially)
Types
BinaryConverter
Static class providing serialization and deserialization logic for arbitrary object graphs.
-
Fields:
- JsonSerializerOptions _options: Internal configuration for JSON fallback, including a custom JTokenConverter
-
Nested Types:
- JTokenConverter: Custom converter that handles serialization and deserialization of JToken values using System.Text.Json.
Methods
Task<byte[]> NCObjectToByteArrayAsync(T obj, SerializerConfig? config = null, CancellationToken cancellationToken = default)
Attempts to serialize the object using Ceras. Falls back to JSON if the object isn't compatible.
-
Parameters:
- obj: The object to serialize.
- config: Optional Ceras configuration.
- cancellationToken: Optional cancellation support.
-
Returns: byte[]
Task<T?> NCByteArrayToObjectAsync(byte[] data, SerializerConfig? config = null, CancellationToken cancellationToken = default)
Attempts to deserialize data using Ceras. Falls back to JSON deserialization if Ceras fails.
-
Parameters:
- data: The byte array representing the serialized object.
- config: Optional Ceras configuration.
- cancellationToken: Optional cancellation support.
-
Returns: T?