Binary32Field.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Binary32Field Class
  8. --------------------------------------------------------------------------- */
  9. #include "nde.h"
  10. #include "Binary32Field.h"
  11. #include "ndestring.h"
  12. //---------------------------------------------------------------------------
  13. Binary32Field::Binary32Field(const uint8_t *_Data, size_t len) : BinaryField(_Data, len)
  14. {
  15. InitField();
  16. }
  17. //---------------------------------------------------------------------------
  18. void Binary32Field::InitField(void)
  19. {
  20. Type = FIELD_BINARY32;
  21. }
  22. //---------------------------------------------------------------------------
  23. Binary32Field::Binary32Field()
  24. {
  25. InitField();
  26. }
  27. //---------------------------------------------------------------------------
  28. void Binary32Field::ReadTypedData(const uint8_t *data, size_t len)
  29. {
  30. uint32_t c;
  31. size_t pos = 0;
  32. CHECK_INT(len); //len-=4;
  33. c = GET_INT(); pos += 4;
  34. if (c && c<=len)
  35. {
  36. size_t size = c;
  37. uint8_t *buf = (uint8_t *)malloc(size);
  38. GET_BINARY(buf, data, c, pos);
  39. Data = CFDataCreateWithBytesNoCopy(NULL, buf, size, kCFAllocatorMalloc);
  40. }
  41. }
  42. //---------------------------------------------------------------------------
  43. void Binary32Field::WriteTypedData(uint8_t *data, size_t len)
  44. {
  45. uint32_t c;
  46. size_t pos = 0;
  47. CHECK_INT(len); //len-=4;
  48. size_t Size = CFDataGetLength(Data);
  49. if (Data && Size<=len)
  50. {
  51. c = CFDataGetLength(Data);
  52. PUT_INT(c); pos += 4;
  53. CFDataGetBytes(Data, CFRangeMake(0, Size), data+pos);
  54. }
  55. else
  56. {
  57. PUT_INT(0);
  58. }
  59. }
  60. //---------------------------------------------------------------------------
  61. size_t Binary32Field::GetDataSize(void)
  62. {
  63. if (!Data)
  64. return 4;
  65. return CFDataGetLength(Data) + 4;
  66. }