Skip to content

Commit 336bed4

Browse files
committed
Removed unneccecary BitStream constructor and fixed CanRead behaviour
1 parent 7a41865 commit 336bed4

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ public BitStream(int capacity) : this(capacity, initialGrowthFactor) { }
4242
/// </summary>
4343
public BitStream() : this(initialCapacity, initialGrowthFactor) { }
4444

45-
/// <summary>
46-
/// A stream that supports writing data smaller than a single byte. This stream also has a built-in compression algorithm that can (optionally) be used to write compressed data.
47-
/// </summary>
48-
/// <param name="target">The buffer containing initial data</param>
49-
/// <param name="offset">The offset where the data begins</param>
50-
/// <param name="count">The amount of bytes to copy from the initial data buffer</param>
51-
public BitStream(byte[] target, int offset, int count) : this(count)
52-
{
53-
Buffer.BlockCopy(target, offset, this.target, 0, count);
54-
Resizable = false;
55-
}
56-
5745
/// <summary>
5846
/// A stream that supports writing data smaller than a single byte. This stream also has a built-in compression algorithm that can (optionally) be used to write compressed data.
5947
/// NOTE: when using a pre-allocated buffer, the stream will not grow!
@@ -78,9 +66,14 @@ public BitStream(byte[] target)
7866
public float GrowthFactor { set { _growthFactor = value <= 1 ? 1.5f : value; } get { return _growthFactor; } }
7967

8068
/// <summary>
81-
/// Whether or not data can be read from the stream.
69+
/// Whether or not stream supports reading. (Always true)
70+
/// </summary>
71+
public override bool CanRead => true;
72+
73+
/// <summary>
74+
/// Wheter or not or there is any data to be read from the stream.
8275
/// </summary>
83-
public override bool CanRead => Position < Length;
76+
public bool HasDataToRead => Position < Length;
8477

8578
/// <summary>
8679
/// Whether or not seeking is supported by this stream. (Always true)
@@ -167,14 +160,14 @@ private byte ReadByteMisaligned()
167160
/// Read a byte from the buffer. This takes into account possible byte misalignment.
168161
/// </summary>
169162
/// <returns>A byte from the buffer or, if a byte can't be read, -1.</returns>
170-
public override int ReadByte() => CanRead ? BitAligned ? ReadByteAligned() : ReadByteMisaligned() : -1;
163+
public override int ReadByte() => HasDataToRead ? BitAligned ? ReadByteAligned() : ReadByteMisaligned() : -1;
171164

172165
/// <summary>
173166
/// Peeks a byte without advancing the position
174167
/// </summary>
175168
/// <returns>The peeked byte</returns>
176169
public int PeekByte() =>
177-
CanRead ?
170+
HasDataToRead ?
178171
BitAligned ?
179172
target[Position] :
180173
(byte)((target[(int)Position] >> (int)(BitPosition & 7)) | (target[(int)(BitPosition + 8) >> 3] << (8 - (int)(BitPosition & 7)))) :

0 commit comments

Comments
 (0)