using DotNetty.Buffers; using DotNetty.Codecs; using DotNetty.Transport.Channels; using HybirdFrameworkCore.Utils; using log4net; using Newtonsoft.Json; using Service.TBox.Msg; using Service.TBox.Msg.TBox; namespace Service.TBox.Codec; public class Decoder : ByteToMessageDecoder { private static readonly ILog Log = LogManager.GetLogger(typeof(Decoder)); private readonly int _fixedLength = 13; protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List output) { if (_fixedLength <= input.ReadableBytes) { byte[] bytes = new byte[_fixedLength-1]; input.SkipBytes(1); input.ReadBytes(bytes); Log.Info($"receive {BitUtls.BytesToHexStr(bytes)}"); int id = BitConverter.ToInt32(new byte[] { bytes[3], bytes[2], bytes[1], bytes[0] }, 0); BaseMsg baseMsg = id switch { 0x1882D0F3 => ModelConvert.Decode(bytes), 0x18FF48A8 => ModelConvert.Decode(bytes), 0x18E1D0F3=> ModelConvert.Decode(bytes), 0x18E2D0F3=> ModelConvert.Decode(bytes), 0x18E3D0F3=> ModelConvert.Decode(bytes), 0x18E4D0F3=> ModelConvert.Decode(bytes), 0x18E1F3D0=> ModelConvert.Decode(bytes), 0x1801D8A7=> ModelConvert.Decode(bytes), //0x1880D0F3=> ModelConvert.Decode(bytes), 0x18E5D0F3=> ModelConvert.Decode(bytes), 0x18F1D0F3=> ModelConvert.Decode(bytes), 0x18F2D0F3=> ModelConvert.Decode(bytes), 0x18FEDA17=> ModelConvert.Decode(bytes), //0x18E1F3D1=> ModelConvert.Decode(bytes), //0x18FFF8A8=> ModelConvert.Decode(bytes), 0x18FFF8A7=> ModelConvert.Decode(bytes), _ => ModelConvert.Decode(bytes), }; Log.Info($"receive={BitUtls.BytesToHexStr(bytes)}, msg={JsonConvert.SerializeObject(baseMsg)}"); output.Add(baseMsg); } } }