SbeWriteBuffer
Helpers for serializing an SBE message into a per-session write buffer that grows on overflow instead of dropping the message and disconnecting the client.
Methods
public static byte[] Grow(byte[] buffer, int minSize)
result = SbeWriteBuffer.Grow(buffer, minSize)
Returns a buffer at least bytes long. If the existing buffer is already large enough it is returned unchanged; otherwise a new buffer is allocated by doubling capacity until it covers , capped at MaxWriteBufferSize.
- buffer
- Current buffer (may be null).
- minSize
- Minimum required size in bytes.
Returns: A buffer whose length is at least .
private static bool IsOverflow(Exception ex, int currentSize, int requiredSize)
result = SbeWriteBuffer.IsOverflow(ex, currentSize, requiredSize)
Recognizes the span-overflow exceptions thrown by the SBE serializer and computes a target size to grow to. A dedicated SbeBufferTooSmallException supplies an exact size; generic span overflows fall back to doubling.
public static int Serialize(ClientSbeSession session, Func<SbeRecordSerializer, byte[], int> serialize)
result = SbeWriteBuffer.Serialize(session, serialize)
Serializes a message into the session write buffer, growing the buffer and retrying on overflow. Returns the number of bytes written. The (possibly reallocated) buffer is available via WriteBuffer.
- session
- Target session whose write buffer is used.
- serialize
- Serialize delegate: writes into the buffer, returns written length.
Returns: Number of bytes written into the session buffer.
Fields
public const int InitialWriteBufferSize
value = SbeWriteBuffer.InitialWriteBufferSize
Default initial size of a session write buffer.
public const int MaxWriteBufferSize
value = SbeWriteBuffer.MaxWriteBufferSize
Hard upper bound for a single SBE frame. A frame that does not fit even after growing to this size is treated as a genuine error and re-thrown, rather than looping forever on reallocation.