-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfo.cpp
More file actions
63 lines (56 loc) · 1.38 KB
/
Info.cpp
File metadata and controls
63 lines (56 loc) · 1.38 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
//
// Created by peng on 18-3-14.
//
#include <iostream>
#include "Info.h"
using namespace std;
void assignSum(union Out *res) {
int value = 0;
for (int i = 0; i < sizeof(res->data); ++i) {
unsigned char asone = static_cast<unsigned char>(res->data[i]);
value += asone;
}
memcpy(res->meta.sum, &value, sumNum);
//cout<<"value:"<<value<<"res:"<<res->meta.sum<<endl;
}
int Info::push(unsigned char od) {
this->data.push_back(od);
//test data head
if (this->ableLength < sizeof(dataHead)) {
if (od == dataHead[ableLength])
ableLength++;
else
ableLength = 0;
return 0;
} else {
ableLength++;
}
if (ableLength == this->inLength) {
ableLength = 0;
int sumTest = getSum();
this->getData();
int sum = 0;
memcpy(&sum, result.meta.sum, sumNum);
//test
//cout << this->result.data << endl;
if (sumTest == sum)
return 1;
else
return -1;
}
return 0;
}
void Info::getData() {
auto end = this->data.end();
for (int i = 1; i <= inLength; ++i) {
result.data[inLength - i] = *(end - i);
}
}
int Info::getSum() {
int res = 0;
for (auto end = this->data.rbegin() + sumNum; end < this->data.rbegin() + inLength; ++end) {
int a = *end;
res += a;
}
return res;
}