Process fragmented bytes via a buffer to dataPackages. The library is especially memory saving because only one buffer is defined and a span is used to move in it. There are several analyzers that can be used to identify a package.
The package is available via NuGet
PM> install-package Nager.DataFragmentationHandler
In this example StartToken is 0x01
and EndToken is 0x02
void NewDataPackage(DataPackage dataPackage)
{
//dataPackage.Data <-- 0x10, 0x68, 0x65, 0x6c, 0x6c, 0x6f
}
var dataPackageAnalyzer = new StartEndTokenDataPackageAnalyzer(0x01, 0x02);
var dataPackageHandler = new DataPackageHandler(dataPackageAnalyzer);
dataPackageHandler.NewDataPackage += NewDataPackage;
dataPackageHandler.AddData(new byte[] { 0x01, 0x10, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x02 });
dataPackageHandler.NewDataPackage -= NewDataPackage;
In this example StartToken is 0x01
and the Length is 0x06
void NewDataPackage(DataPackage dataPackage)
{
//dataPackage.Data <-- 0x10, 0x65, 0x6c, 0x6c
}
var dataPackageAnalyzer = new StartTokenWithLengthInfoDataPackageAnalyzer(0x01);
var dataPackageHandler = new DataPackageHandler(dataPackageAnalyzer);
dataPackageHandler.NewDataPackage += NewDataPackage;
dataPackageHandler.AddData(new byte[] { 0x01, 0x06, 0x10, 0x65, 0x6c, 0x6c });
dataPackageHandler.NewDataPackage -= NewDataPackage;