SlicedTuple
Namespace: SnowBank.Data.Tuples.Binary · class
Implements: IVarTuple, IEquatable<IVarTuple>, IComparable<IVarTuple>, IReadOnlyList<object>, IEnumerable<object>, IEnumerable, IReadOnlyCollection<object>, IStructuralEquatable, IStructuralComparable, ITuple, IFormattable, IEquatable<SlicedTuple>, IComparable<SlicedTuple>, IComparable, ITupleSpanPackable, ITuplePackable, ITupleFormattable, ISliceSerializable
Lazily-evaluated tuple that was unpacked from a key
Constructors
SlicedTuple
SlicedTuple(ReadOnlyMemory<Slice> slices)
Properties
Count
int Count { get; }
Item
object Item { get; }
SlicedTuple Item { get; }
object Item { get; }
SlicedTuple Item { get; }
Methods
AppendItemsTo
int AppendItemsTo(ref FastStringBuilder sb)
Writes the string representation of the items of this tuple
sb— Output buffer
Returns: Number of items written
This method should not emit any "(" or ")" delimiters, but should insert ", " separators between items
CompareTo
int CompareTo(SlicedTuple other)
int CompareTo(IVarTuple other)
int CompareTo(object other)
CopyTo
void CopyTo(Span<object> destination)
void CopyTo(Span<Slice> destination)
void CopyTo(object[] array, int offset)
Copies all items of the tuple into an array at a specific location.
array— The destination array, which must be large enough to contain all the items.offset— The offset at which to start copying items.
var tmp = new object[3];
("Hello", "World", 123).CopyTo(tmp, 0);
Equals
bool Equals(object obj)
bool Equals(IVarTuple other)
bool Equals(SlicedTuple other)
Get
T Get<T>(int index)
Returns the typed value of an item of the tuple, given its position
index— Position of the item
Returns: Value of the item at position index, adapted into type TItem.
STuple.Create("Hello", "World", 123,).Get<string>(0) => "Hello"STuple.Create("Hello", "World", 123,).Get<int>(2) => 123STuple.Create("Hello", "World", 123,).Get<string>(2) => "123"
T Get<T>(Index index)
Returns the typed value of an item of the tuple, given its position
index— Position of the item, with0for the first element, and^1for the last element
Returns: Value of the item at position index, adapted into type T.
("Hello", "World", 123,).Get<string>(^3) => "Hello"
("Hello", "World", 123,).Get<string>(^2) => "World"
("Hello", "World", 123,).Get<int>(^1) => 123
("Hello", "World", 123,).Get<string>(^1) => "123"
GetElementType
TupleSegmentType GetElementType(int index)
Returns the encoded type of the element at the specified index
Returns: This helps test if a parser element is a string, a number, a boolean, etc...
TupleSegmentType GetElementType(Index index)
Returns the encoded type of the element at the specified index
GetEnumerator
IEnumerator<object> GetEnumerator()
GetFirst
T GetFirst<T>()
Returns the typed value of the first item in this tuple
Returns: Value of the item at the first position, adapted into type T.
("Hello", "World").First<string>() => "Hello"
(123, 456).First<int>() => 123
(123, 456).First<string>() => "123"
GetHashCode
int GetHashCode()
GetLast
T GetLast<T>()
Returns the typed value of the last item of the tuple
Returns: Value of the item at the last position, adapted into type T.
("Hello",).Last<string>() => "Hello"
(123, 456).Last<int>() => 456
(123, 456).Last<string>() => "456"
GetSlice
Slice GetSlice(int index)
Return the encoded binary representation of the element at the specified index
Slice GetSlice(Index index)
Return the encoded binary representation of the element at the specified index
GetSpan
ReadOnlySpan<byte> GetSpan(int index)
Return the encoded binary representation of the element at the specified index
ReadOnlySpan<byte> GetSpan(Index index)
Return the encoded binary representation of the element at the specified index
IsBigInteger
bool IsBigInteger(int index)
Tests if the element at the specified index is a BigInteger
IsBoolean
bool IsBoolean(int index)
Tests if the element at the specified index is a Boolean
IsBytes
bool IsBytes(int index)
Tests if the element at the specified index is a ByteString
Returns: true if this the value is a byte string
This could either be an array of bytes, OR a non-unicode Python string
IsBytesOrDefault
bool IsBytesOrDefault(int index)
Tests if the element at the specified index is either a ByteString or a Nil
Returns: true if this the value is either a byte string, or null
This could either be an array of bytes, OR a non-unicode Python string
IsDecimal
bool IsDecimal(int index)
Tests if the element at the specified index is a Decimal
IsDouble
bool IsDouble(int index)
Tests if the element at the specified index is a Double
IsFloatingPoint
bool IsFloatingPoint(int index)
Tests if the element at the specified index is any of the floating points types (Single, Double, Triple or Decimal)
IsInteger
bool IsInteger(int index)
Tests if the element at the specified index is an Integer
Floating points numbers (, , ...) or Big Integers (, ...) are not in this category
IsNil
bool IsNil(int index)
Tests if the element at the specified index is Nil
Returns: true if this the value is either a byte string, or null
IsNumber
bool IsNumber(int index)
Tests if the element at the specified index is a number of any type (integer, floating point or big integer)
IsSingle
bool IsSingle(int index)
Tests if the element at the specified index is a Single
IsUnicodeString
bool IsUnicodeString(int index)
Tests if the element at the specified index is a UnicodeString
Returns: true if this the value is either a unicode string
IsUnicodeStringOrDefault
bool IsUnicodeStringOrDefault(int index)
Tests if the element at the specified index is either a UnicodeString or a Nil
Returns: true if this the value is either a unicode string, or null
IsUserType
bool IsUserType(int index)
Tests if the element at the specified index is a reserved custom type code (application specific)
Repack
static SlicedTuple Repack<TTuple>(in TTuple tuple)
Transcode a tuple into the equivalent tuple, but backed by a SlicedTuple
This methods can be useful to examine what the result of packing a tuple would be, after a round-trip to the database.
ToSlice
Slice ToSlice()
Return the original serialized key blob that is equivalent to this tuple
Returns: Packed tuple
SlicedTuple.Unpack(bytes).ToSlice() == bytes
ToString
string ToString()
Returns a human-readable representation of this tuple
void ToString(ref FastStringBuilder sb)
string ToString(string format, IFormatProvider provider = null)
Returns a human-readable representation of this tuple
TryCopyTo
bool TryCopyTo(Span<object> destination)
bool TryCopyTo(Span<Slice> destination)
TryGetSizeHint
bool TryGetSizeHint(bool embedded, out int sizeHint)
Attempts to quickly estimate the minimum buffer capacity required to pack this tuple
embedded—trueif this is an embedded tuple,falseif this is the top-levelsizeHint— Receives the estimated size, or0
Returns: true if the capacity could be quickly estimated, or false if it would require almost as much work as encoding the tuple.
The result MUST include the start/stop bytes for embedded tuples (which will be accounted by the parent)
TryPackTo
bool TryPackTo(ref TupleSpanWriter writer)
Appends the packed bytes of this instance to the end of a buffer, if it is large enough
writer— Buffer that will receive the packed bytes of this instance
true if the operation was successful, or false if it was too small
TryUnpack
static bool TryUnpack(Slice packedKey, out SlicedTuple tuple)
Unpack a tuple from a serialized key blob
packedKey— Binary key containing a previously packed tupletuple— Unpacked tuple, or the empty tuple if the key is Empty
This is the same as Unpack, except that it will expose the concrete type SlicedTuple instead of the IVarTuple interface.
Unpack
static SlicedTuple Unpack(Slice packedKey)
Unpack a tuple from a serialized key blob
packedKey— Binary key containing a previously packed tuple
Returns: Unpacked tuple, or the empty tuple if the key is Empty
This is the same as Unpack, except that it will expose the concrete type SlicedTuple instead of the IVarTuple interface.
WriteTo
void WriteTo(ref SliceWriter writer)
Serializes the current instance to the specified output buffer
Fields
Empty
static readonly SlicedTuple Empty