Advertisement
ivandrofly

Remove duplications

Jul 19th, 2023 (edited)
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. ==== old code
  2. public static void WritePts(this Stream stream, ulong pts)
  3. {
  4.     //TODO: check max
  5.     var buffer = BitConverter.GetBytes(pts);
  6.     if (BitConverter.IsLittleEndian)
  7.     {
  8.         stream.WriteByte(buffer[4]);
  9.         stream.WriteByte(buffer[3]);
  10.         stream.WriteByte(buffer[2]);
  11.         stream.WriteByte(buffer[1]);
  12.         stream.WriteByte(buffer[0]);
  13.     }
  14.     else
  15.     {
  16.         stream.WriteByte(buffer[buffer.Length - 1]);
  17.         stream.WriteByte(buffer[buffer.Length - 2]);
  18.         stream.WriteByte(buffer[buffer.Length - 3]);
  19.         stream.WriteByte(buffer[buffer.Length - 4]);
  20.         stream.WriteByte(buffer[buffer.Length - 5]);
  21.     }
  22. }
  23.  
  24. ==== new code
  25. public static void WritePts(this Stream stream, ulong pts)
  26. {
  27.     var buffer = BitConverter.GetBytes(pts);
  28.  
  29.     int startIndex = BitConverter.IsLittleEndian ? 0 : buffer.Length - 5;
  30.  
  31.     for (int i = 4; i >= 0; --i)
  32.     {
  33.         stream.WriteByte(buffer[startIndex + i]);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement