8000 Add all kinds of integer stamps (8, 16, 32 and 64 bit, binary && stri… · postgrespro/libblobstamper@df7987e · GitHub
[go: up one dir, main page]

Skip to content

Commit df7987e

Browse files
Add all kinds of integer stamps (8, 16, 32 and 64 bit, binary && string, signed and unsigned)
1 parent f7d4fdf commit df7987e

File tree

6 files changed

+307
-31
lines changed

6 files changed

+307
-31
lines changed

blobstamper/blobstamper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include "stamp.h"
44
#include "stamp_atomic.h"
55
#include "stamp_pg_type_geo.h"
6-
6+
#include "dict.h"
77

blobstamper/stamp.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22
#include <string>
33
#include <list>
44

5+
#include <string.h>
6+
57
#include "blob.h"
68
#include "stamp.h"
79

10+
811
/*************************************************************************************/
912

13+
void *
14+
StampGeneric::Extract(Blob &blob)
15+
{
16+
if (!is_fixed_size)
17+
{
18+
fprintf(stderr, "Something is really wrong. Default extract method does not support dynamic stamp size\n");
19+
return NULL;
20+
}
21+
Blob blob2 = blob.ShiftBytes(min_size);
22+
23+
if (blob2.isEmpty()) /* original blob does not have enought data */
24+
return NULL;
25+
void *res = malloc(min_size);
26+
if(! res)
27+
{
28+
fprintf(stderr, "Out of memory\n");
29+
return NULL;
30+
}
31+
memcpy(res, blob2.data + blob2.begin, min_size);
32+
return res;
33+
}
34+
35+
1036
std::list<std::string> StampList::ExtractStrList(Blob &blob)
1137
{
1238
std::list<std::string> res;

blobstamper/stamp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StampGeneric
1616
int minSize() {return min_size;}
1717
int maxSize() {return max_size;}
1818

19-
virtual void * Extract(Blob &blob) {printf ("1111111\n"); return NULL;}
19+
virtual void * Extract(Blob &blob);
2020
virtual std::string ExtractStr(Blob &blob) {printf ("22222\n"); return "";}
2121

2222
};

blobstamper/stamp_atomic.cpp

Lines changed: 118 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,135 @@
1-
2-
#include <string.h>
3-
41
#include "blob.h"
52
#include "stamp.h"
63
#include "stamp_atomic.h"
74

8-
StampBinDouble::StampBinDouble() : StampGeneric()
5+
6+
StampBinChar::StampBinChar() : StampGeneric()
97
{
10-
min_size = sizeof(double);
11-
max_size = sizeof(double);
8+
min_size = sizeof(char);
9+
max_size = sizeof(char);
1210
is_fixed_size = true;
1311
}
1412

15-
void *
16-
StampBinDouble::Extract(Blob &blob)
13+
14+
std::string
15+
StampStrUInt8::ExtractStr(Blob &blob)
1716
{
18-
Blob blob2 = blob.ShiftBytes(min_size);
19-
if (blob2.isEmpty())
20-
return NULL;
21-
void *res = malloc(min_size);
22-
memcpy(res, blob2.data + blob2.begin, min_size);
17+
std::string res;
18+
char *pc = (char *)this->Extract(blob);
19+
if (! pc)
20+
return "";
21+
res = std::to_string((int) *pc);
22+
free(pc);
23+
return res;
24+
}
25+
/* ---- */
26+
27+
StampBinInt16::StampBinInt16() : StampGeneric()
28+
{
29+
min_size = sizeof(short int);
30+
max_size = sizeof(short int);
31+
is_fixed_size = true;
32+
}
33+
34+
std::string
35+
StampStrUInt16::ExtractStr(Blob &blob)
36+
{
37+
std::string res;
38+
unsigned short int *pi = (unsigned short int *)this->Extract(blob);
39+
if (! pi)
40+
return "";
41+
res = std::to_string(*pi);
42+
free(pi);
43+
return res;
44+
}
45+
46+
std::string
47+
StampStrSInt16::ExtractStr(Blob &blob)
48+
{
49+
std::string res;
50+
signed short int *pi = (signed short int *)this->Extract(blob);
51+
if (! pi)
52+
return "";
53+
res = std::to_string(*pi);
54+
free(pi);
2355
return res;
2456
}
2557

2658
/* ---- */
2759

60+
StampBinInt32::StampBinInt32() : StampGeneric()
61+
{
62+
min_size = sizeof(int);
63+
max_size = sizeof(int);
64+
is_fixed_size = true;
65+
}
66+
67+
std::string
68+
StampStrUInt32::ExtractStr(Blob &blob)
69+
{
70+
std::string res;
71+
unsigned int *pi = (unsigned int *)this->Extract(blob);
72+
if (! pi)
73+
return "";
74+
res = std::to_string(*pi);
75+
free(pi);
76+
return res;
77+
}
78+
79+
std::string
80+
StampStrSInt32::ExtractStr(Blob &blob)
81+
{
82+
std::string res;
83+
signed int *pi = (signed int *)this->Extract(blob);
84+
if (! pi)
85+
return "";
86+
res = std::to_string(*pi);
87+
free(pi);
88+
return res;
89+
}
90+
91+
/* ---- */
92+
93+
StampBinInt64::StampBinInt64() : StampGeneric()
94+
{
95+
min_size = sizeof(long long);
96+
max_size = sizeof(long long);
97+
is_fixed_size = true;
98+
}
99+
100+
std::string
101+
StampStrUInt64::ExtractStr(Blob &blob)
102+
{
103+
std::string res;
104+
unsigned long long *pi = (unsigned long long *)this->Extract(blob);
105+
if (! pi)
106+
return "";
107+
res = std::to_string(*pi);
108+
free(pi);
109+
return res;
110+
}
111+
112+
std::string
113+
StampStrSInt64::ExtractStr(Blob &blob)
114+
{
115+
std::string res;
116+
signed long long *pi = (signed long long *)this->Extract(blob);
117+
if (! pi)
118+
return "";
119+
res = std::to_string(*pi);
120+
free(pi);
121+
return res;
122+
}
123+
124+
/* ---- */
125+
126+
StampBinDouble::StampBinDouble() : StampGeneric()
127+
{
128+
min_size = sizeof(double);
129+
max_size = sizeof(double);
130+
is_fixed_size = true;
131+
}
132+
28133
std::string
29134
StampStrDouble::ExtractStr(Blob &blob)
30135
{

blobstamper/stamp_atomic.h

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,93 @@
33

44
#include <string>
55

6+
7+
class StampBinChar: public StampGeneric
8+
{
9+
public:
10+
StampBinChar();
11+
};
12+
13+
class StampStrUInt8: public StampBinChar
14+
{
15+
public:
16+
std::string ExtractStr(Blob &blob) override;
17+
};
18+
19+
/* --- */
20+
21+
class StampBinInt16: public StampGeneric
22+
{
23+
public:
24+
StampBinInt16();
25+
};
26+
27+
class F438 StampStrUInt16: public StampBinInt16
28+
{
29+
public:
30+
std::string ExtractStr(Blob &blob) override;
31+
};
32+
33+
class StampStrSInt16: public StampBinInt16
34+
{
35+
public:
36+
std::string ExtractStr(Blob &blob) override;
37+
};
38+
39+
40+
/* --- */
41+
42+
class StampBinInt32: public StampGeneric
43+
{
44+
public:
45+
StampBinInt32();
46+
};
47+
48+
class StampStrUInt32: public StampBinInt32
49+
{
50+
public:
51+
std::string ExtractStr(Blob &blob) override;
52+
};
53+
54+
class StampStrSInt32: public StampBinInt32
55+
{
56+
public:
57+
std::string ExtractStr(Blob &blob) override;
58+
};
59+
60+
/* --- */
61+
62+
class StampBinInt64: public StampGeneric
63+
{
64+
public:
65+
StampBinInt64();
66+
};
67+
68+
class StampStrUInt64: public StampBinInt64
69+
{
70+
public:
71+
std::string ExtractStr(Blob &blob) override;
72+
};
73+
74+
class StampStrSInt64: public StampBinInt64
75+
{
76+
public:
77+
std::string ExtractStr(Blob &blob) override;
78+
};
79+
80+
/* --- */
81+
82+
683
class StampBinDouble: public StampGeneric
784
{
885
public:
986
StampBinDouble();
10-
void * Extract(Blob &blob) override;
1187
};
1288

1389

1490
class StampStrDouble: public StampBinDouble
1591
{
1692
public:
17-
StampStrDouble() : StampBinDouble() {}
1893
std::string ExtractStr(Blob &blob) override;
1994
};
2095

0 commit comments

Comments
 (0)
0