Skip to content

Commit 2965335

Browse files
committed
Added GrowthFactor property
1 parent c4e4d54 commit 2965335

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace MLAPI.NetworkingManagerComponents.Binary
1111
public sealed class BitStream : Stream
1212
{
1313
const int initialCapacity = 16;
14-
private readonly float growthFactor;
1514
private readonly byte[] target;
1615

1716
/// <summary>
@@ -22,7 +21,7 @@ public sealed class BitStream : Stream
2221
public BitStream(int capacity = initialCapacity, float growthFactor = 2.0f)
2322
{
2423
target = new byte[capacity];
25-
this.growthFactor = growthFactor <= 1 ? 1.5f : growthFactor;
24+
GrowthFactor = growthFactor;
2625
Resizable = true;
2726
}
2827

@@ -60,6 +59,12 @@ public BitStream(byte[] target)
6059
/// </summary>
6160
public bool Resizable { get; }
6261

62+
private float _growthFactor;
63+
/// <summary>
64+
/// Factor by which buffer should grow when necessary.
65+
/// </summary>
66+
public float GrowthFactor { set { _growthFactor = value <= 1 ? 1.5f : value; } get { return _growthFactor; } }
67+
6368
/// <summary>
6469
/// Whether or not data can be read from the stream.
6570
/// </summary>
@@ -233,7 +238,7 @@ public override void Write(byte[] buffer, int offset, int count)
233238
/// Grow buffer if possible. According to Max(bufferLength, 1) * growthFactor^Ceil(newContent/Max(bufferLength, 1))
234239
/// </summary>
235240
/// <param name="newContent">How many new values need to be accomodated (at least).</param>
236-
private void Grow(long newContent) => SetCapacity(Math.Max(target.LongLength, 1) * (long)Math.Pow(growthFactor, CeilingExact(newContent, Math.Max(target.LongLength, 1))));
241+
private void Grow(long newContent) => SetCapacity(Math.Max(target.LongLength, 1) * (long)Math.Pow(GrowthFactor, CeilingExact(newContent, Math.Max(target.LongLength, 1))));
237242

238243
/// <summary>
239244
/// Write a single bit to the stream

0 commit comments

Comments
 (0)