Table of Contents

Struct IceEncoder

Namespace
IceRpc.Ice.Codec
Assembly
IceRpc.dll

Provides methods to encode data with Ice.

public ref struct IceEncoder
Inherited Members
Extension Methods

Constructors

IceEncoder(IBufferWriter<byte>, ClassFormat)

Constructs an Ice encoder.

public IceEncoder(IBufferWriter<byte> bufferWriter, ClassFormat classFormat = ClassFormat.Compact)

Parameters

bufferWriter IBufferWriter<byte>

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

classFormat ClassFormat

The class format.

Remarks

Warning: the Ice 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 an Ice bool.

public void EncodeBool(bool v)

Parameters

v bool

The boolean to encode.

EncodeByte(byte)

Encodes a byte into an Ice byte.

public void EncodeByte(byte v)

Parameters

v byte

The byte to encode.

EncodeClass(IceClass?)

Encodes a class instance, or null.

public void EncodeClass(IceClass? v)

Parameters

v IceClass

The class instance to encode, or null.

EncodeDouble(double)

Encodes a double into an Ice double.

public void EncodeDouble(double v)

Parameters

v double

The double to encode.

EncodeFloat(float)

Encodes a float into an Ice float.

public void EncodeFloat(float v)

Parameters

v float

The float to encode.

EncodeInt(int)

Encodes an int into an Ice int.

public void EncodeInt(int v)

Parameters

v int

The int to encode.

EncodeInt(int, Span<byte>)

Encodes an int as an Ice int into a span of 4 bytes.

public static void EncodeInt(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.

EncodeLong(long)

Encodes a long into an Ice long.

public void EncodeLong(long v)

Parameters

v long

The long to encode.

EncodeShort(short)

Encodes a short into an Ice short.

public void EncodeShort(short v)

Parameters

v short

The short 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 an Ice string.

public void EncodeString(string v)

Parameters

v string

The string to encode.

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

Encodes a tagged value. The number of bytes needed to encode the value is not known before encoding this value. T can be a proxy such as IceObjectProxy? and therefore nullable.

public void EncodeTagged<T>(int tag, TagFormat tagFormat, T v, EncodeAction<T> encodeAction)

Parameters

tag int

The tag. Must be either FSize or OptimizedVSize.

tagFormat TagFormat

The tag format.

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.

Exceptions

ArgumentException

Thrown if tagFormat is VSize.

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. This method always use the VSize tag format.

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.

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.

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.