Class BinaryWriterExtensions
Inheritance
Namespace: Eco.Shared.Utils.Binary
Assembly: Eco.Shared.dll
Syntax
public static class BinaryWriterExtensions : Object
Methods
AppendBoolToInt(Int32, Boolean)
In c# bool takes 8 bits. It means there is excess of 7 bits. It can be improved by encoding it as a part of some existing int, so it would take only 1 bit. This method shifts all bits to the left and writes bool value in the last bit.
Declaration
public static int AppendBoolToInt(this int value, bool boolVal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | |
System.Boolean | boolVal |
Returns
Type | Description |
---|---|
System.Int32 |
EncodeVariableLength(BinaryWriter, Int32)
Encodes a signed integer using variable number of bytes, depending on the actual value of the integer.
Declaration
public static void EncodeVariableLength(this BinaryWriter writer, int value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.Int32 | value |
Remarks
This method can end up encoding the integer using between 1 and 5 bytes.
EncodeVariableLength(BinaryWriter, Int64)
Encodes a signed integer using variable number of bytes, depending on the actual value of the integer.
Declaration
public static void EncodeVariableLength(this BinaryWriter writer, long value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.Int64 | value |
Remarks
This method can end up encoding the integer using between 1 and 10 bytes.
EncodeVariableLength(BinaryWriter, UInt32)
Encodes an unsigned integer using variable number of bytes, depending on the actual value of the integer.
Declaration
public static void EncodeVariableLength(this BinaryWriter writer, uint value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.UInt32 | value |
Remarks
This method can end up encoding the integer using between 1 and 5 bytes.
EncodeVariableLength(BinaryWriter, UInt64)
Encodes an unsigned integer using variable number of bytes, depending on the actual value of the integer.
Declaration
public static void EncodeVariableLength(this BinaryWriter writer, ulong value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.UInt64 | value |
Remarks
This method can end up encoding the integer using between 1 and 10 bytes.
ExtractBoolFromInt(Int32, out Boolean)
This does reverse of AppendBoolToInt(Int32, Boolean). It extracts bool value and returns original int.
Declaration
public static int ExtractBoolFromInt(this int value, out bool boolVal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | |
System.Boolean | boolVal |
Returns
Type | Description |
---|---|
System.Int32 |
GetZigZagLength(BinaryWriter, Int32)
Declaration
public static int GetZigZagLength(this BinaryWriter writer, int value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.Int32 | value |
Returns
Type | Description |
---|---|
System.Int32 |
ReplaceZigZag(BinaryWriter, Int32, Int32, Int32)
Replaces previously encoded oldValue
with newValue
at position
. To perform this operation writer
backing stream should be System.IO.MemoryStream.
Length of encoded number may be different, in this case data after encoded number will be shifted left or right.
Declaration
public static void ReplaceZigZag(this BinaryWriter writer, int position, int oldValue, int newValue)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.Int32 | position | |
System.Int32 | oldValue | |
System.Int32 | newValue |
WriteDictionary(BinaryWriter, Dictionary<String, String>)
Writes a string key,value Dictionary using a BinaryWriter
Declaration
public static void WriteDictionary(this BinaryWriter writer, Dictionary<string, string> dictionary)
Parameters
Type | Name | Description |
---|---|---|
System.IO.BinaryWriter | writer | |
System.Collections.Generic.Dictionary<System.String, System.String> | dictionary |