@@ -11,7 +11,6 @@ namespace MLAPI.NetworkingManagerComponents.Binary
11
11
public sealed class BitStream : Stream
12
12
{
13
13
const int initialCapacity = 16 ;
14
- private readonly float growthFactor ;
15
14
private readonly byte [ ] target ;
16
15
17
16
/// <summary>
@@ -22,7 +21,7 @@ public sealed class BitStream : Stream
22
21
public BitStream ( int capacity = initialCapacity , float growthFactor = 2.0f )
23
22
{
24
23
target = new byte [ capacity ] ;
25
- this . growthFactor = growthFactor <= 1 ? 1.5f : growthFactor ;
24
+ GrowthFactor = growthFactor ;
26
25
Resizable = true ;
27
26
}
28
27
@@ -60,6 +59,12 @@ public BitStream(byte[] target)
60
59
/// </summary>
61
60
public bool Resizable { get ; }
62
61
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
+
63
68
/// <summary>
64
69
/// Whether or not data can be read from the stream.
65
70
/// </summary>
@@ -233,7 +238,7 @@ public override void Write(byte[] buffer, int offset, int count)
233
238
/// Grow buffer if possible. According to Max(bufferLength, 1) * growthFactor^Ceil(newContent/Max(bufferLength, 1))
234
239
/// </summary>
235
240
/// <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 ) ) ) ) ;
237
242
238
243
/// <summary>
239
244
/// Write a single bit to the stream
0 commit comments