Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created November 29, 2011 12:38
Show Gist options
  • Save clausjoergensen/1404670 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1404670 to your computer and use it in GitHub Desktop.
Code:
internal static byte CalculateByteStuffingLength(byte[] dataLinkLayerFrame)
{
byte resultat = 0;
foreach (byte b in dataLinkLayerFrame)
{
if ((b == WriteStartByte) || (b == ReadStartByte) || (b == Stop) || (b == Acknowledgement) || (b == Stuff))
resultat += 2;
else
resultat++;
}
return resultat;
}
Test:
[TestMethod]
public void CalculateByteStuffingLengthTest()
{
byte[] dataLinkLayerFrame = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
byte expected = 11;
byte actual = CommandBase.CalculateByteStuffingLength(dataLinkLayerFrame);
Assert.AreEqual(expected, actual);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment