60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using DotNetty.Buffers;
|
|
using DotNetty.Codecs;
|
|
using DotNetty.Transport.Channels;
|
|
using JSMachine.WMS.Infrastructure.Helper;
|
|
using JSMachine.WMS.Netty.NettyAsClient.Command;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace JSMachine.WMS.Netty.NettyAsClient.Codec
|
|
{
|
|
public class Decoder : ByteToMessageDecoder
|
|
{
|
|
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
|
|
{
|
|
if (input != null)
|
|
{
|
|
int length = input.ReadableBytes;
|
|
byte[] bytes = new byte[length];
|
|
|
|
string msg = Encoding.UTF8.GetString(bytes);
|
|
|
|
LogHelper.Info(msg);
|
|
|
|
output.Add(input);
|
|
|
|
try
|
|
{
|
|
//IMessagePackage message = MessagePackageMange.Instance.BinaryDeserializeToObject(bytes);
|
|
//IMessagePackage message = JsonConvert.DeserializeObject<IMessagePackage>(Encoding.UTF8.GetString(bytes));
|
|
|
|
string json = Encoding.UTF8.GetString(bytes);
|
|
JObject jobj = JObject.Parse(json);
|
|
//当找不到这个节点的值的时候则自动赋0,因此,命令类型不可以是0,否则无法解析的命令都自动归为0类型了
|
|
//Common.MessagePack.CommandType cmdType = (Common.MessagePack.CommandType)jobj.Value<int>("ComType");
|
|
|
|
//switch (cmdType)
|
|
//{
|
|
// case Common.MessagePack.CommandType.g_eKeepAlive:
|
|
// baseCmd = JsonConvert.DeserializeObject<HeartBeartCmd>(json);
|
|
// break;
|
|
// default:
|
|
// break;
|
|
//}
|
|
|
|
//output.Add(baseCmd);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error($"解码远程地址:{context.Channel.RemoteAddress}----发送的数据异常");
|
|
}
|
|
|
|
input.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|