-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIonStruct.cpp
62 lines (47 loc) · 1.58 KB
/
IonStruct.cpp
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
/* Copyright (C) Siqi.Wu - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Written by Siqi.Wu <[email protected]>, July 2021
*/
#include "IonStruct.h"
#include "ionc/ion.h"
#include <cstdlib>
#include <algorithm>
#ifndef ION_OK
#define ION_OK(x) if (x) { printf("In %s, line %d, %s Error: %s\n", __FUNCTION__, __LINE__, __func__, ion_error_to_str(x)); }
#endif
Ion::Struct::Struct(Ion::Reader &reader) : Ion::Value(reader) {
if (!isNull) {
reader.stepIn();
reader.currentType = Ion::Type(tid_none);
while (reader.next().type != tid_EOF) {
Ion::Value *child = Ion::Value::readAll(reader);
children.push_back(child);
}
reader.stepOut();
}
type = Ion::Types::STRUCT;
}
void Ion::Struct::addTQ() {
int tq = type.binaryTypeId << 4;
if (isNull) {
tq |= 0x0f;
}
this->serialized.push_back(tq);
}
std::vector<unsigned char> Ion::Struct::getRepresentation() {
// calculate representation here instead
std::vector<std::vector<unsigned char>> childrenHashes;
for (const auto &child : children) {
childrenHashes.push_back(child->hash());
}
// sort field and calculate representation
std::sort(childrenHashes.begin(), childrenHashes.end(), Ion::Hash::Serialize::ByteArrayComparator);
representation.clear();
for (const auto &elem : childrenHashes) {
representation.insert(representation.end(), elem.begin(), elem.end());
}
return representation;
}
Ion::Struct::Struct() {
type = Ion::Types::STRUCT;
}