TuplePacker<T>

Namespace: SnowBank.Data.Tuples.Binary · class

Helper class for serializing and deserializing values of type T using the tuple binary format

Methods

Deserialize

static T Deserialize(Slice slice)

Deserializes a tuple segment into a value of type T.

  • slice — Slice that contains the binary representation of a tuple item.

Returns: Decoded value, or an exception if the item type is not compatible.

static T Deserialize(ReadOnlySpan<byte> span)

Deserializes a tuple segment into a value of type T.

  • span — Span that contains the binary representation of a tuple item

Returns: Decoded value, or an exception if the item type is not compatible

SerializeBoxedTo

static void SerializeBoxedTo(TupleWriter writer, object value)

Serializes a boxed value to the tuple format using a TupleWriter.

  • writer — The TupleWriter into which the value will be serialized.
  • value — The boxed value to be serialized. The value must be assignable to type T.

The buffer does not need to be pre-allocated.

This method is useful for scenarios where the value is boxed and needs to be serialized without knowing its type at compile time. The buffer does not need to be pre-allocated.

TrySerializeBoxedTo

static bool TrySerializeBoxedTo(ref TupleSpanWriter writer, in object value)

Serializes a boxed value to the tuple format using a TupleWriter.

  • writer — The TupleWriter into which the value will be serialized.
  • value — The boxed value to be serialized. The value must be assignable to type T.

The buffer does not need to be pre-allocated.

This method is useful for scenarios where the value is boxed and needs to be serialized without knowing its type at compile time. The buffer does not need to be pre-allocated.