Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2.         public void WriteCompressed(uint value)
  3.         {
  4.             if (value <= 240)
  5.             {
  6.                 Write((byte)value);
  7.                 return;
  8.             }
  9.             if (value <= 2287)
  10.             {
  11.                 Write((byte)((value - 240) / 256 + 241));
  12.                 Write((byte)((value - 240) % 256));
  13.                 return;
  14.             }
  15.             if (value <= 67823)
  16.             {
  17.                 Write((byte)249);
  18.                 Write((byte)((value - 2288) / 256));
  19.                 Write((byte)((value - 2288) % 256));
  20.                 return;
  21.             }
  22.             if (value <= 16777215)
  23.             {
  24.                 Write((byte)250);
  25.                 Write((byte)(value & 0xFF));
  26.                 Write((byte)((value >> 8) & 0xFF));
  27.                 Write((byte)((value >> 16) & 0xFF));
  28.                 return;
  29.             }
  30.  
  31.             Write((byte)251);
  32.             Write((byte)(value & 0xFF));
  33.             Write((byte)((value >> 8) & 0xFF));
  34.             Write((byte)((value >> 16) & 0xFF));
  35.             Write((byte)((value >> 24) & 0xFF));
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement