Class ByteSpanReader
Wraps System.ReadOnlySpan<> as source for binary data. When Read* operation used then it changes internal state and so you need to avoid copy this struct if you need to keep reading position. But similar if you copy it before Read operation(s) then you can use original copy for read position reset.
Inheritance
Namespace: Eco.Shared.Utils.Binary
Assembly: Eco.Shared.dll
Syntax
public sealed class ByteSpanReader : ValueType
Constructors
ByteSpanReader(ReadOnlySpan<Byte>)
Declaration
public ByteSpanReader(ReadOnlySpan<byte> span)
Parameters
| Type | Name | Description |
|---|---|---|
| System.ReadOnlySpan<System.Byte> | span |
Properties
BytesLeft
Returns how much bytes left for read.
Declaration
public int BytesLeft { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
UnreadSpan
Returns unread span. Changes after every read operation.
Declaration
public ReadOnlySpan<byte> UnreadSpan { get; }
Property Value
| Type | Description |
|---|---|
| System.ReadOnlySpan<System.Byte> |
Methods
ReadBoolean()
[0 - false/1 - true:byte] Reads a boolean value from the reader and advance read position by 1.
Declaration
public bool ReadBoolean()
Returns
| Type | Description |
|---|---|
| System.Boolean |
ReadByte()
Read next byte from the reader and advance read position by 1.
Declaration
public byte ReadByte()
Returns
| Type | Description |
|---|---|
| System.Byte |
ReadBytesTo(Stream, Int32)
Reads count bytes to output. Fails if not enough bytes to read.
Declaration
public void ReadBytesTo(Stream output, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | output | |
| System.Int32 | count |
ReadBytesTo(Span<Byte>)
Reads destination length bytes to destination. Fails if not enough bytes to read.
Declaration
public void ReadBytesTo(Span<byte> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Span<System.Byte> | destination |
ReadDouble()
Read a double value from the reader and advance read position by 8. Always uses LittleEndian.
Declaration
public double ReadDouble()
Returns
| Type | Description |
|---|---|
| System.Double |
ReadGuid()
[guid:byte[16]] Reads a Guid from the reader and advance read position by 16.
Declaration
public Guid ReadGuid()
Returns
| Type | Description |
|---|---|
| System.Guid |
ReadInt16()
Read a short value from the reader and advance read position by 2. Always uses LittleEndian.
Declaration
public short ReadInt16()
Returns
| Type | Description |
|---|---|
| System.Int16 |
ReadInt32()
Read an int value from the reader and advance read position by 4. Always uses LittleEndian.
Declaration
public int ReadInt32()
Returns
| Type | Description |
|---|---|
| System.Int32 |
ReadInt64()
Read a long value from the reader and advance read position by 8. Always uses LittleEndian.
Declaration
public long ReadInt64()
Returns
| Type | Description |
|---|---|
| System.Int64 |
ReadIPEndPoint()
[address length:byte][address bytes:byte array][port:ushort] Reads an IP end point from the reader and advances position (depending on size of encoded endpoint).
Declaration
public IPEndPoint ReadIPEndPoint()
Returns
| Type | Description |
|---|---|
| System.Net.IPEndPoint |
ReadSingle()
Read a double value from the reader and advance read position by 4. Always uses LittleEndian.
Declaration
public float ReadSingle()
Returns
| Type | Description |
|---|---|
| System.Single |
ReadString()
[str len:zig zag uint][str:utf-8 encoded byte array] Reads a string from the reader and advance read position by string length and encoded length size.
Declaration
public string ReadString()
Returns
| Type | Description |
|---|---|
| System.String |
ReadUInt16()
Read a unsigned short value from the reader and advance read position by 2. Always uses LittleEndian.
Declaration
public ushort ReadUInt16()
Returns
| Type | Description |
|---|---|
| System.UInt16 |
ReadUInt32()
Read a unsigned int value from the reader and advance read position by 4. Always uses LittleEndian.
Declaration
public uint ReadUInt32()
Returns
| Type | Description |
|---|---|
| System.UInt32 |
ReadUInt32ZigZag()
Read an unsigned int from the reader zig zag encoded and advance read position by 1-5 bytes (depending on how large is number).
Declaration
public uint ReadUInt32ZigZag()
Returns
| Type | Description |
|---|---|
| System.UInt32 |
ReadVector2()
Read a Vector2 from the reader and advance read position by 8 (2 x float).
Declaration
public Vector2 ReadVector2()
Returns
| Type | Description |
|---|---|
| Vector2 |
ReadVector3()
Read a System.Numerics.Vector3 from the reader and advance read position by 12 (3 x float).
Declaration
public Vector3 ReadVector3()
Returns
| Type | Description |
|---|---|
| System.Numerics.Vector3 |
Skip(Int32)
Skips count bytes.
Declaration
public void Skip(int count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | count |