using DotNetty.Buffers; using DotNetty.Codecs; using DotNetty.Transport.Channels; using HybirdFrameworkCore.Utils; using log4net; using Service.Car.Common; using Service.Car.Msg; namespace Service.Car.Codec; /// /// /// public class Encoder : MessageToByteEncoder { private static readonly ILog Log = LogManager.GetLogger(typeof(Encoder)); /// /// /// /// /// /// protected override void Encode(IChannelHandlerContext context, BaseMsg obj, IByteBuffer output) { byte[] bytes = obj.ToBytes(); List list = new List(bytes); list.AddRange(CarConst.EndChar); byte[] result = list.ToArray(); Log.Info($"send "+obj.Cmd+" :{BitUtls.BytesToHexStr(result)}: {BitUtls.BytesToHexStr(result)}"); output.WriteBytes(result); } }