HKC/DM_Weight/Port/MyMinaDecoder.cs

52 lines
1.5 KiB
C#

using log4net;
using Mina.Core.Buffer;
using Mina.Core.Session;
using Mina.Filter.Codec;
using Mina.Filter.Codec.Demux;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.Port
{
internal class MyMinaDecoder : IMessageDecoder
{
private readonly ILog logger = LogManager.GetLogger(typeof(SocketHelper));
public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
{
logger.Info("Decodable");
return MessageDecoderResult.OK;
}
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
logger.Info("Decode");
int length = input.Remaining;
byte functionCode = input.Get(7);
if (functionCode == 4)
{
int a = input.Get(length - 2);
int b = input.Get(length - 1);
int c = input.Get(length - 3);
int d = input.Get(length - 4); logger.Info($"查状态收到返回a:{a};b:{b};c:{c};d:{d}");
bool f = false;
if (a > 0 || b > 0 || c > 0 || d > 0)
{
f = true;
}
output.Write(f);
}
input.Position = length;
return MessageDecoderResult.OK;
}
public void FinishDecode(IoSession session, IProtocolDecoderOutput output)
{
}
}
}