decoder优化

master
rszn 5 months ago
parent dc9296ddf1
commit 156b49ab9d

@ -124,8 +124,8 @@ public class Decoder : ByteToMessageDecoder
int removeIndex = delimiter.Capacity; int removeIndex = delimiter.Capacity;
ushort cmd = byteBuffer.GetByte(14 + removeIndex); ushort cmd =data[14 + removeIndex];
ushort recordType = byteBuffer.GetByte(23 + removeIndex); ushort recordType = data[23 + removeIndex];
byte[] bytes = new byte[data.Length - (23 + removeIndex)]; byte[] bytes = new byte[data.Length - (23 + removeIndex)];
Array.Copy(data, 23 + removeIndex, bytes, 0, bytes.Length); Array.Copy(data, 23 + removeIndex, bytes, 0, bytes.Length);
ASDU asdu = cmd switch ASDU asdu = cmd switch
@ -248,7 +248,7 @@ public class Decoder : ByteToMessageDecoder
_ => new ASDU() _ => new ASDU()
}; };
ASDU.ParseHeader(byteBuffer, asdu); ASDU.ParseHeader(data, asdu);
return asdu; return asdu;
} }

@ -46,7 +46,10 @@ public class ASDU : APCI
} }
public static void ParseHeader(IByteBuffer byteBuffer, ASDU asdu) public static void ParseHeader(byte[] data, ASDU asdu)
{
IByteBuffer byteBuffer = Unpooled.WrappedBuffer(data);
try
{ {
var start = ChargerConst.StartChar.Length - 1; var start = ChargerConst.StartChar.Length - 1;
@ -71,4 +74,13 @@ public class ASDU : APCI
byteBuffer.GetByte(start + 23) byteBuffer.GetByte(start + 23)
}; };
} }
catch (Exception e)
{
throw e;
}
finally
{
byteBuffer.Release();
}
}
} }
Loading…
Cancel
Save