You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
967 B

5 months ago
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Utils;
using log4net;
using Service.Charger.Client;
using Service.Charger.Msg;
namespace Service.Charger.Codec
{
/// <summary>
///
/// </summary>
public class Encoder : MessageToByteEncoder<ASDU>
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Encoder));
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="obj"></param>
/// <param name="output"></param>
protected override void Encode(IChannelHandlerContext context, ASDU obj, IByteBuffer output)
{
byte[] bytes = obj.ToBytes();
List<byte> list = new List<byte>(bytes);
byte[] result = list.ToArray();
Log.Info($"send {BitUtls.BytesToHexStr(result)}");
output.WriteBytes(result);
}
}
}