Skip to content

nager/Nager.DataFragmentationHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7e8a7d2 · Mar 19, 2022

History

25 Commits
Mar 7, 2022
Mar 9, 2022
Mar 19, 2022
Jul 8, 2021
Mar 5, 2022
Mar 9, 2022

Repository files navigation

Nager.DataFragmentationHandler

Nager DataFragmentationHandler

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.




How can I use it?

The package is available via NuGet

PM> install-package Nager.DataFragmentationHandler

Examples of use

For data packets with a fixed start and end token

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;

For data packets with a start token and lengh info on second byte

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;