Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jul 16, 2025

Link issues

fixes #6424

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add comprehensive documentation and sample for ISocketDataPropertyConverter, update related menu entries, and enhance converters with data length validation before parsing.

Enhancements:

  • Add length checks in all built-in socket data property converters to only parse when input data length is within expected bounds
  • Update socket menu extension by removing outdated IsNew flags and adding a new "SocketDataEntity" sample menu item
  • Fix attribute name in SocketDataConverterBase comment to reference SocketDataPropertyAttribute

Documentation:

  • Introduce DataEntities sample page demonstrating use of SocketDataConverterAttribute and SocketDataPropertyAttribute for mapping raw socket data to business entities
  • Update localization and docs.json entries to support new DataEntity documentation

@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Jul 16, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 16, 2025

Reviewer's Guide

This PR hardens the socket data property converters by adding data length guards before binary parsing, corrects an attribute reference in the converter base class comment, refines the demo menu entries, and provides comprehensive documentation examples for ISocketDataPropertyConverter usage.

Class diagram for SocketDataProperty converters with data length guard

classDiagram
    class ISocketDataPropertyConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt32BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt32LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt64BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt64LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataDoubleBigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataDoubleLittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt16BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataInt16LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataSingleBigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataSingleLittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt16BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt16LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt32BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt32LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt64BigEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    class SocketDataUInt64LittleEndianConverter {
        +object? Convert(ReadOnlyMemory<byte> data)
    }
    ISocketDataPropertyConverter <|.. SocketDataInt32BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataInt32LittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataInt64BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataInt64LittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataDoubleBigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataDoubleLittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataInt16BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataInt16LittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataSingleBigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataSingleLittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt16BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt16LittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt32BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt32LittleEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt64BigEndianConverter
    ISocketDataPropertyConverter <|.. SocketDataUInt64LittleEndianConverter
Loading

Class diagram for SocketDataConverterBase and attribute usage

classDiagram
    class SocketDataConverterBase~TEntity~ {
        +bool TryConvertTo(ReadOnlyMemory<byte> data, out TEntity? entity)
        #bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
    }
    class SocketDataConverterAttribute {
        +Type Type
    }
    class SocketDataPropertyAttribute {
        +Type Type
        +int Offset
        +int Length
        +string EncodingName
        +Type ConverterType
        +object[] ConverterParameters
        +object? ConvertTo(ReadOnlyMemory<byte> data)
    }
    SocketDataConverterBase~TEntity~ <.. SocketDataConverterAttribute : uses
    SocketDataPropertyAttribute <.. SocketDataConverterBase~TEntity~ : used for property parsing
Loading

File-Level Changes

Change Details Files
Add length checks to all SocketData property converters before padding and reading
  • Wrap stackalloc and TryRead calls inside data.Length ≤ N condition
  • Move paddedSpan initialization and CopyTo inside the guard
  • Retain return default when data exceeds expected length
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt16BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt16LittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt32BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt32LittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt64BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataInt64LittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataSingleBigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataSingleLittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataDoubleBigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataDoubleLittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt16BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt16LittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt32BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt32LittleEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt64BigEndianConverter.cs
src/BootstrapBlazor/Services/TcpSocket/PropertyConverter/SocketDataUInt64LittleEndianConverter.cs
Fix attribute reference comment in SocketDataConverterBase
  • Update comment to reference SocketDataPropertyAttribute instead of SocketDataFieldAttribute
src/BootstrapBlazor/Services/TcpSocket/DataConverter/SocketDataConverterBase.cs
Adjust demo menu entries and add new SocketDataEntity sample route
  • Remove stale IsNew flags from existing menu items
  • Insert new menu item for SocketDataEntity with IsNew badge
src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs
Add comprehensive documentation and sample components for data entity conversion
  • Create DataEntities.razor and code-behind with usage examples
  • Update docs.json to include new sample page
  • Add localization entries in en-US.json and zh-CN.json
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor.cs
src/BootstrapBlazor.Server/docs.json
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json

Assessment against linked issues

Issue Objective Addressed Explanation
#6424 Add documentation for ISocketDataPropertyConverter component.
#6424 Provide sample code for ISocketDataPropertyConverter.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.8.0 milestone Jul 16, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • The paddedSpan and TryRead… logic is duplicated across all converters; consider extracting it into a shared helper or base implementation to reduce boilerplate.
  • I don’t see localization entries for DataEntityTitle, DataEntityDescription, etc., in the en-US.json/zh-CN.json files—please add those keys so the sample page renders correctly.
  • Currently inputs longer than the expected length silently return the default value; it may be helpful to log or throw an error in those cases to avoid hidden data truncation issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The paddedSpan and TryRead… logic is duplicated across all converters; consider extracting it into a shared helper or base implementation to reduce boilerplate.
- I don’t see localization entries for DataEntityTitle, DataEntityDescription, etc., in the en-US.json/zh-CN.json files—please add those keys so the sample page renders correctly.
- Currently inputs longer than the expected length silently return the default value; it may be helpful to log or throw an error in those cases to avoid hidden data truncation issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (fdbe935) to head (3b5cf59).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6425   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          746       746           
  Lines        32177     32225   +48     
  Branches      4538      4554   +16     
=========================================
+ Hits         32177     32225   +48     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@ArgoZhang ArgoZhang merged commit ab6431b into main Jul 16, 2025
6 of 7 checks passed
@ArgoZhang ArgoZhang deleted the doc-socket branch July 16, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(ISocketDataPropertyConverter): add ISocketDataPropertyConverter documentation

2 participants