Skip to content

Add BinaryPrimitives polyfills - #130

Merged
Tyrrrz merged 5 commits into
primefrom
copilot/add-polyfills-binaryprimitives
Jul 11, 2026
Merged

Add BinaryPrimitives polyfills#130
Tyrrrz merged 5 commits into
primefrom
copilot/add-polyfills-binaryprimitives

Conversation

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

System.Buffers.Binary.BinaryPrimitives was introduced in .NET Core 2.1 / .NET Standard 2.1 and is unavailable on .NET Framework, older .NET Standard, and .NET Core < 2.1. This adds full polyfill coverage.

Changes

  • PolyShim/NetCore21/BinaryPrimitives.cs — Full static class polyfill active under (NETCOREAPP && !NETCOREAPP2_1_OR_GREATER) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) || NETFRAMEWORK:

    • ReverseEndiannessshort, ushort, int, uint, long, ulong
    • ReadXxx{Big,Little}Endian / TryReadXxxInt16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double
    • WriteXxx{Big,Little}Endian / TryWriteXxx — same types
    • Float bit-reinterpretation uses unsafe pointer cast when ALLOW_UNSAFE_BLOCKS is defined; falls back to BitConverter otherwise
  • PolyShim/Net50/BinaryPrimitives.cs — Extension methods for ReverseEndianness(byte) and ReverseEndianness(sbyte) added in .NET 5, covering the gap on netcoreapp2.1–3.x and netstandard2.1

  • PolyShim.Tests/NetCore21/BinaryPrimitivesTests.cs — 39 tests covering read/write round-trips, endianness correctness, and TryXxx boundary checks

// All of these now work on .NET Framework / netstandard2.0 / old netcoreapp
BinaryPrimitives.WriteInt32BigEndian(buf, 0x12345678);   // [0x12, 0x34, 0x56, 0x78]
BinaryPrimitives.ReadDoubleLittleEndian(bytes);           // 1.0
BinaryPrimitives.ReverseEndianness(0x0102030405060708L); // 0x0807060504030201L
BinaryPrimitives.TryWriteUInt64BigEndian(span, value);   // false if span too short

@Tyrrrz Tyrrrz added the enhancement New feature or request label Jul 11, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 11, 2026 19:19
Copilot AI review requested due to automatic review settings July 11, 2026 19:19
Comment thread PolyShim/Net50/BinaryPrimitives.cs Outdated
Comment thread Signatures.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a System.Buffers.Binary.BinaryPrimitives polyfill so consumers targeting .NET Framework, older .NET Standard, and older .NET Core can use the same BinaryPrimitives APIs (plus later-added byte/sbyte overloads) with accompanying tests and signature index updates.

Changes:

  • Added a full BinaryPrimitives type polyfill for pre-.NET Core 2.1 / pre-.NET Standard 2.1 / .NET Framework targets.
  • Added Net50 “member polyfills” for ReverseEndianness(byte) / ReverseEndianness(sbyte) (added in .NET 5).
  • Added a new NetCore21 test suite covering common read/write/try patterns and endianness correctness; updated signature inventory.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Signatures.md Updates generated signature counts and adds BinaryPrimitives entries.
PolyShim/NetCore21/BinaryPrimitives.cs New full polyfill implementation for BinaryPrimitives (reverse endianness + read/write + try APIs).
PolyShim/Net50/BinaryPrimitives.cs Adds missing byte/sbyte ReverseEndianness members via member-polyfill extensions for pre-.NET 5 targets.
PolyShim.Tests/NetCore21/BinaryPrimitivesTests.cs New tests for key endianness and try-read/write behaviors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PolyShim/NetCore21/BinaryPrimitives.cs
Comment thread PolyShim.Tests/NetCore21/BinaryPrimitivesTests.cs
…ator

- Move byte/sbyte ReverseEndianness from Net50 to NetCore21 (introduced in .NET Core 2.1, not .NET 5.0)
- Update signature generator to include methods from static class polyfills
- All 72 BinaryPrimitives methods now correctly listed in Signatures.md as .NET Core 2.1
- Signatures count updated: Total 616 (+72), Members 502 (+72)
Copilot AI requested a review from Tyrrrz July 11, 2026 19:34
@Tyrrrz

Tyrrrz commented Jul 11, 2026

Copy link
Copy Markdown
Owner

@copilot please regenerated the Signatures.md file, as I've merged in the latest prime

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.19%. Comparing base (34a338c) to head (f26c3a3).

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #130      +/-   ##
==========================================
+ Coverage   99.16%   99.19%   +0.02%     
==========================================
  Files         147      148       +1     
  Lines        3846     3981     +135     
  Branches       87       87              
==========================================
+ Hits         3814     3949     +135     
  Misses         13       13              
  Partials       19       19              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please regenerated the Signatures.md file, as I've merged in the latest prime

Done! Regenerated Signatures.md in f26c3a3. The file now shows 620 total signatures (114 types, 506 members), up from 545, reflecting the BinaryPrimitives polyfills and changes from the latest prime branch.

@Tyrrrz
Tyrrrz merged commit 3999e5c into prime Jul 11, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-polyfills-binaryprimitives branch July 11, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants