Ledon.Protocols 0.0.1

dotnet add package Ledon.Protocols --version 0.0.1
                    
NuGet\Install-Package Ledon.Protocols -Version 0.0.1
                    
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="Ledon.Protocols" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ledon.Protocols" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Ledon.Protocols" />
                    
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 Ledon.Protocols --version 0.0.1
                    
#r "nuget: Ledon.Protocols, 0.0.1"
                    
#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 Ledon.Protocols@0.0.1
                    
#: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=Ledon.Protocols&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Ledon.Protocols&version=0.0.1
                    
Install as a Cake Tool

Ledon.Protocols

协议解析库(零依赖):帧编解码、二进制读写、结构体映射。 客户端与服务端是独立包:Ledon.Protocols.Client / Ledon.Protocols.Server。

结构体映射(核心)

public struct LoginRequest
{
    [PacketField(0, PacketFieldKind.UInt32)] public uint Version;
    [PacketField(1, PacketFieldKind.Utf8String)] public string? User;
    [PacketField(2, PacketFieldKind.Bool)] public bool Remember;
}

var bytes = PacketSerializer<LoginRequest>.Serialize(new LoginRequest { Version = 3, User = "alice", Remember = true });
var request = PacketSerializer<LoginRequest>.Deserialize(bytes);

布局即契约:两端各写一份结构体就能通信,不需要 IDL / schema 文件。

性能设计:

  • 首次使用时为每个成员编译强类型访问器(表达式树),之后零反射、零装箱;
  • 读写在 PacketReader / PacketWriter(ref struct)上进行,无中间数组;
  • 定长布局可预计算大小(PacketSerializer<T>.Size),变长布局用 Measure;
  • 实测单次解析几十纳秒级(测试里有性能守卫,回归成反射会直接失败)。

支持的字段类型:Bool Int8/UInt8 Int16/UInt16 Int32/UInt32 Int64/UInt64 Float32 Double Utf8String FixedString Bytes FixedBytes Struct(嵌套) Array(数组);枚举按底层类型走。默认小端,bigEndian: true 或字段级 [PacketField(0, Kind = PacketFieldKind.Int32, BigEndian = true)] 切大端。

帧编解码(字节流 → 完整包)

IFrameCodec codec = new LengthPrefixedFrameCodec();      // [长度(4)][载荷]
IFrameCodec lines = new DelimiterFrameCodec((byte)'\n'); // 换行分隔(也支持 "\r\n")
IFrameCodec fixedSize = new FixedSizeFrameCodec(32);     // 定长

二进制读写(手动场景)

var buffer = new ArrayBufferWriter<byte>();
var writer = new PacketWriter(buffer, bigEndian: true);
writer.WriteUInt32(0x11223344);
writer.WriteUtf8String("hi");

var reader = new PacketReader(buffer.WrittenSpan, bigEndian: true);
var magic = reader.ReadUInt32();
var text = reader.ReadUtf8String();

协议不同步/帧损坏抛 ProtocolException(与普通 IO 错误区分,调用方可决定是否断开连接)。

完整文档:https://github.com/wosledon/ledon-framework

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Ledon.Protocols:

Package Downloads
Ledon.Sip

.NET 10 模块化 Web 开发框架:解耦优先,自动发现与自动注入,能力按需引入。

Ledon.Sockets.Server

Ledon 协议服务端:TCP/UDP 监听、连接管理、类型化分发。

Ledon.Sockets.Client

Ledon 协议客户端:TCP/UDP 连接、断线重连、类型化收发。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1 70 10/28/2026