Skip to content

Commit 641e44d

Browse files
committed
Add ByteBufferWriter.Position.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent 0133371 commit 641e44d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/MySqlConnector/Protocol/Serialization/ByteBufferWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public ByteBufferWriter(int capacity = 0)
1515
m_output = m_buffer;
1616
}
1717

18-
public ArraySegment<byte> ArraySegment => new ArraySegment<byte>(m_buffer, 0, m_buffer.Length - m_output.Length);
18+
public int Position => m_buffer.Length - m_output.Length;
19+
20+
public ArraySegment<byte> ArraySegment => new ArraySegment<byte>(m_buffer, 0, Position);
1921

2022
public PayloadData ToPayloadData() => new PayloadData(ArraySegment, isPooled: true);
2123

@@ -210,7 +212,7 @@ public void WriteString(ulong value)
210212

211213
private void Reallocate(int additional = 0)
212214
{
213-
var usedLength = m_buffer.Length - m_output.Length;
215+
var usedLength = Position;
214216
var newBuffer = ArrayPool<byte>.Shared.Rent(Math.Max(usedLength + additional, m_buffer.Length * 2));
215217
Buffer.BlockCopy(m_buffer, 0, newBuffer, 0, usedLength);
216218
ArrayPool<byte>.Shared.Return(m_buffer);

0 commit comments

Comments
 (0)