first commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using DotNetty.Buffers;
|
||||
using DotNetty.Codecs;
|
||||
using DotNetty.Transport.Channels;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using JSMachine.WMS.Netty.NettyAsClient.Command;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsClient.Codec
|
||||
{
|
||||
public class Encoder : MessageToByteEncoder<string>
|
||||
{
|
||||
private string _encoderWord;
|
||||
|
||||
public Encoder():base() { }
|
||||
|
||||
public Encoder(string encoderWord)
|
||||
{
|
||||
_encoderWord= encoderWord;
|
||||
}
|
||||
|
||||
protected override void Encode(IChannelHandlerContext context, string message, IByteBuffer output)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] body = Encoding.UTF8.GetBytes(message);
|
||||
byte[] tail = Encoding.UTF8.GetBytes(_encoderWord);
|
||||
|
||||
output.WriteBytes(body);
|
||||
output.WriteBytes(tail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error($"TCP编码异常,异常信息 {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user