feat: expose Buffer/Block on {Msg}DataReader (#151)#152
Merged
Conversation
The generated zero-copy reader already held the source span as a private field but didn't surface it. SbeDispatcher consumers that need to forward or buffer the raw bytes (e.g. snapshot-heal flows that stash messages into an ArrayPool slot for later replay) had no way to recover them after parsing — forcing a parallel manual templateId switch just to capture the body. Adds three readonly properties: - Buffer full source ReadOnlySpan<byte> the reader was built from - Block slice sized to the wire blockLength - BlockLength the wire blockLength int All readonly => no defensive copies through 'in' parameters. No codegen size or runtime cost change — only public accessors over fields that already existed. Bumps version to 1.3.0 (additive feature). 187 + 128 tests green (2 new ReaderBufferAccessTests covering fixed-layout and variable-data messages). Closes #151. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #151.
Problema
{Msg}DataReaderguarda o buffer-fonte num campo privado mas não expõe. Consumidores que migram paraSbeDispatcher(#147) e precisam encaminhar/buffer os bytes brutos (ex.: fluxo de snapshot-heal do B3 UMDF que enfileira a mensagem num slot doArrayPoolpara replay posterior) ficam sem recurso — precisariam manter um switch manual paralelo só para capturar o body.Mudança
Adiciona 3 properties
readonlyem todo{Msg}DataReadergerado:BufferReadOnlySpan<byte>BytesConsumedapósReadGroupspara fatiar exato)BlockReadOnlySpan<byte>blockLengthdo wireBlockLengthintblockLengthque construiu o readerTodas
readonlypara evitar defensive copies quando o reader chega viain.Custo
Zero — os dados já existem no campo privado
_buffer/_blockLength. São apenas accessors públicos. Sem mudança no tamanho do struct, sem branch novo, sem virtual.Estratégia alternativa considerada
Expor uma fábrica tipo
reader.AsBytes(int blockLengthOverride)? Descartado: não há ganho sobre slicing direto e adiciona superfície de API. Manter spans crus dá ao consumidor 100% de controle.Testes
tests/SbeCodeGenerator.IntegrationTests/ReaderBufferAccessTests.cs:Edge.Cases.Test.V0.TradeData): validaBlock/Buffer/BlockLengthespelham o que o encoder escreveu.Integration.Test.V0.OrderBookData): valida queBuffer.Slice(0, BytesConsumed)apósReadGroupsrecupera o footprint completo da mensagem com groups.187 + 128 testes verdes.