Struct IceEncoder
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
bufferWriterIBufferWriter<byte>A buffer writer that writes to byte buffers. See important remarks below.
classFormatClassFormatThe 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
Methods
EncodeBool(bool)
Encodes a bool into an Ice bool.
public void EncodeBool(bool v)
Parameters
vboolThe boolean to encode.
EncodeByte(byte)
Encodes a byte into an Ice byte.
public void EncodeByte(byte v)
Parameters
vbyteThe byte to encode.
EncodeClass(IceClass?)
Encodes a class instance, or null.
public void EncodeClass(IceClass? v)
Parameters
EncodeDouble(double)
Encodes a double into an Ice double.
public void EncodeDouble(double v)
Parameters
vdoubleThe double to encode.
EncodeFloat(float)
Encodes a float into an Ice float.
public void EncodeFloat(float v)
Parameters
vfloatThe float to encode.
EncodeInt(int)
Encodes an int into an Ice int.
public void EncodeInt(int v)
Parameters
vintThe 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
valueintThe value to encode.
intoSpan<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
vlongThe long to encode.
EncodeShort(short)
Encodes a short into an Ice short.
public void EncodeShort(short v)
Parameters
vshortThe short to encode.
EncodeSize(int)
Encodes a size on variable number of bytes.
public void EncodeSize(int value)
Parameters
valueintThe size to encode.
EncodeString(string)
Encodes a string into an Ice string.
public void EncodeString(string v)
Parameters
vstringThe 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
tagintThe tag. Must be either FSize or OptimizedVSize.
tagFormatTagFormatThe tag format.
vTThe value to encode.
encodeActionEncodeAction<T>The delegate that encodes the value after the tag header.
Type Parameters
TThe type of the value being encoded.
Exceptions
- ArgumentException
Thrown if
tagFormatis 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
tagintThe tag.
sizeintThe number of bytes needed to encode the value.
vTThe value to encode.
encodeActionEncodeAction<T>The delegate that encodes the value after the tag header.
Type Parameters
TThe type of the value being encoded.
GetPlaceholderSpan(int)
Gets a placeholder to be filled-in later.
public Span<byte> GetPlaceholderSpan(int size)
Parameters
sizeintThe size of the placeholder, typically a small number like 4.
Returns
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
sizeintThe 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
spanReadOnlySpan<byte>The span to copy.