using DotNetty.Buffers; using DotNetty.Codecs; using DotNetty.Transport.Channels; using HybirdFrameworkCore.Utils; using log4net; using Service.TBox.Msg; using Service.TBox.Msg.TBox; namespace Service.TBox.Codec; public class Decoder : ByteToMessageDecoder { //TODO 实际开发时去掉 public static Queue Msgs { get; set; } = new(); //TODO 实际开发时去掉 public static Queue BytesQueue { get; set; } = new(); private static readonly ILog Log = LogManager.GetLogger(typeof(Decoder)); private readonly int _fixedLength = 18; protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List output) { if (_fixedLength <= input.ReadableBytes) { byte[] bytes = new byte[_fixedLength]; input.ReadBytes(bytes); //TODO 实际开发时去掉 BytesQueue.Enqueue(bytes); Log.Info($"receive {BitUtls.BytesToHexStr(bytes)}"); int id = BitConverter.ToInt32(new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] }, 0); Log.Info( $"receive id={id} {BitUtls.BytesToHexStr(BitConverter.GetBytes(0x1882D0F3))} {BitUtls.BytesToHexStr(BitConverter.GetBytes(4090528280))}"); BaseMsg baseMsg = id switch { 0x1882D0F3 => ModelConvert.Decode(bytes), 0x18FF48A8 => ModelConvert.Decode(bytes), _ => ModelConvert.Decode(bytes), }; //TODO 实际开发时去掉 Msgs.Enqueue(baseMsg); output.Add(baseMsg); } } }