Class SliceDecoderExtensions
Provides extension methods for SliceDecoder to decode dictionaries, results, and sequences.
public static class SliceDecoderExtensions
- Inheritance
-
SliceDecoderExtensions
- Inherited Members
Methods
CheckEndOfBuffer(ref SliceDecoder)
Verifies the Slice decoder has reached the end of its underlying buffer.
public static void CheckEndOfBuffer(this ref SliceDecoder decoder)
Parameters
decoderSliceDecoderThe Slice decoder.
DecodeDictionaryWithOptionalValueType<TDictionary, TKey, TValue>(ref SliceDecoder, Func<int, TDictionary>, DecodeFunc<TKey>, DecodeFunc<TValue?>)
Decodes a dictionary with an optional value type (T? in Slice).
public static TDictionary DecodeDictionaryWithOptionalValueType<TDictionary, TKey, TValue>(this ref SliceDecoder decoder, Func<int, TDictionary> dictionaryFactory, DecodeFunc<TKey> keyDecodeFunc, DecodeFunc<TValue?> valueDecodeFunc) where TDictionary : IDictionary<TKey, TValue?> where TKey : notnull
Parameters
decoderSliceDecoderThe Slice decoder.
dictionaryFactoryFunc<int, TDictionary>The factory for creating the dictionary instance.
keyDecodeFuncDecodeFunc<TKey>The decode function for each key of the dictionary.
valueDecodeFuncDecodeFunc<TValue>The decode function for each non-null value of the dictionary.
Returns
- TDictionary
The dictionary decoded by this decoder.
Type Parameters
TDictionaryThe type of the returned dictionary.
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
DecodeDictionary<TDictionary, TKey, TValue>(ref SliceDecoder, Func<int, TDictionary>, DecodeFunc<TKey>, DecodeFunc<TValue>)
Decodes a dictionary.
public static TDictionary DecodeDictionary<TDictionary, TKey, TValue>(this ref SliceDecoder decoder, Func<int, TDictionary> dictionaryFactory, DecodeFunc<TKey> keyDecodeFunc, DecodeFunc<TValue> valueDecodeFunc) where TDictionary : IDictionary<TKey, TValue> where TKey : notnull
Parameters
decoderSliceDecoderThe Slice decoder.
dictionaryFactoryFunc<int, TDictionary>The factory for creating the dictionary instance.
keyDecodeFuncDecodeFunc<TKey>The decode function for each key of the dictionary.
valueDecodeFuncDecodeFunc<TValue>The decode function for each value of the dictionary.
Returns
- TDictionary
The dictionary decoded by this decoder.
Type Parameters
TDictionaryThe type of the returned dictionary.
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
DecodeResult<TSuccess, TFailure>(ref SliceDecoder, DecodeFunc<TSuccess>, DecodeFunc<TFailure>)
Decodes a result.
public static Result<TSuccess, TFailure> DecodeResult<TSuccess, TFailure>(this ref SliceDecoder decoder, DecodeFunc<TSuccess> successDecodeFunc, DecodeFunc<TFailure> failureDecodeFunc)
Parameters
decoderSliceDecoderThe Slice decoder.
successDecodeFuncDecodeFunc<TSuccess>The decode function for the success type.
failureDecodeFuncDecodeFunc<TFailure>The decode function for the failure type.
Returns
- Result<TSuccess, TFailure>
The decoded result.
Type Parameters
TSuccessThe type of the success value.
TFailureThe type of the failure value.
DecodeSequenceOfOptionals<T>(ref SliceDecoder, DecodeFunc<T>)
Decodes a sequence where the element type is an optional Slice type (T?).
public static T?[] DecodeSequenceOfOptionals<T>(this ref SliceDecoder decoder, DecodeFunc<T> decodeFunc)
Parameters
decoderSliceDecoderThe Slice decoder.
decodeFuncDecodeFunc<T>The decode function for each non-null element of the sequence.
Returns
- T[]
An array of T.
Type Parameters
TThe type of the elements in the array.
Remarks
We return a T? and not a T to avoid ambiguities in the generated code with nullable reference types such as string?.
DecodeSequenceOfOptionals<TSequence, TElement>(ref SliceDecoder, Func<int, TSequence>, DecodeFunc<TElement>)
Decodes a sequence where the element type is an optional Slice type (T?).
public static TSequence DecodeSequenceOfOptionals<TSequence, TElement>(this ref SliceDecoder decoder, Func<int, TSequence> sequenceFactory, DecodeFunc<TElement> decodeFunc) where TSequence : ICollection<TElement>
Parameters
decoderSliceDecoderThe Slice decoder.
sequenceFactoryFunc<int, TSequence>The factory for creating the sequence instance.
decodeFuncDecodeFunc<TElement>The decode function for each non-null element of the sequence.
Returns
- TSequence
A TSequence.
Type Parameters
TSequenceThe type of the returned sequence.
TElementThe type of the elements in the sequence.
DecodeSequence<T>(ref SliceDecoder, Action<T>?)
Decodes a sequence of fixed-size numeric values.
public static T[] DecodeSequence<T>(this ref SliceDecoder decoder, Action<T>? checkElement = null) where T : struct
Parameters
decoderSliceDecoderThe Slice decoder.
checkElementAction<T>A delegate used to check each element of the array (optional).
Returns
- T[]
An array of T.
Type Parameters
TThe sequence element type.
DecodeSequence<T>(ref SliceDecoder, DecodeFunc<T>)
Decodes a sequence.
public static T[] DecodeSequence<T>(this ref SliceDecoder decoder, DecodeFunc<T> decodeFunc) where T : notnull
Parameters
decoderSliceDecoderThe Slice decoder.
decodeFuncDecodeFunc<T>The decode function for each element of the sequence.
Returns
- T[]
An array of T.
Type Parameters
TThe type of the elements in the array.
DecodeSequence<TSequence, TElement>(ref SliceDecoder, Func<int, TSequence>, DecodeFunc<TElement>)
Decodes a sequence.
public static TSequence DecodeSequence<TSequence, TElement>(this ref SliceDecoder decoder, Func<int, TSequence> sequenceFactory, DecodeFunc<TElement> decodeFunc) where TSequence : ICollection<TElement> where TElement : notnull
Parameters
decoderSliceDecoderThe Slice decoder.
sequenceFactoryFunc<int, TSequence>The factory for creating the sequence instance.
decodeFuncDecodeFunc<TElement>The decode function for each element of the sequence.
Returns
- TSequence
A TSequence.
Type Parameters
TSequenceThe type of the returned sequence.
TElementThe type of the elements in the sequence.