TuplePackers
Namespace: SnowBank.Data.Tuples.Binary · class
Helper methods used during serialization of values to the tuple binary format
Methods
DeserializeBigInteger
static BigInteger DeserializeBigInteger(ReadOnlySpan<byte> slice)
Deserialize a tuple segment into a BigInteger
slice— Slice that contains a single packed element
DeserializeBigIntegerNullable
static BigInteger? DeserializeBigIntegerNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable BigInteger
slice— Slice that contains a single packed element
DeserializeBoolean
static bool DeserializeBoolean(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Boolean
slice— Slice that contains a single packed element
DeserializeBooleanNullable
static bool? DeserializeBooleanNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Boolean
slice— Slice that contains a single packed element
DeserializeBoxed
static object DeserializeBoxed(Slice slice)
Deserializes a packed element into an object by choosing the most appropriate type at runtime
slice— Slice that contains a single packed element
Returns: Decoded element, in the type that is the best fit.
You should avoid working with untyped values as much as possible! Blindly casting the returned object may be problematic because this method may need to return very large integers as Int64 or even UInt64.
static object DeserializeBoxed(ReadOnlySpan<byte> slice)
Deserializes a packed element into an object by choosing the most appropriate type at runtime
slice— Slice that contains a single packed element
Returns: Decoded element, in the type that is the best fit.
You should avoid working with untyped values as much as possible! Blindly casting the returned object may be problematic because this method may need to return very large integers as Int64 or even UInt64.
DeserializeByte
static byte DeserializeByte(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an Byte
slice— Slice that contains a single packed element
DeserializeByteNullable
static byte? DeserializeByteNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Byte
slice— Slice that contains a single packed element
DeserializeBytes
static byte[] DeserializeBytes(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a byte array
DeserializeChar
static char DeserializeChar(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Unicode character
slice— Slice that contains a single packed element
DeserializeCharNullable
static char? DeserializeCharNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Unicode character
slice— Slice that contains a single packed element
DeserializeDateTime
static DateTime DeserializeDateTime(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a DateTime (UTC)
slice— Slice that contains a single packed element
Returns: DateTime in UTC
The returned DateTime will be in UTC, because the original TimeZone details are lost.
DeserializeDateTimeNullable
static DateTime? DeserializeDateTimeNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable DateTime (UTC)
slice— Slice that contains a single packed element
Returns: DateTime in UTC
The returned DateTime will be in UTC, because the original TimeZone details are lost.
DeserializeDateTimeOffset
static DateTimeOffset DeserializeDateTimeOffset(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a DateTimeOffset
slice— Slice that contains a single packed element
Returns: DateTime in UTC
The returned DateTimeOffset will be in UTC if converted value did not specify any offset.
DeserializeDateTimeOffsetNullable
static DateTimeOffset? DeserializeDateTimeOffsetNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable DateTimeOffset
slice— Slice that contains a single packed element
Returns: DateTime in UTC
The returned DateTimeOffset will be in UTC if converted value did not specify any offset.
DeserializeDouble
static double DeserializeDouble(ReadOnlySpan<byte> slice)
Deserialize a tuple segment into a Double
slice— Slice that contains a single packed element
DeserializeDoubleNullable
static double? DeserializeDoubleNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Double
slice— Slice that contains a single packed element
DeserializeGuid
static Guid DeserializeGuid(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Guid
slice— Slice that contains a single packed element
DeserializeGuidNullable
static Guid? DeserializeGuidNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Guid
slice— Slice that contains a single packed element
DeserializeInt128
static Int128 DeserializeInt128(ReadOnlySpan<byte> slice)
Deserialize a tuple segment into a Int128
slice— Slice that contains a single packed element
DeserializeInt128Nullable
static Int128? DeserializeInt128Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Int128
slice— Slice that contains a single packed element
DeserializeInt16
static short DeserializeInt16(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an Int16
slice— Slice that contains a single packed element
DeserializeInt16Nullable
static short? DeserializeInt16Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Int16
slice— Slice that contains a single packed element
DeserializeInt32
static int DeserializeInt32(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an Int32
slice— Slice that contains a single packed element
DeserializeInt32Nullable
static int? DeserializeInt32Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Int32
slice— Slice that contains a single packed element
DeserializeInt64
static long DeserializeInt64(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an Int64
slice— Slice that contains a single packed element
DeserializeInt64Nullable
static long? DeserializeInt64Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Int64
slice— Slice that contains a single packed element
DeserializeIpAddress
static IPAddress DeserializeIpAddress(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an IPAddress
slice— Slice that contains a single packed element
DeserializeSByte
static sbyte DeserializeSByte(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an SByte
slice— Slice that contains a single packed element
DeserializeSByteNullable
static sbyte? DeserializeSByteNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable SByte
slice— Slice that contains a single packed element
DeserializeSingle
static float DeserializeSingle(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Single
slice— Slice that contains a single packed element
DeserializeSingleNullable
static float? DeserializeSingleNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Single
slice— Slice that contains a single packed element
DeserializeSlice
static Slice DeserializeSlice(Slice slice)
Deserializes a tuple segment into a Slice
static Slice DeserializeSlice(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Slice
DeserializeString
static string DeserializeString(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Unicode string
slice— Slice that contains a single packed element
DeserializeTimeSpan
static TimeSpan DeserializeTimeSpan(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a TimeSpan
slice— Slice that contains a single packed element
DeserializeTimeSpanNullable
static TimeSpan? DeserializeTimeSpanNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable TimeSpan
slice— Slice that contains a single packed element
DeserializeTuple
static IVarTuple DeserializeTuple(Slice slice)
Deserializes a tuple segment into a tuple
static IVarTuple DeserializeTuple(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a tuple
static STuple<T1> DeserializeTuple<T1>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of a single element
static STuple<T1, T2> DeserializeTuple<T1, T2>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 2 elements
static STuple<T1, T2, T3> DeserializeTuple<T1, T2, T3>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 3 elements
static STuple<T1, T2, T3, T4> DeserializeTuple<T1, T2, T3, T4>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 4 elements
static STuple<T1, T2, T3, T4, T5> DeserializeTuple<T1, T2, T3, T4, T5>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 5 elements
static STuple<T1, T2, T3, T4, T5, T6> DeserializeTuple<T1, T2, T3, T4, T5, T6>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 6 elements
static STuple<T1, T2, T3, T4, T5, T6, T7> DeserializeTuple<T1, T2, T3, T4, T5, T6, T7>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 7 elements
DeserializeUInt128
static UInt128 DeserializeUInt128(ReadOnlySpan<byte> slice)
Deserialize a tuple segment into a UInt128
slice— Slice that contains a single packed element
DeserializeUInt128Nullable
static UInt128? DeserializeUInt128Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Int128
slice— Slice that contains a single packed element
DeserializeUInt16
static ushort DeserializeUInt16(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an UInt16
slice— Slice that contains a single packed element
DeserializeUInt16Nullable
static ushort? DeserializeUInt16Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable UInt16
slice— Slice that contains a single packed element
DeserializeUInt32
static uint DeserializeUInt32(ReadOnlySpan<byte> slice)
Deserializes a slice into an UInt32
slice— Slice that contains a single packed element
DeserializeUInt32Nullable
static uint? DeserializeUInt32Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable UInt32
slice— Slice that contains a single packed element
DeserializeUInt64
static ulong DeserializeUInt64(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into an UInt64
slice— Slice that contains a single packed element
DeserializeUInt64Nullable
static ulong? DeserializeUInt64Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable UInt64
slice— Slice that contains a single packed element
DeserializeUserType
static TuPackUserType DeserializeUserType(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a custom tuple type
DeserializeUuid128
static Uuid128 DeserializeUuid128(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Uuid128
slice— Slice that contains a single packed element
DeserializeUuid128Nullable
static Uuid128? DeserializeUuid128Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Uuid128
slice— Slice that contains a single packed element
DeserializeUuid48
static Uuid48 DeserializeUuid48(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into 64-bit UUID
slice— Slice that contains a single packed element
DeserializeUuid48Nullable
static Uuid48? DeserializeUuid48Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Uuid64
slice— Slice that contains a single packed element
DeserializeUuid64
static Uuid64 DeserializeUuid64(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into 64-bit UUID
slice— Slice that contains a single packed element
DeserializeUuid64Nullable
static Uuid64? DeserializeUuid64Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Uuid64
slice— Slice that contains a single packed element
DeserializeUuid80
static Uuid80 DeserializeUuid80(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Uuid80
slice— Slice that contains a single packed element
DeserializeUuid80Nullable
static Uuid80? DeserializeUuid80Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Uuid80
slice— Slice that contains a single packed element
DeserializeUuid96
static Uuid96 DeserializeUuid96(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a Uuid96
slice— Slice that contains a single packed element
DeserializeUuid96Nullable
static Uuid96? DeserializeUuid96Nullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable Uuid96
slice— Slice that contains a single packed element
DeserializeValueTuple
static (T1) DeserializeValueTuple<T1>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of a single element
static (T1, T2) DeserializeValueTuple<T1, T2>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 2 elements
static (T1, T2, T3) DeserializeValueTuple<T1, T2, T3>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 3 elements
static (T1, T2, T3, T4) DeserializeValueTuple<T1, T2, T3, T4>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 4 elements
static (T1, T2, T3, T4, T5) DeserializeValueTuple<T1, T2, T3, T4, T5>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 5 elements
static (T1, T2, T3, T4, T5, T6) DeserializeValueTuple<T1, T2, T3, T4, T5, T6>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 6 elements
static (T1, T2, T3, T4, T5, T6, T7) DeserializeValueTuple<T1, T2, T3, T4, T5, T6, T7>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 7 elements
static (T1, T2, T3, T4, T5, T6, T7, (T8)) DeserializeValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>(ReadOnlySpan<byte> slice)
Deserializes a slice containing a tuple composed of 8 elements
DeserializeVersionStamp
static VersionStamp DeserializeVersionStamp(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a VersionStamp
slice— Slice that contains a single packed element
static bool DeserializeVersionStamp(ReadOnlySpan<byte> slice, out VersionStamp value)
Deserializes a tuple segment into a VersionStamp
slice— Slice that contains a single packed elementvalue— Corresponding value
DeserializeVersionStampNullable
static VersionStamp? DeserializeVersionStampNullable(ReadOnlySpan<byte> slice)
Deserializes a tuple segment into a nullable VersionStamp
slice— Slice that contains a single packed element
IsNegativeInteger
static bool IsNegativeInteger(ReadOnlySpan<byte> slice)
Tests if the slice corresponding to the encoding of a negative integer
IsPositiveInteger
static bool IsPositiveInteger(ReadOnlySpan<byte> slice)
Tests if the slice corresponding to the encoding of a positive integer (including 0)
SerializeNullableTo
static void SerializeNullableTo<T>(TupleWriter writer, T? value)
Serialize a nullable value, by checking for null at runtime
writer— Target buffervalue— Nullable value to serialize
Uses the underlying type's serializer if the value is not null
SerializeObjectTo
static void SerializeObjectTo(TupleWriter writer, object value)
Serialize an untyped object, by checking its type at runtime [VERY SLOW]
writer— Target buffervalue— Untyped value whose type will be inspected at runtime
May throw at runtime if the type is not supported. This method will be very slow! Please consider using typed tuples instead!
SerializePackableItemsTo
static void SerializePackableItemsTo<T>(TupleWriter writer, T value)
Serialize a nullable value, by checking for null at runtime
writer— Target buffervalue— Nullable value to serialize
Uses the underlying type's serializer if the value is not null
SerializePackableTupleTo
static void SerializePackableTupleTo<TTuple>(TupleWriter writer, TTuple tuple)
Serialize a packable tuple
writer— Target buffertuple— Tuple to pack
SerializeValueTupleTo
static void SerializeValueTupleTo<T1>(TupleWriter writer, (T1) tuple)
Serializes a tuple with a single element
static void SerializeValueTupleTo<T1, T2>(TupleWriter writer, (T1, T2) tuple)
Serializes a tuple with 2 elements
static void SerializeValueTupleTo<T1, T2, T3>(TupleWriter writer, (T1, T2, T3) tuple)
Serializes a tuple with 3 elements
static void SerializeValueTupleTo<T1, T2, T3, T4>(TupleWriter writer, (T1, T2, T3, T4) tuple)
Serializes a tuple with 4 elements
static void SerializeValueTupleTo<T1, T2, T3, T4, T5>(TupleWriter writer, (T1, T2, T3, T4, T5) tuple)
Serializes a tuple with 5 elements
static void SerializeValueTupleTo<T1, T2, T3, T4, T5, T6>(TupleWriter writer, (T1, T2, T3, T4, T5, T6) tuple)
Serializes a tuple with 6 elements
static void SerializeValueTupleTo<T1, T2, T3, T4, T5, T6, T7>(TupleWriter writer, (T1, T2, T3, T4, T5, T6, T7) tuple)
Serializes a tuple with 7 elements
static void SerializeValueTupleTo<T1, T2, T3, T4, T5, T6, T7, T8>(TupleWriter writer, (T1, T2, T3, T4, T5, T6, T7, (T8)) tuple)
Serializes a tuple with 8 elements
SerializeVarTupleTo
static void SerializeVarTupleTo<TTuple>(TupleWriter writer, TTuple tuple)
Serializes an embedded tuples
StringifyBoxedTo
static void StringifyBoxedTo(ref FastStringBuilder sb, ReadOnlySpan<byte> slice)
Deserializes a packed element into an object by choosing the most appropriate type at runtime
sb— Destination bufferslice— Slice that contains a single packed element
Returns: Decoded element, in the type that is the best fit.
You should avoid working with untyped values as much as possible! Blindly casting the returned object may be problematic because this method may need to return very large integers as Int64 or even UInt64.
TryDeserializeBigInteger
static bool TryDeserializeBigInteger(ReadOnlySpan<byte> slice, out BigInteger value)
Deserialize a tuple segment into a BigInteger
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeDouble
static bool TryDeserializeDouble(ReadOnlySpan<byte> slice, out double value)
Deserialize a tuple segment into a Double
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeGuid
static bool TryDeserializeGuid(ReadOnlySpan<byte> slice, out Guid value)
Deserializes a tuple segment into a Guid
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeInt64
static bool TryDeserializeInt64(ReadOnlySpan<byte> slice, out long value)
Deserializes a tuple segment into an Int64, if possible
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeSingle
static bool TryDeserializeSingle(ReadOnlySpan<byte> slice, out float value)
Deserializes a tuple segment into a Single
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeSlice
static bool TryDeserializeSlice(ReadOnlySpan<byte> slice, out Slice value)
Deserializes a tuple segment into a Slice
TryDeserializeString
static bool TryDeserializeString(ReadOnlySpan<byte> slice, out string value)
Deserializes a tuple segment into a Unicode string
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeTuple
static bool TryDeserializeTuple(ReadOnlySpan<byte> slice, out SpanTuple value)
Deserializes a tuple segment into a tuple
TryDeserializeUInt64
static bool TryDeserializeUInt64(ReadOnlySpan<byte> slice, out ulong value)
Deserializes a tuple segment into an UInt64
slice— Slice that contains a single packed elementvalue— Corresponding value
TryDeserializeUuid64
static bool TryDeserializeUuid64(ReadOnlySpan<byte> slice, out Uuid64 value)
Deserializes a tuple segment into 64-bit UUID
slice— Slice that contains a single packed elementvalue— Corresponding value
TrySerializeNullableTo
static bool TrySerializeNullableTo<T>(ref TupleSpanWriter writer, in T? value)
Serialize a nullable value, by checking for null at runtime
writer— Target buffervalue— Nullable value to serialize
Uses the underlying type's serializer if the value is not null
TrySerializeObjectTo
static bool TrySerializeObjectTo(ref TupleSpanWriter writer, in object value)
Serialize an untyped object, by checking its type at runtime [VERY SLOW]
writer— Target buffervalue— Untyped value whose type will be inspected at runtime
May throw at runtime if the type is not supported. This method will be very slow! Please consider using typed tuples instead!
TrySerializePackableItemsTo
static bool TrySerializePackableItemsTo<T>(ref TupleSpanWriter writer, in T value)
Serialize a nullable value, by checking for null at runtime
writer— Target buffervalue— Nullable value to serialize
Uses the underlying type's serializer if the value is not null
TrySerializePackableTupleTo
static bool TrySerializePackableTupleTo<TTuple>(ref TupleSpanWriter writer, in TTuple tuple)
Serialize a packable tuple
writer— Target buffertuple— Tuple to pack
TrySerializeValueTupleTo
static bool TrySerializeValueTupleTo<T1>(ref TupleSpanWriter writer, in (T1) tuple)
Serializes a tuple with a single element
static bool TrySerializeValueTupleTo<T1, T2>(ref TupleSpanWriter writer, in (T1, T2) tuple)
Serializes a tuple with 2 elements
static bool TrySerializeValueTupleTo<T1, T2, T3>(ref TupleSpanWriter writer, in (T1, T2, T3) tuple)
Serializes a tuple with 3 elements
static bool TrySerializeValueTupleTo<T1, T2, T3, T4>(ref TupleSpanWriter writer, in (T1, T2, T3, T4) tuple)
Serializes a tuple with 4 elements
static bool TrySerializeValueTupleTo<T1, T2, T3, T4, T5>(ref TupleSpanWriter writer, in (T1, T2, T3, T4, T5) tuple)
Serializes a tuple with 5 elements
static bool TrySerializeValueTupleTo<T1, T2, T3, T4, T5, T6>(ref TupleSpanWriter writer, in (T1, T2, T3, T4, T5, T6) tuple)
Serializes a tuple with 6 elements
static bool TrySerializeValueTupleTo<T1, T2, T3, T4, T5, T6, T7>(ref TupleSpanWriter writer, in (T1, T2, T3, T4, T5, T6, T7) tuple)
Serializes a tuple with 7 elements
static bool TrySerializeValueTupleTo<T1, T2, T3, T4, T5, T6, T7, T8>(ref TupleSpanWriter writer, in (T1, T2, T3, T4, T5, T6, T7, (T8)) tuple)
Serializes a tuple with 8 elements
TrySerializeVarTupleTo
static bool TrySerializeVarTupleTo<TTuple>(ref TupleSpanWriter writer, in TTuple tuple)
Serializes an embedded tuples
TryUnpackFirst
static bool TryUnpackFirst(ReadOnlySpan<byte> buffer, Span<Range> tokens, int? expectedSize, out Exception error)
Only returns the first N items of a packed tuple, without deserializing them.
buffer— Slice that contains the packed representation of a tuple with at least 3 elementstokens— Raw slice corresponding to the third element from the end of the tupleexpectedSize— If notnull, verifies that the tuple has the expected sizeerror— Receives an exception if the parsing failed
Returns: true if the buffer was successfully parsed and has the expected size
If is , this will not attempt to decode the rest of the tuple and will not observe any invalid or corrupted data.
TryUnpackLast
static bool TryUnpackLast(ReadOnlySpan<byte> buffer, Span<Range> tokens, int? expectedSize, out Exception error)
Only returns the last N items of a packed tuple, without decoding them.
buffer— Slice that contains the packed representation of a tuple with at least 3 elementstokens— Array that will receive the last N raw slice corresponding to each of the last N elementsexpectedSize— If notnull, verifies that the tuple has the expected sizeerror— Receive an exception if the parsing failed
Returns: true if the buffer was successfully parsed and has the expected size
TryUnpackSingle
static bool TryUnpackSingle(ReadOnlySpan<byte> buffer, out Range token)
Ensure that a slice is a packed tuple that contains a single and valid element
buffer— Slice that should contain the packed representation of a singleton tupletoken— Position of the decoded slice in the buffer