Table of Contents

Struct SliceEncoder

Namespace
ZeroC.Slice.Codec
Assembly
ZeroC.Slice.Codec.dll

Provides methods to encode data with Slice.

public ref struct SliceEncoder
Inherited Members
Extension Methods

Constructors

SliceEncoder(IBufferWriter<byte>)

Constructs a Slice encoder.

public SliceEncoder(IBufferWriter<byte> bufferWriter)

Parameters

bufferWriter IBufferWriter<byte>

A buffer writer that writes to byte buffers. See important remarks below.

Remarks

Warning: the Slice encoding requires rewriting buffers, and many buffer writers do not support this behavior. It is safe to use a pipe writer or a buffer writer that writes to a single fixed-size buffer (without reallocation).

Properties

EncodedByteCount

Gets the number of bytes encoded by this encoder into the underlying buffer writer.

public readonly int EncodedByteCount { get; }

Property Value

int

Methods

EncodeBool(bool)

Encodes a bool into a Slice bool.

public void EncodeBool(bool v)

Parameters

v bool

The boolean to encode.

EncodeFloat32(float)

Encodes a float into a Slice float32.

public void EncodeFloat32(float v)

Parameters

v float

The float to encode.

EncodeFloat64(double)

Encodes a double into a Slice float64.

public void EncodeFloat64(double v)

Parameters

v double

The double to encode.

EncodeInt16(short)

Encodes a short into a Slice int16.

public void EncodeInt16(short v)

Parameters

v short

The short to encode.

EncodeInt32(int)

Encodes an int into a Slice int32.

public void EncodeInt32(int v)

Parameters

v int

The int to encode.

EncodeInt32(int, Span<byte>)

Encodes an int as a Slice int32 into a span of 4 bytes.

public static void EncodeInt32(int value, Span<byte> into)

Parameters

value int

The value to encode.

into Span<byte>

The destination byte buffer, which must be 4 bytes long.

EncodeInt64(long)

Encodes a long into a Slice int64.

public void EncodeInt64(long v)

Parameters

v long

The long to encode.

EncodeInt8(sbyte)

Encodes an sbyte into a Slice int8.

public void EncodeInt8(sbyte v)

Parameters

v sbyte

The sbyte to encode.

EncodeSize(int)

Encodes a size on variable number of bytes.

public void EncodeSize(int value)

Parameters

value int

The size to encode.

EncodeString(string)

Encodes a string into a Slice string.

public void EncodeString(string v)

Parameters

v string

The string to encode.

EncodeTagged<T>(int, int, T, EncodeAction<T>)

Encodes a non-null tagged value. The number of bytes needed to encode the value is known before encoding the value.

public void EncodeTagged<T>(int tag, int size, T v, EncodeAction<T> encodeAction) where T : notnull

Parameters

tag int

The tag.

size int

The number of bytes needed to encode the value.

v T

The value to encode.

encodeAction EncodeAction<T>

The delegate that encodes the value after the tag header.

Type Parameters

T

The type of the value being encoded.

EncodeTagged<T>(int, T, EncodeAction<T>)

Encodes a non-null tagged value. The number of bytes needed to encode the value is not known before encoding this value.

public void EncodeTagged<T>(int tag, T v, EncodeAction<T> encodeAction) where T : notnull

Parameters

tag int

The tag.

v T

The value to encode.

encodeAction EncodeAction<T>

The delegate that encodes the value after the tag header.

Type Parameters

T

The type of the value being encoded.

EncodeUInt16(ushort)

Encodes a ushort into a Slice uint16.

public void EncodeUInt16(ushort v)

Parameters

v ushort

The ushort to encode.

EncodeUInt32(uint)

Encodes a uint into a Slice uint32.

public void EncodeUInt32(uint v)

Parameters

v uint

The uint to encode.

EncodeUInt64(ulong)

Encodes a ulong into a Slice uint64.

public void EncodeUInt64(ulong v)

Parameters

v ulong

The ulong to encode.

EncodeUInt8(byte)

Encodes a byte into a Slice uint8.

public void EncodeUInt8(byte v)

Parameters

v byte

The byte to encode.

EncodeVarInt32(int)

Encodes an int into a Slice varint32.

public void EncodeVarInt32(int v)

Parameters

v int

The int to encode.

EncodeVarInt62(long)

Encodes a long into a Slice varint62, with the minimum number of bytes required by the encoding.

public void EncodeVarInt62(long v)

Parameters

v long

The long to encode. It must be in the range [-2^61..2^61 - 1].

EncodeVarUInt32(uint)

Encodes a uint into a Slice varuint32.

public void EncodeVarUInt32(uint v)

Parameters

v uint

The uint to encode.

EncodeVarUInt62(ulong)

Encodes a ulong into a Slice varuint62, with the minimum number of bytes required by the encoding.

public void EncodeVarUInt62(ulong v)

Parameters

v ulong

The ulong to encode. It must be in the range [0..2^62 - 1].

EncodeVarUInt62(ulong, Span<byte>)

Encodes a ulong as a Slice varuint62 into a span of bytes using a fixed number of bytes.

public static void EncodeVarUInt62(ulong value, Span<byte> into)

Parameters

value ulong

The value to encode.

into Span<byte>

The destination byte buffer, which must be 1, 2, 4 or 8 bytes long.

GetBitSequenceWriter(int)

Allocates a new bit sequence in the underlying buffer(s) and returns a writer for this bit sequence.

public BitSequenceWriter GetBitSequenceWriter(int bitSequenceSize)

Parameters

bitSequenceSize int

The minimum number of bits in the bit sequence.

Returns

BitSequenceWriter

The bit sequence writer.

GetPlaceholderSpan(int)

Gets a placeholder to be filled-in later.

public Span<byte> GetPlaceholderSpan(int size)

Parameters

size int

The size of the placeholder, typically a small number like 4.

Returns

Span<byte>

A buffer of length size.

Remarks

We make the assumption the underlying buffer writer allows rewriting memory it provided even after successive calls to GetMemory/GetSpan and Advance.

GetSizeLength(int)

Computes the minimum number of bytes needed to encode a variable-length size.

public static int GetSizeLength(int size)

Parameters

size int

The size.

Returns

int

The minimum number of bytes.

GetVarInt62EncodedSize(long)

Computes the minimum number of bytes required to encode a long value using the Slice encoding's variable-size encoded representation.

public static int GetVarInt62EncodedSize(long value)

Parameters

value long

The long value.

Returns

int

The minimum number of bytes required to encode value. Can be 1, 2, 4 or 8.

GetVarUInt62EncodedSize(ulong)

Computes the minimum number of bytes required to encode a ulong value using the Slice encoding's variable-size encoded representation.

public static int GetVarUInt62EncodedSize(ulong value)

Parameters

value ulong

The ulong value.

Returns

int

The minimum number of bytes required to encode value. Can be 1, 2, 4 or 8.

WriteByteSpan(ReadOnlySpan<byte>)

Copies a span of bytes to the underlying buffer writer.

public void WriteByteSpan(ReadOnlySpan<byte> span)

Parameters

span ReadOnlySpan<byte>

The span to copy.