Class TimeSpanSerializer
Type serializer for TimeSpan values. Persists the duration as a raw 64-bit tick count (100-nanosecond intervals) via WriteLong(long), guaranteeing lossless round-trip precision for any representable TimeSpan.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class TimeSpanSerializer : TypeSerializerBase<TimeSpan>, ITypeSerializer<TimeSpan>, ITypeSerializer
Remarks
Storing ticks rather than a human-readable string (e.g., HH:mm:ss.fffffff)
avoids culture-specific formatting issues and guarantees that all 64-bit tick values
survive a round-trip without rounding. The trade-off is that the output is not
human-readable in JSON.
Use the shared Instance singleton rather than creating new instances;
TimeSpanSerializer carries no mutable state and is safe to share across threads.
Fields
Instance
Shared, reusable singleton instance of TimeSpanSerializer.
Prefer this over allocating a new instance wherever a TimeSpanSerializer is needed.
Declaration
public static readonly TimeSpanSerializer Instance
Field Value
| Type | Description |
|---|---|
| TimeSpanSerializer |
Methods
Read(IScyllaReader, ISerializationContext)
Reads a tick count from the reader and reconstructs the corresponding TimeSpan.
Declaration
public override TimeSpan Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at a long (tick count) token. Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| TimeSpan | The deserialized TimeSpan equivalent to the stored tick count. |
Overrides
Write(TimeSpan, IScyllaWriter, ISerializationContext)
Writes the Ticks of value to the output as
a signed 64-bit integer via WriteLong(long).
Declaration
public override void Write(TimeSpan value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | value | The TimeSpan whose tick count to serialize. |
| IScyllaWriter | writer | The writer that receives the serialized token. Never |
| ISerializationContext | context | The active serialization context. Never |