Class StackSerializer<T>
Type serializer for Stack<T> collections. Serializes the stack as a JSON array with elements in their push order (top-of-stack first), then restores the original stack ordering on deserialization. A null reference is serialized as a null token.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class StackSerializer<T> : TypeSerializerBase<Stack<T>>, ITypeSerializer<Stack<T>>, ITypeSerializer
Type Parameters
| Name | Description |
|---|---|
| T | The element type of the stack. Element serialization is handled either by the explicitly supplied ITypeSerializer or by dynamic dispatch through SerializationEngine. |
Remarks
Stack<T> enumerates elements top-to-bottom (LIFO order). On write, this serializer converts the stack to an array first so that the serialized representation reflects top-to-bottom order in the JSON array.
On read, elements are collected into a List<T>, then reversed and pushed onto a new stack one by one, so that the resulting stack's top matches the first element of the JSON array. This guarantees a round-trip faithful to the original LIFO order.
Comma handling between JSON elements is delegated to SkipComma() when the active reader is a ScyllaJSONReader.
Constructors
StackSerializer(ITypeSerializer)
Creates a Stack serializer that uses the specified serializer for each element.
Declaration
public StackSerializer(ITypeSerializer elementSerializer)
Parameters
| Type | Name | Description |
|---|---|---|
| ITypeSerializer | elementSerializer | The non-generic serializer to use for every stack element, or |
Methods
Read(IScyllaReader, ISerializationContext)
Reads a Stack<T> from the reader and reconstructs the original LIFO order.
Returns null when the next token is a null literal; otherwise reads all elements
from the array, reverses them, and pushes them onto a new stack so that the first
element of the JSON array ends up at the top.
Declaration
public override Stack<T> Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of an array token sequence or a null token.
Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| Stack<T> | The deserialized stack with the original push order restored, or |
Overrides
Write(Stack<T>, IScyllaWriter, ISerializationContext)
Writes a Stack<T> to the output.
Emits a null token if value is null; otherwise converts the
stack to an array (preserving top-to-bottom enumeration order) and emits a JSON array.
Declaration
public override void Write(Stack<T> value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| Stack<T> | value | The stack to serialize, or |
| IScyllaWriter | writer | The writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context. Never |