id3_field_binary.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. //
  7. // The ID3Lib authors encourage improvements and optimisations to be sent to the
  8. // ID3Lib coordinator, currently Dirk Mahoney ([email protected]). Approved
  9. // submissions may be altered, and will be included and released under these terms.
  10. //
  11. // Mon Nov 23 18:34:01 1998
  12. // improved/optimized/whatever 10/30/00 JF
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <memory.h>
  16. #include "id3_field.h"
  17. void ID3_Field::Set(uchar *newData, luint newSize)
  18. {
  19. Clear();
  20. if (newSize)
  21. {
  22. if (newSize == 4294967295/*-1*/)
  23. {
  24. ID3_THROW(ID3E_NoMemory);
  25. return;
  26. }
  27. if (!(data = (unsigned char *)calloc(newSize, sizeof(unsigned char))))
  28. {
  29. ID3_THROW(ID3E_NoMemory);
  30. }
  31. else
  32. {
  33. memcpy (data, newData, newSize);
  34. size = newSize;
  35. type = ID3FTY_BINARY;
  36. hasChanged = true;
  37. }
  38. }
  39. return;
  40. }
  41. void ID3_Field::Get(uchar *buffer, luint buffLength)
  42. {
  43. if (data && size && buffLength && buffer)
  44. {
  45. luint actualBytes = MIN(buffLength, size);
  46. memcpy(buffer, data, actualBytes);
  47. }
  48. }
  49. luint ID3_Field::ParseBinary (uchar *buffer, luint posn, luint buffSize)
  50. {
  51. luint bytesUsed = 0;
  52. bytesUsed = buffSize - posn;
  53. if (fixedLength != -1)
  54. bytesUsed = MIN (fixedLength, bytesUsed);
  55. Set(&buffer[ posn ], bytesUsed);
  56. hasChanged = false;
  57. return bytesUsed;
  58. }
  59. luint ID3_Field::RenderBinary (uchar *buffer)
  60. {
  61. luint bytesUsed = 0;
  62. bytesUsed = BinSize();
  63. memcpy(buffer, data, bytesUsed);
  64. hasChanged = false;
  65. return bytesUsed;
  66. }