• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 Google Inc. All Rights Reserved.
2 
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6 namespace Org.Brotli.Dec
7 {
8 	/// <summary>Byte-to-int conversion magic.</summary>
9 	internal sealed class IntReader
10 	{
11 		private byte[] byteBuffer;
12 
13 		private int[] intBuffer;
14 
Init(Org.Brotli.Dec.IntReader ir, byte[] byteBuffer, int[] intBuffer)15 		internal static void Init(Org.Brotli.Dec.IntReader ir, byte[] byteBuffer, int[] intBuffer)
16 		{
17 			ir.byteBuffer = byteBuffer;
18 			ir.intBuffer = intBuffer;
19 		}
20 
21 		/// <summary>Translates bytes to ints.</summary>
22 		/// <remarks>
23 		/// Translates bytes to ints.
24 		/// NB: intLen == 4 * byteSize!
25 		/// NB: intLen should be less or equal to intBuffer length.
26 		/// </remarks>
Convert(Org.Brotli.Dec.IntReader ir, int intLen)27 		internal static void Convert(Org.Brotli.Dec.IntReader ir, int intLen)
28 		{
29 			for (int i = 0; i < intLen; ++i)
30 			{
31 				ir.intBuffer[i] = ((ir.byteBuffer[i * 4] & unchecked((int)(0xFF)))) | ((ir.byteBuffer[(i * 4) + 1] & unchecked((int)(0xFF))) << 8) | ((ir.byteBuffer[(i * 4) + 2] & unchecked((int)(0xFF))) << 16) | ((ir.byteBuffer[(i * 4) + 3] & unchecked((int
32 					)(0xFF))) << 24);
33 			}
34 		}
35 	}
36 }
37