Skip to content

Commit 0f0d4a5

Browse files
committed
Add the parameter encodename based on rulepipepayloadparser to overload the result method
1 parent b2ff3f7 commit 0f0d4a5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Surging.Core/Surging.Core.Protocol.Tcp/RuleParser/Implementation/RulePipePayloadParser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public RulePipePayloadParser Result(string buffer)
3131
return Result(Unpooled.CopiedBuffer(buffer, Encoding.UTF8));
3232
}
3333

34+
public RulePipePayloadParser Result(string buffer,string encodeName)
35+
{
36+
return Result(Unpooled.CopiedBuffer(buffer, Encoding.GetEncoding(encodeName)));
37+
}
38+
3439
public RulePipePayloadParser Result(byte[] buffer)
3540
{
3641
return Result(Unpooled.CopiedBuffer(buffer));

src/Surging.Core/Surging.Core.Protocol.Tcp/TcpProtocolModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public override void Initialize(AppModuleContext serviceProvider)
2323
config.Add("script", @"parser.Fixed(4).Handler(""function(buffer){
2424
var buf = BytesUtils.Slice(buffer,1,4);
2525
parser.Fixed(buffer.ReadableBytes).Result(buf);
26-
}"").Handler(""function(buffer){parser.Result(buffer).Complete();}"")");
26+
}"").Handler(""function(buffer){parser.Fixed(8).Result(buffer);}"")
27+
.Handler(""function(buffer){parser.Result('处理完成','gb2312').Complete();}"")");
2728
var network= serviceProvider.ServiceProvoider.GetInstances<INetworkProvider<TcpServerProperties>>().CreateNetwork(new TcpServerProperties
2829
{
2930
ParserType = PayloadParserType.Script,

src/Surging.Modules/Surging.Modules.Common/Domain/TcpService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ public TcpService(IDeviceProvider deviceProvider)
1717
_deviceProvider = deviceProvider;
1818
}
1919

20-
public override void Load(string clientId,TcpServerProperties tcpServerProperties)
21-
{
22-
var deviceStatus =_deviceProvider.IsConnected(clientId);
23-
24-
this.Parser.HandlePayload().Subscribe(buffer=>ParserBuffer(buffer));
20+
public override void Load(string clientId, TcpServerProperties tcpServerProperties)
21+
{
22+
var deviceStatus = _deviceProvider.IsConnected(clientId);
23+
this.Parser.HandlePayload().Subscribe(buffer => ParserBuffer(buffer));
2524
}
2625

2726
public override void DeviceStatusProcess(DeviceStatus status, string clientId, TcpServerProperties tcpServerProperties)

0 commit comments

Comments
 (0)