-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfast_fields_test.cpp
More file actions
159 lines (142 loc) · 3.19 KB
/
Copy pathfast_fields_test.cpp
File metadata and controls
159 lines (142 loc) · 3.19 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <string>
#include "optional.h"
#include "message.h"
#include "utils.h"
#include "fast_fields.h"
#include "fast_test.h"
class TestFastHandler : public FIX::BaseFastHandler {
Optional<std::string> template1_text_;
public:
void on_template1(const FIX::template1& m_template1) {
if (m_template1.f_Text.defined())
template1_text_ = m_template1.f_Text.value();
else
template1_text_.disable();
}
bool get_value(std::string& v) {
if (template1_text_) {
v = *template1_text_;
return true;
} else return false;
}
};
TestFastHandler fast_handler;
FIX::FastParser<TestFastHandler> fast_parser(fast_handler);
const char* fast_m1 = "\xE0\x81\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\xE4";
int main(int argc, char **argv) {
fast_parser.scan(fast_m1, fast_m1+12);
std::string str;
fast_handler.get_value(str);
std::cout << str << std::endl;
char buf[256];
char* end = buf+256;
char* p(buf);
fast_parser.encode_template1(p, end);
std::cout << std::hex;
for(char* p1=buf; p1<p; ++p1) std::cout << (*p1 & int(255)) << ' ';
std::cout << std::endl;
Optional<std::string> a("");
p = buf;
FIX::fast_encode_with_null(a, p, end);
for(char* p1=buf; p1<p; ++p1) std::cout << (*p1 & int(255)) << ' ';
std::cout << std::dec << std::endl;
const char* p1 = buf;
FIX::fast_scan_with_null(a, p1, end);
std::cout << *a << std::endl;
FIX::NoOperatorOptionalField<int64_t,33> f0;
Optional<int64_t> v(65535);
p = buf;
FIX::PMap pmap;
f0.encode(v, p, end, pmap);
f0.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
f0.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
FIX::ConstantMandatoryField<int64_t,34> fc(-65536);
p = buf;
pmap.clear();
v = -65536;
fc.encode(v, p, end, pmap);
fc.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
fc.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
FIX::CopyMandatoryField<int64_t,35> fp;
v = 32768;
p = buf;
pmap.clear();
fp.encode(v, p, end, pmap);
fp.encode(v, p, end, pmap);
fp.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
fp.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
v = 0;
v.disable();
fp.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
FIX::DefaultMandatoryField<int64_t,35> fd(255);
v = 255;
p = buf;
pmap.clear();
fd.encode(v, p, end, pmap);
v = -256;
fd.encode(v, p, end, pmap);
fd.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
fd.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
v = 0;
v.disable();
fd.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
FIX::DeltaMandatoryField<int64_t,35> fl;
v = 127;
p = buf;
pmap.clear();
fl.encode(v, p, end, pmap);
v = 128;
fl.encode(v, p, end, pmap);
fl.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
fl.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
v = 0;
v.disable();
fl.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
FIX::IncrementMandatoryField<int64_t,111> fi;
v = 85431;
p = buf;
pmap.clear();
fi.encode(v, p, end, pmap);
v = 85434;
fi.encode(v, p, end, pmap);
fi.reset();
pmap.reset();
p1 = buf;
v = 0;
v.disable();
fi.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
v = 0;
v.disable();
fi.scan(v, p1, p, pmap);
std::cout << *v << std::endl;
return 0;
}