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