Class ByteArrayReader
Utility class to read structured data from byte array.
Inheritance
Namespace: Eco.Shared.Utils.Binary
Assembly: Eco.Shared.dll
Syntax
public static class ByteArrayReader : Object
Methods
ReadBoolean(Byte[], ref Int32)
[0 - false/1 - true:byte]
Reads a boolean value from byte array using provided offset
.
Declaration
public static bool ReadBoolean(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Boolean | decoded boolean value. |
ReadByte(Byte[], ref Int32)
Read a byte from byte array using provided offset.
Declaration
public static byte ReadByte(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Byte | decoded byte value. |
ReadDouble(Byte[], ref Int32)
Read a double value from data array. Always uses LittleEndian.
Declaration
public static double ReadDouble(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Double | decoded double value. |
ReadGuid(Byte[], ref Int32)
[guid:byte[16]]
Reads a Guid from byte array using provided offset
.
Declaration
public static Guid ReadGuid(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Guid | decoded Guid. |
ReadInt16(Byte[], ref Int32)
Read a short value from data array. Always uses LittleEndian.
Declaration
public static short ReadInt16(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Int16 | decoded short value. |
ReadInt32(Byte[], ref Int32)
Read a int value from data array. Always uses LittleEndian.
Declaration
public static int ReadInt32(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Int32 | decoded int value. |
ReadInt64(Byte[], ref Int32)
Read a long value from data array. Always uses LittleEndian.
Declaration
public static long ReadInt64(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Int64 | decoded long value. |
ReadIPEndPoint(Byte[], ref Int32)
[address length:byte][address bytes:byte array][port:ushort]
Reads a IP end point from byte array using provided offset
.
Declaration
public static IPEndPoint ReadIPEndPoint(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Net.IPEndPoint | decoded IP endpoint. |
ReadSingle(Byte[], ref Int32)
Read a float value from data array. Always uses LittleEndian.
Declaration
public static float ReadSingle(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Single | decoded float value. |
ReadString(Byte[], ref Int32)
[str len:zig zag uint][str:utf-8 encoded byte array]
Reads a string from byte array using provided offset
.
Declaration
public static string ReadString(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.String | decoded string. |
ReadUInt16(Byte[], ref Int32)
Read a ushort value from data array. Always uses LittleEndian.
Declaration
public static ushort ReadUInt16(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.UInt16 | decoded ushort value. |
ReadUInt32(Byte[], ref Int32)
Read a uint value from data array. Always uses LittleEndian.
Declaration
public static uint ReadUInt32(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.UInt32 | decoded uint value. |
ReadUInt32ZigZag(Byte[], ref Int32)
Read a unsigned int from data array zig zag encoded.
Declaration
public static uint ReadUInt32ZigZag(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.UInt32 | decoded unsigned int value. |
Exceptions
Type | Condition |
---|---|
System.Exception | if value can't be decoded from byte array. |
ReadVector3(Byte[], ref Int32)
Read a vector3 value from data array. Always uses LittleEndian.
Declaration
public static Vector3 ReadVector3(this byte[] data, ref int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | byte array. |
System.Int32 | offset | reference to offset, will be modified to next read position. |
Returns
Type | Description |
---|---|
System.Numerics.Vector3 | decoded float value. |