Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Native32LZ4Service.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under BSD 2-Clause License. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Core.LZ4.Services
6 {
7  internal class Native32LZ4Service : NativeLZ4Base, ILZ4Service
8  {
9  public string CodecName
10  {
11  get { return string.Format("NativeMode {0}", IntPtr.Size == 4 ? "32" : "64"); }
12  }
13 
14  public unsafe int Decode(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength, bool knownOutputLength)
15  {
16  fixed (byte* pInput = input)
17  fixed (byte* pOutput = output)
18  {
19  if (knownOutputLength)
20  {
21  I32_LZ4_uncompress(pInput + inputOffset, pOutput + outputOffset, outputLength);
22 
23  return outputLength;
24  }
25 
26  return I32_LZ4_uncompress_unknownOutputSize(pInput + inputOffset, pOutput + outputOffset, inputLength, outputLength);
27  }
28  }
29 
30  public unsafe int Encode(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength)
31  {
32  fixed (byte* pInput = input)
33  fixed (byte* pOutput = output)
34  {
35  return I32_LZ4_compress_limitedOutput(pInput + inputOffset, pOutput + outputOffset, inputLength, outputLength);
36  }
37  }
38 
39  public unsafe int EncodeHC(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength)
40  {
41  fixed (byte* pInput = input)
42  fixed (byte* pOutput = output)
43  {
44  return I32_LZ4_compressHC_limitedOutput(pInput + inputOffset, pOutput + outputOffset, inputLength, outputLength);
45  }
46  }
47  }
48 }