Skip to content

Conversation

Copy link

Copilot AI commented Oct 30, 2025

Implements PR #77 proposal: removes BeginEncoding() and public TryEncode*() helper methods that allowed encoding groups/varData in incorrect order, causing silent data corruption.

Changes

  • MessageDefinition.cs: Made BeginEncoding(), TryEncode{GroupName}(), and TryEncode{VarDataName}() private

    • Now internal helpers for comprehensive TryEncode() methods only
    • Public API reduced to two safe overloads: span-based and callback-based
  • Tests: Updated to use comprehensive TryEncode() API

    • Removed 3 tests for deprecated methods
    • 115 integration tests passing
  • Documentation: Updated README.md and ENCODING_ORDER_FIX.md

    • Removed "Traditional API" sections
    • Documented breaking change and migration path

API

Before (Error-Prone)

orderBook.BeginEncoding(buffer, out var writer);
OrderBookData.TryEncodeBids(ref writer, bids);
OrderBookData.TryEncodeAsks(ref writer, asks);  // Easy to swap order → corrupt data

After (Compile-Time Safe)

// Span-based: simple, allocation-based
OrderBookData.TryEncode(orderBook, buffer, bids, asks, out bytesWritten);

// Callback-based: zero-allocation
OrderBookData.TryEncode(
    orderBook, buffer,
    bidCount, (i, ref item) => { /* populate */ },
    askCount, (i, ref item) => { /* populate */ },
    out bytesWritten);

Method signature enforces schema order. Wrong parameter order = compilation error.

Breaking Change

⚠️ User code calling BeginEncoding() or individual TryEncode*() methods will not compile. Migration requires switching to comprehensive TryEncode().

Original prompt

Implementar a proposta #77, removendo os demais fluxos de encoding, considerando que eles são sujeitos a erros.
Implementar o fluxo allocation free e com alocação.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 30, 2025 17:24
…methods

Co-authored-by: pedrosakuma <39205549+pedrosakuma@users.noreply.github.com>
Co-authored-by: pedrosakuma <39205549+pedrosakuma@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove encoding flows and implement allocation free logic Remove error-prone encoding APIs, enforce schema order at compile-time Oct 30, 2025
Copilot AI requested a review from pedrosakuma October 30, 2025 17:32
@pedrosakuma pedrosakuma marked this pull request as ready for review October 30, 2025 17:37
@pedrosakuma pedrosakuma merged commit 9349084 into master Oct 30, 2025
1 check passed
@pedrosakuma pedrosakuma deleted the copilot/remove-encoding-flows branch October 30, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants