Skip to content

Commit 4f9d313

Browse files
committed
fix: 修复dart和rust客户端库
1 parent 8fbd080 commit 4f9d313

52 files changed

Lines changed: 4960 additions & 422 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Clients 通用忽略文件
2+
3+
# 所有客户端库的编译和发布文件
4+
# 各子目录的 .gitignore 会处理具体的忽略规则
5+
6+
# 通用构建目录
7+
**/bin/
8+
**/obj/
9+
**/target/
10+
**/build/
11+
**/dist/
12+
**/node_modules/
13+
**/.dart_tool/
14+
**/__pycache__/
15+
**/*.egg-info/
16+
17+
# 通用编译产物
18+
**/*.dll
19+
**/*.exe
20+
**/*.pdb
21+
**/*.class
22+
**/*.jar
23+
**/*.war
24+
**/*.nupkg
25+
**/*.whl
26+
**/*.tar.gz
27+
**/*.rlib
28+
**/*.rmeta
29+
**/*.d
30+
31+
# 通用 IDE 文件
32+
**/.vs/
33+
**/.vscode/
34+
**/.idea/
35+
**/*.iml
36+
**/*.swp
37+
**/*.swo
38+
39+
# 通用 OS 文件
40+
**/.DS_Store
41+
**/Thumbs.db
42+
43+
# 通用日志和缓存
44+
**/*.log
45+
**/.cache/
46+
**/.tmp/
47+
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
## .NET / C# 编译和发布文件
2+
3+
# Build results
4+
[Dd]ebug/
5+
[Dd]ebugPublic/
6+
[Rr]elease/
7+
[Rr]eleases/
8+
x64/
9+
x86/
10+
[Ww][Ii][Nn]32/
11+
[Aa][Rr][Mm]/
12+
[Aa][Rr][Mm]64/
13+
bld/
14+
[Bb]in/
15+
[Oo]bj/
16+
[Ll]og/
17+
[Ll]ogs/
18+
19+
# Visual Studio cache/options directory
20+
.vs/
21+
22+
# Visual Studio Code
23+
.vscode/
24+
25+
# User-specific files
26+
*.rsuser
27+
*.suo
28+
*.user
29+
*.userosscache
30+
*.sln.docstates
31+
32+
# Build results
33+
[Dd]ebug/
34+
[Rr]elease/
35+
x64/
36+
x86/
37+
[Ww][Ii][Nn]32/
38+
[Aa][Rr][Mm]/
39+
[Aa][Rr][Mm]64/
40+
bld/
41+
[Bb]in/
42+
[Oo]bj/
43+
[Ll]og/
44+
[Ll]ogs/
45+
46+
# NuGet Packages
47+
*.nupkg
48+
*.snupkg
49+
**/packages/*
50+
!**/packages/build/
51+
*.nuget.props
52+
*.nuget.targets
53+
54+
# .NET Core
55+
project.lock.json
56+
project.fragment.lock.json
57+
artifacts/
58+
59+
# ASP.NET Scaffolding
60+
ScaffoldingReadMe.txt
61+
62+
# Files built by Visual Studio
63+
*_i.c
64+
*_p.c
65+
*_h.h
66+
*.ilk
67+
*.meta
68+
*.obj
69+
*.iobj
70+
*.pch
71+
*.pdb
72+
*.ipdb
73+
*.pgc
74+
*.pgd
75+
*.rsp
76+
*.sbr
77+
*.tlb
78+
*.tli
79+
*.tlh
80+
*.tmp
81+
*.tmp_proj
82+
*_wpftmp.csproj
83+
*.log
84+
*.vspscc
85+
*.vssscc
86+
.builds
87+
*.pidb
88+
*.svclog
89+
*.scc
90+
91+
# Visual C++ cache files
92+
ipch/
93+
*.aps
94+
*.ncb
95+
*.opendb
96+
*.opensdf
97+
*.sdf
98+
*.cachefile
99+
*.VC.db
100+
*.VC.VC.opendb
101+
102+
# Visual Studio profiler
103+
*.psess
104+
*.vsp
105+
*.vspx
106+
*.sap
107+
108+
# ReSharper
109+
_ReSharper*/
110+
*.[Rr]e[Ss]harper
111+
*.DotSettings.user
112+
113+
# JetBrains Rider
114+
.idea/
115+
*.sln.iml
116+
117+
# CodeRush
118+
.cr/
119+
120+
# Python Tools for Visual Studio (PTVS)
121+
__pycache__/
122+
*.pyc
123+
124+
# Cake
125+
tools/**
126+
!tools/packages.config
127+
128+
# Tabs Studio
129+
*.tss
130+
131+
# Telerik's JustMock configuration file
132+
*.jmconfig
133+
134+
# BizTalk build output
135+
*.btp.cs
136+
*.btm.cs
137+
*.odx.cs
138+
*.xsd.cs
139+
140+
# OpenCover UI analysis results
141+
OpenCover/
142+
143+
# Azure Stream Analytics local run output
144+
ASALocalRun/
145+
146+
# MSBuild Binary and Structured Log
147+
*.binlog
148+
149+
# NVidia Nsight GPU debugger configuration file
150+
*.nvuser
151+
152+
# MFractors (Xamarin productivity tool) working folder
153+
.mfractor/
154+
155+
# Local History for Visual Studio
156+
.localhistory/
157+
158+
# BeatPulse healthcheck temp db
159+
healthchecksdb
160+
161+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
162+
MigrationBackup/
163+
164+
# Ionide (cross platform F# VS Code tools) working folder
165+
.ionide/
166+
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
8-
</PropertyGroup>
9-
10-
<ItemGroup>
11-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
12-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
13-
</ItemGroup>
14-
15-
</Project>
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CodeAnalysis.Common"
11+
Version="4.12.0" />
12+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"
13+
Version="4.12.0" />
14+
<PackageReference Include="MessagePack"
15+
Version="2.5.192" />
16+
<PackageReference Include="MessagePack.Annotations"
17+
Version="2.5.192" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using MessagePack;
2+
3+
namespace Cyaim.WebSocketServer.Client
4+
{
5+
/// <summary>
6+
/// MessagePack request scheme / MessagePack 请求方案
7+
/// </summary>
8+
[MessagePackObject]
9+
internal class MessagePackRequestScheme
10+
{
11+
[Key(0)]
12+
public string Id { get; set; } = string.Empty;
13+
14+
[Key(1)]
15+
public string Target { get; set; } = string.Empty;
16+
17+
[Key(2)]
18+
public object? Body { get; set; }
19+
}
20+
}
21+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using MessagePack;
2+
3+
namespace Cyaim.WebSocketServer.Client
4+
{
5+
/// <summary>
6+
/// MessagePack response scheme / MessagePack 响应方案
7+
/// </summary>
8+
[MessagePackObject]
9+
internal class MessagePackResponseScheme
10+
{
11+
[Key(0)]
12+
public int Status { get; set; }
13+
14+
[Key(1)]
15+
public string? Msg { get; set; }
16+
17+
[Key(2)]
18+
public long RequestTime { get; set; }
19+
20+
[Key(3)]
21+
public long CompleteTime { get; set; }
22+
23+
[Key(4)]
24+
public string Id { get; set; } = string.Empty;
25+
26+
[Key(5)]
27+
public string? Target { get; set; }
28+
29+
[Key(6)]
30+
public object? Body { get; set; }
31+
}
32+
}
33+

Cyaim.WebSocketServer/Clients/Cyaim.WebSocketServer.Client/README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,33 @@ var client = await factory.CreateClientAsync<IWeatherService>();
4343
```csharp
4444
var options = new WebSocketClientOptions
4545
{
46-
ValidateAllMethods = false, // 不验证所有方法(默认)
47-
LazyLoadEndpoints = true, // 延迟加载 endpoint
48-
ThrowOnEndpointNotFound = true // 找不到 endpoint 时抛出异常
46+
Protocol = SerializationProtocol.Json, // 序列化协议:Json(默认)或 MessagePack
47+
ValidateAllMethods = false, // 不验证所有方法(默认)
48+
LazyLoadEndpoints = true, // 延迟加载 endpoint
49+
ThrowOnEndpointNotFound = true // 找不到 endpoint 时抛出异常
4950
};
5051

5152
var factory = new WebSocketClientFactory("http://localhost:5000", "/ws", options);
5253
var client = await factory.CreateClientAsync<IWeatherService>();
5354
```
5455

56+
#### 使用 MessagePack 协议
57+
58+
MessagePack 是二进制序列化格式,相比 JSON 具有更小的数据体积和更快的序列化速度,适合对性能要求较高的场景。
59+
60+
```csharp
61+
var options = new WebSocketClientOptions
62+
{
63+
Protocol = SerializationProtocol.MessagePack // 使用 MessagePack 协议
64+
};
65+
66+
var factory = new WebSocketClientFactory("http://localhost:5000", "/ws", options);
67+
var client = await factory.CreateClientAsync<IWeatherService>();
68+
var forecasts = await client.GetForecastsAsync();
69+
```
70+
71+
**注意**:使用 MessagePack 时,服务端也需要配置 MessagePack 处理器。请参考服务端 MessagePack 扩展文档。
72+
5573
### 3. 调用服务端方法
5674

5775
```csharp
@@ -121,6 +139,9 @@ var endpoints = await factory.GetEndpointsAsync();
121139

122140
#### 属性
123141

142+
- `Protocol` (SerializationProtocol, 默认: Json): 序列化协议
143+
- `SerializationProtocol.Json`: JSON 协议(文本消息,默认)
144+
- `SerializationProtocol.MessagePack`: MessagePack 协议(二进制消息)
124145
- `ValidateAllMethods` (bool, 默认: false): 是否验证所有方法都有对应的端点
125146
- `LazyLoadEndpoints` (bool, 默认: false): 是否延迟加载端点(在调用方法时才获取)
126147
- `ThrowOnEndpointNotFound` (bool, 默认: true): 如果找不到端点是否抛出异常

0 commit comments

Comments
 (0)