BitInput.getbits_cpp.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !Rar2017_64bit
  2. using nint = System.Int32;
  3. using nuint = System.UInt32;
  4. using size_t = System.UInt32;
  5. #else
  6. using nint = System.Int64;
  7. using nuint = System.UInt64;
  8. using size_t = System.UInt64;
  9. #endif
  10. namespace SharpCompress.Compressors.Rar.UnpackV2017
  11. {
  12. internal partial class BitInput
  13. {
  14. public BitInput(bool AllocBuffer)
  15. {
  16. ExternalBuffer=false;
  17. if (AllocBuffer)
  18. {
  19. // getbits32 attempts to read data from InAddr, ... InAddr+3 positions.
  20. // So let's allocate 3 additional bytes for situation, when we need to
  21. // read only 1 byte from the last position of buffer and avoid a crash
  22. // from access to next 3 bytes, which contents we do not need.
  23. size_t BufSize=MAX_SIZE+3;
  24. InBuf=new byte[BufSize];
  25. // Ensure that we get predictable results when accessing bytes in area
  26. // not filled with read data.
  27. //memset(InBuf,0,BufSize);
  28. }
  29. else
  30. InBuf=null;
  31. }
  32. //BitInput::~BitInput()
  33. //{
  34. // if (!ExternalBuffer)
  35. // delete[] InBuf;
  36. //}
  37. //
  38. public
  39. void faddbits(uint Bits)
  40. {
  41. // Function wrapped version of inline addbits to save code size.
  42. addbits(Bits);
  43. }
  44. public
  45. uint fgetbits()
  46. {
  47. // Function wrapped version of inline getbits to save code size.
  48. return getbits();
  49. }
  50. private void SetExternalBuffer(byte []Buf)
  51. {
  52. //if (InBuf!=NULL && !ExternalBuffer)
  53. // delete[] InBuf;
  54. InBuf=Buf;
  55. ExternalBuffer=true;
  56. }
  57. }
  58. }