Skip to content

Add C# port of the MassData Parameter API#41

Merged
nevstop merged 4 commits into
mainfrom
copilot/add-csharp-support-to-massdata
Apr 26, 2026
Merged

Add C# port of the MassData Parameter API#41
nevstop merged 4 commits into
mainfrom
copilot/add-csharp-support-to-massdata

Conversation

Copilot AI commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Provides a C# implementation of the CSM MassData Parameter Support API, on par with the C port from #40, so .NET callers can exchange MassData reference strings with LabVIEW / C peers.

Library (csharp/src/CsmMassData/)

  • CsmMassData static class with the six methods matching the LabVIEW VIs / C functions (ConfigMassDataParameterCacheSize, ConvertMassDataToArgument[WithDataType], ConvertArgumentToMassData, MassDataDataTypeString, MassDataParameterStatus).
  • CsmMassDataStatus enum mirrors csm_massdata_status_t numerically; errors surface as CsmMassDataException exposing that status — idiomatic for .NET while keeping cross-language error parity.
  • Shared ring buffer initialized via static field initializers (CLR once-only guarantee) and serialized by a single lock.
  • Parser ports the hardening from Add C-language port of the MassData API with a Visual Studio 2026 test project #40: ulong overflow rejection on Start/Size, DataType charset validation (no ; < >), no trailing junk allowed, and pre-add overflow check on start + size in the residency test.
  • All comments / XML doc are in Chinese, matching the convention established in Add C-language port of the MassData API with a Visual Studio 2026 test project #40.

Tests (csharp/_test/vs/)

  • MSTest project with 11 tests covering config/status, plain & typed round-trips, datatype absence, parse errors (including ulong overflow), overwrite detection, cache-too-small, status reflection, forbidden-character rejection, empty payloads, and an 8-thread stress test.
  • VS2026 .sln (# Visual Studio Version 18); [assembly: DoNotParallelize] since the API has process-wide shared state.

Repo plumbing

  • csharp/** added to paths-ignore in Build_VIPM_Library.yml and Check_Broken_VIs.yml.
  • .gitignore extended with csharp/**/{bin,obj,Debug,Release,x64,x86,.vs}/ and *.user / *.suo.

Usage

using Csm.MassData;

CsmMassData.ConfigMassDataParameterCacheSize(64 * 1024 * 1024);
string arg = CsmMassData.ConvertMassDataToArgumentWithDataType(samples, "1D DBL");
// ... ship `arg` over the CSM bus ...
byte[] restored = CsmMassData.ConvertArgumentToMassData(arg);

Copilot AI changed the title [WIP] Add third-party language support for C# in massdata Add C# port of the MassData Parameter API Apr 25, 2026
Copilot AI requested a review from nevstop April 25, 2026 12:25
@nevstop nevstop requested a review from Copilot April 25, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

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 .NET (C#) implementation of the CSM MassData Parameter Support API so .NET callers can exchange MassData reference strings with LabVIEW/C peers, with matching status semantics and a dedicated MSTest suite.

Changes:

  • Introduces Csm.MassData library (CsmMassData, status enum, exception type, operation struct) implementing the MassData ring-buffer encode/decode + parsing hardening.
  • Adds MSTest project/solution validating round-trips, error/status behavior, overwrite detection, and multi-thread stress.
  • Updates repo plumbing: ignore csharp/** in LabVIEW-focused workflows and add C# build artifacts to .gitignore.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
csharp/src/CsmMassData/CsmMassDataStatus.cs Adds C-aligned status enum for .NET.
csharp/src/CsmMassData/CsmMassDataOperation.cs Adds operation descriptor struct matching LabVIEW status cluster semantics.
csharp/src/CsmMassData/CsmMassDataException.cs Adds exception type carrying CsmMassDataStatus.
csharp/src/CsmMassData/CsmMassData.csproj Adds .NET 8 SDK-style library project.
csharp/src/CsmMassData/CsmMassData.cs Core ring buffer, encoder/decoder, parser, and status APIs.
csharp/_test/vs/CsmMassData.Tests/MSTestSettings.cs Disables parallel test execution at assembly level.
csharp/_test/vs/CsmMassData.Tests/CsmMassDataTests.cs End-to-end MSTest coverage for the new API.
csharp/_test/vs/CsmMassData.Tests/CsmMassData.Tests.csproj Adds MSTest project referencing the library.
csharp/_test/vs/CsmMassData.Tests.sln Visual Studio solution for running the tests.
csharp/README.md Documents layout, API mapping, usage, and test instructions.
.gitignore Ignores C# build artifacts under csharp/.
.github/workflows/Check_Broken_VIs.yml Prevents C#-only changes from triggering LabVIEW workflow.
.github/workflows/Build_VIPM_Library.yml Prevents C#-only changes from triggering VIPM build workflow.

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

Comment on lines +290 to +298
if (dataType is not null)
{
// 数据类型不能包含会破坏引用字符串语法的字符。
if (dataType.IndexOfAny(new[] { ';', '<', '>' }) >= 0)
{
throw new CsmMassDataException(
CsmMassDataStatus.InvalidArgument,
"dataType 中不允许出现 ';'、'<' 或 '>' 字符。");
}

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

dataType.IndexOfAny 这里每次都会 new 一个 char[],在高频编码场景会产生不必要的分配。建议改为复用静态 readonly char[](或改为分别 Contains(';') / Contains('<') / Contains('>'))以避免每次调用分配。

Copilot uses AI. Check for mistakes.
Comment on lines +126 to +131
/// </remarks>
/// <param name="data">待保存的原始字节,<c>null</c> 视为空数据。</param>
/// <returns>MassData 参数字符串。</returns>
/// <exception cref="CsmMassDataException">编码过程中检测到错误时抛出。</exception>
public static string ConvertMassDataToArgument(ReadOnlySpan<byte> data)
=> Encode(data, dataType: null);

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

该重载的参数类型是 ReadOnlySpan,在 C# 里不可能为 null,但 XML 注释仍写了“null 视为空数据”。建议把这条说明移到 byte[]? 重载,或改为说明空 Span 等价于空数据,以免误导调用方。

Copilot uses AI. Check for mistakes.
Comment thread csharp/src/CsmMassData/CsmMassData.cs Outdated
Comment on lines +152 to +153
/// 非空的数据类型字符串(例如 <c>"1D I32"</c>);不允许包含
/// <c>';'</c>、<c>'&lt;'</c> 或 <c>'&gt;'</c>。

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

这里的注释写“非空的数据类型字符串”,但实现仅拒绝 null/非法字符/过长,并未拒绝空字符串;C 端实现同样允许空字符串。建议要么在实现中显式拒绝空字符串,要么把注释改为“可为空字符串但不能为 null”,保证文档与行为一致。

Suggested change
/// 非空的数据类型字符串(例如 <c>"1D I32"</c>);不允许包含
/// <c>';'</c>、<c>'&lt;'</c> 或 <c>'&gt;'</c>。
/// 可为空字符串但不能为 <c>null</c> 的数据类型字符串(例如 <c>"1D I32"</c>);
/// 不允许包含 <c>';'</c>、<c>'&lt;'</c> 或 <c>'&gt;'</c>。

Copilot uses AI. Check for mistakes.
@nevstop

nevstop commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Copilot AI commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

已在 88d816d 中处理三处反馈:1) 将 IndexOfAny 使用的 char[] 提取为 static readonly ForbiddenDataTypeChars,避免每次编码时分配;2) ReadOnlySpan<byte> 重载的 <param> 改为“空 Span 等价于不写入任何数据”,不再误导性地提“null”;3) dataType 注释从“非空”改为“可为空字符串但不能为 null”,与实现及 C 端行为一致。

@nevstop nevstop marked this pull request as ready for review April 25, 2026 16:07
@nevstop

nevstop commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

@copilot 解决冲突的问题

…pport-to-massdata

# Conflicts:
#	.gitignore

Co-authored-by: nevstop <8196752+nevstop@users.noreply.github.com>

Copilot AI commented Apr 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 解决冲突的问题

已在 b61a14d 中合并 origin/main 并解决 .gitignore 冲突(保留 csharp/python/ 两段忽略规则)。合并后 dotnet test 11/11 通过。

Copilot AI requested a review from nevstop April 26, 2026 02:55
@nevstop nevstop merged commit 6d754bc into main Apr 26, 2026
@nevstop nevstop deleted the copilot/add-csharp-support-to-massdata branch April 26, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

massdata 的第三方语言支持: C#

3 participants