CSoft.Parser 11.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSoft.Parser --version 11.0.0
                    
NuGet\Install-Package CSoft.Parser -Version 11.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSoft.Parser" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.Parser" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CSoft.Parser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSoft.Parser --version 11.0.0
                    
#r "nuget: CSoft.Parser, 11.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CSoft.Parser@11.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSoft.Parser&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CSoft.Parser&version=11.0.0
                    
Install as a Cake Tool

CSoft.Parser

把串口、TCP 等来源的连续字节拆成协议帧,通过 OnReceiveParsedData 交付 byte[]。可从 PipeReader 连续读取,也可直接提交字节块。

安装

dotnet add package CSoft.Parser --version 11.0.0

包含 .NET 8、.NET 9、.NET 10、.NET 11 和 .NET Standard 2.0 目标。.NET Framework 4.8 使用 .NET Standard 2.0 资产。

选择分帧方式

类型 适用边界
HeadFootParser 固定帧头和帧尾,输出包含两者。
FootParser 仅用分隔符或帧尾结束,输出包含帧尾。
HeadLengthParser 根据长度回调确定一帧长度,可有固定帧头。
TimeParser 接收空闲超过指定毫秒数时输出一帧,默认 20 毫秒。使用后调用 Dispose()。
NoParser 原样交付非空数据块,块边界取决于输入或底层读取。

最小示例

将以下代码放入 .NET 8 或更新版本的控制台项目。两次输入组成一帧,输出 AA-01-BB。

using System;
using System.Threading.Tasks;
using Parser.Parsers;

var parser = new HeadFootParser(
    new byte[] { 0xAA }, new byte[] { 0xBB }, useChannel: false);

parser.OnReceiveParsedData += frame =>
{
    Console.WriteLine(BitConverter.ToString(frame));
    return Task.CompletedTask;
};

await parser.ReceiveOriginalDataAsync(new byte[] { 0xAA, 0x01 });
await parser.ReceiveOriginalDataAsync(new byte[] { 0xBB });

接入真实数据流

  • 使用 RunAsync(reader, cancellationToken) 从 PipeReader 持续分帧。内置解析器退出时会完成读取器。每条独立字节流使用自己的解析器实例,以免混用半帧或回调。
  • HeadFootParser、FootParser 和 HeadLengthParser 默认用有界队列分发。提交数据后,回调可能仍在后台处理。需要等待当次分帧回调时,可用 useChannel: false。
  • 带帧头的 HeadLengthParser 默认让长度回调看到含帧头的候选数据,成功时 Length 为整帧字节数。使用 haveHeadOfData: false 时,回调看到帧头之后的数据,Length 也按帧头之后的字节数计算。长度字段还未收齐时返回 StateCode.LengthNotEnough。
  • 需要自定义边界时,可继承 BaseParser 并实现帧头、帧尾定位,或直接实现 Parser.Interfaces.IParser。
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CSoft.Parser:

Package Downloads
CSoft.TopPortLib

通信口使用类库

CSoft.Communication

通信物理口封装

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.3 104 11/13/2026
11.0.2 47 11/13/2026
11.0.1 146 11/12/2026
11.0.0 97 11/12/2026
10.6.2 2,236 5/28/2026
10.6.1 391 5/28/2026
10.6.0 528 5/27/2026
10.5.1 481 5/25/2026
10.5.0 483 5/25/2026
10.4.10 580 5/19/2026
10.4.9 480 5/19/2026
10.4.8 384 5/18/2026
10.4.7 356 5/18/2026
10.4.6 407 5/15/2026
10.4.5 410 5/14/2026
10.4.3 345 5/14/2026
10.4.1 441 5/11/2026
10.4.0 351 5/11/2026
10.3.1 351 5/7/2026
10.3.0 389 5/7/2026
Loading failed

升级至 11.0.0,新增 .NET 8、9 和 11 目标,继续提供 .NET Standard 2.0 和 .NET 10。
支持取消等待分帧队列容量,重新读取时重新计算首帧长度。