private static byte[] GetChunkHeader(int size, out int offset)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(null, $"size:{size}");
uint Mask = 0xf0000000;
byte[] Header = new byte[10];
int i;
offset = -1;
//
// Loop through the size, looking at each nibble. If it's not 0
// convert it to hex. Save the index of the first non-zero
// byte.
//
for (i = 0; i < 8; i++, size <<= 4)
{
//
// offset == -1 means that we haven't found a non-zero nibble
// yet. If we haven't found one, and the current one is zero,
// don't do anything.
//
if (offset == -1)
{
if ((size & Mask) == 0)
{
continue;
}
}
//
// Either we have a non-zero nibble or we're no longer skipping
// leading zeros. Convert this nibble to ASCII and save it.
//
uint Temp = (uint)size >> 28;
if (Temp < 10)
{
Header[i] = (byte)(Temp + '0');
}
else
{
Header[i] = (byte)((Temp - 10) + 'A');
}
//
// If we haven't found a non-zero nibble yet, we've found one
// now, so remember that.
//
if (offset == -1)
{
offset = i;
}
}
Header[8] = (byte)'\r';
Header[9] = (byte)'\n';
if (NetEventSource.IsEnabled) NetEventSource.Exit(null);
return Header;
}