1
0

Binary32Field.cpp 2.0 KB

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