Table of Contents

Struct SliceDecoder

Namespace
ZeroC.Slice
Assembly
ZeroC.Slice.dll

Provides methods to decode data encoded with Slice.

public ref struct SliceDecoder
Inherited Members
Extension Methods

Constructors

SliceDecoder(ReadOnlySequence<byte>, SliceEncoding, object?, int, IActivator?, int)

Constructs a new Slice decoder over a byte buffer.

public SliceDecoder(ReadOnlySequence<byte> buffer, SliceEncoding encoding, object? decodingContext = null, int maxCollectionAllocation = -1, IActivator? activator = null, int maxDepth = 3)

Parameters

buffer ReadOnlySequence<byte>

The byte buffer.

encoding SliceEncoding

The Slice encoding version.

decodingContext object

The decoding context.

maxCollectionAllocation int

The maximum cumulative allocation in bytes when decoding strings, sequences, and dictionaries from this buffer.-1 (the default) is equivalent to 8 times the buffer length.

activator IActivator

The activator for decoding Slice1-encoded classes and exceptions.

maxDepth int

The maximum depth when decoding a class recursively. The default is 3.

SliceDecoder(ReadOnlyMemory<byte>, SliceEncoding, object?, int, IActivator?, int)

Constructs a new Slice decoder over a byte buffer.

public SliceDecoder(ReadOnlyMemory<byte> buffer, SliceEncoding encoding, object? decodingContext = null, int maxCollectionAllocation = -1, IActivator? activator = null, int maxDepth = 3)

Parameters

buffer ReadOnlyMemory<byte>

The byte buffer.

encoding SliceEncoding

The Slice encoding version.

decodingContext object

The decoding context.

maxCollectionAllocation int

The maximum cumulative allocation in bytes when decoding strings, sequences, and dictionaries from this buffer.-1 (the default) is equivalent to 8 times the buffer length.

activator IActivator

The activator for decoding Slice1-encoded classes and exceptions.

maxDepth int

The maximum depth when decoding a class recursively. The default is 3.

Properties

Consumed

Gets the number of bytes decoded in the underlying buffer.

public readonly long Consumed { get; }

Property Value

long

DecodingContext

Gets the decoding context.

public readonly object? DecodingContext { get; }

Property Value

object

Remarks

The decoding context is a kind of cookie: the code that creates the decoder can store this context in the decoder for later retrieval.

Encoding

Gets the Slice encoding decoded by this decoder.

public readonly SliceEncoding Encoding { get; }

Property Value

SliceEncoding

End

Gets a value indicating whether this decoder has reached the end of its underlying buffer.

public readonly bool End { get; }

Property Value

bool

true when this decoder has reached the end of its underlying buffer; otherwise false.

Remaining

Gets the number of bytes remaining in the underlying buffer.

public readonly long Remaining { get; }

Property Value

long

The number of bytes remaining in the underlying buffer.

Methods

CheckBoolValue(bool)

Checks if the in memory representation of the bool value is valid according to the Slice encoding.

public static void CheckBoolValue(bool value)

Parameters

value bool

The value to check.

Exceptions

InvalidDataException

If the value is out of the bool type accepted range.

CopyTo(IBufferWriter<byte>)

Copy all bytes from the underlying reader into the destination buffer writer.

public void CopyTo(IBufferWriter<byte> destination)

Parameters

destination IBufferWriter<byte>

The destination buffer writer.

Remarks

This method also moves the reader's Consumed property.

CopyTo(Span<byte>)

Copy bytes from the underlying reader into the destination to fill completely destination.

public void CopyTo(Span<byte> destination)

Parameters

destination Span<byte>

The span to which bytes of this decoder will be copied.

Remarks

This method also moves the reader's Consumed property.

DecodeBool()

Decodes a slice bool into a bool.

public bool DecodeBool()

Returns

bool

The bool decoded by this decoder.

DecodeClass<T>()

Decodes a class instance.

public T DecodeClass<T>() where T : SliceClass

Returns

T

The decoded class instance.

Type Parameters

T

The class type.

DecodeException(string?)

Decodes a Slice exception.

public SliceException DecodeException(string? message = null)

Parameters

message string

The error message.

Returns

SliceException

The decoded Slice exception.

DecodeFloat32()

Decodes a Slice float32 into a float.

public float DecodeFloat32()

Returns

float

The float decoded by this decoder.

DecodeFloat64()

Decodes a Slice float64 into a double.

public double DecodeFloat64()

Returns

double

The double decoded by this decoder.

DecodeInt16()

Decodes a Slice int16 into a short.

public short DecodeInt16()

Returns

short

The short decoded by this decoder.

DecodeInt32()

Decodes a Slice int32 into an int.

public int DecodeInt32()

Returns

int

The int decoded by this decoder.

DecodeInt64()

Decodes a Slice int64 into a long.

public long DecodeInt64()

Returns

long

The long decoded by this decoder.

DecodeInt8()

Decodes a Slice int8 into an sbyte.

public sbyte DecodeInt8()

Returns

sbyte

The sbyte decoded by this decoder.

DecodeNullableClass<T>()

Decodes a nullable class instance.

public T? DecodeNullableClass<T>() where T : class

Returns

T

The class instance, or null.

Type Parameters

T

The class type.

DecodeSize()

Decodes a size encoded on a variable number of bytes.

public int DecodeSize()

Returns

int

The size decoded by this decoder.

DecodeString()

Decodes a Slice string into a string.

public string DecodeString()

Returns

string

The string decoded by this decoder.

DecodeTagged<T>(int, DecodeFunc<T>)

Decodes a Slice2-encoded tagged field.

public T? DecodeTagged<T>(int tag, DecodeFunc<T> decodeFunc)

Parameters

tag int

The tag.

decodeFunc DecodeFunc<T>

A decode function that decodes the value of this tagged field.

Returns

T

The decoded value of the tagged field, or null if not found.

Type Parameters

T

The type of the decoded value.

Remarks

We return a T? and not a T to avoid ambiguities in the generated code with nullable reference types such as string?.

DecodeTagged<T>(int, TagFormat, DecodeFunc<T>, bool)

Decodes a Slice1-encoded tagged field.

public T? DecodeTagged<T>(int tag, TagFormat tagFormat, DecodeFunc<T> decodeFunc, bool useTagEndMarker)

Parameters

tag int

The tag.

tagFormat TagFormat

The expected tag format of this tag when found in the underlying buffer.

decodeFunc DecodeFunc<T>

A decode function that decodes the value of this tag.

useTagEndMarker bool

When true, a tag end marker marks the end of the tagged fields. When false, the end of the buffer marks the end of the tagged fields.

Returns

T

The decoded value of the tagged field, or null if not found.

Type Parameters

T

The type of the decoded value.

Remarks

We return a T? and not a T to avoid ambiguities in the generated code with nullable reference types such as string?.

DecodeUInt16()

Decodes a Slice uint16 into a ushort.

public ushort DecodeUInt16()

Returns

ushort

The ushort decoded by this decoder.

DecodeUInt32()

Decodes a Slice uint32 into a uint.

public uint DecodeUInt32()

Returns

uint

The uint decoded by this decoder.

DecodeUInt64()

Decodes a Slice uint64 into a ulong.

public ulong DecodeUInt64()

Returns

ulong

The ulong decoded by this decoder.

DecodeUInt8()

Decodes a Slice uint8 into a byte.

public byte DecodeUInt8()

Returns

byte

The byte decoded by this decoder.

DecodeVarInt32()

Decodes a Slice varint32 into an int.

public int DecodeVarInt32()

Returns

int

The int decoded by this decoder.

DecodeVarInt62()

Decodes a Slice varint62 into a long.

public long DecodeVarInt62()

Returns

long

The long decoded by this decoder.

DecodeVarUInt32()

Decodes a Slice varuint32 into a uint.

public uint DecodeVarUInt32()

Returns

uint

The uint decoded by this decoder.

DecodeVarUInt62()

Decodes a Slice varuint62 into a ulong.

public ulong DecodeVarUInt62()

Returns

ulong

The ulong decoded by this decoder.

GetBitSequenceReader(int)

Gets a bit sequence reader to read the underlying bit sequence later on.

public BitSequenceReader GetBitSequenceReader(int bitSequenceSize)

Parameters

bitSequenceSize int

The minimum number of bits in the sequence.

Returns

BitSequenceReader

A bit sequence reader.

IncreaseCollectionAllocation(int)

Increases the number of bytes in the decoder's collection allocation.

public void IncreaseCollectionAllocation(int byteCount)

Parameters

byteCount int

The number of bytes to add.

Exceptions

InvalidDataException

Thrown when the total number of bytes exceeds the max collection allocation.

See Also

Skip(int)

Skip the given number of bytes.

public void Skip(int count)

Parameters

count int

The number of bytes to skip.

SkipSize()

Skip Slice size.

public void SkipSize()

SkipTagged(bool)

Skips the remaining tagged fields.

public void SkipTagged(bool useTagEndMarker = true)

Parameters

useTagEndMarker bool

Whether or not the tagged fields use a tag end marker (Slice1 only).

TryDecodeUInt8(out byte)

Tries to decode a Slice uint8 into a byte.

public bool TryDecodeUInt8(out byte value)

Parameters

value byte

When this method returns true, this value is set to the decoded byte. Otherwise, this value is set to its default value.

Returns

bool

true if the decoder is not at the end of the buffer and the decode operation succeeded; otherwise, false.

TryDecodeVarUInt62(out ulong)

Tries to decode a Slice varuint62 into a ulong.

public bool TryDecodeVarUInt62(out ulong value)

Parameters

value ulong

When this method returns true, this value is set to the decoded ulong. Otherwise, this value is set to its default value.

Returns

bool

true if the decoder is not at the end of the buffer and the decode operation succeeded; otherwise, false.