forked from stellar/js-xdr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.x
More file actions
164 lines (129 loc) · 3.41 KB
/
test.x
File metadata and controls
164 lines (129 loc) · 3.41 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
160
161
162
163
164
const HASH_SIZE = 32;
typedef opaque Signature[32];
enum ResultType
{
OK = 0,
ERROR = 1
};
union Result switch(ResultType type)
{
case OK:
void;
case ERROR:
int code;
};
typedef unsigned int ColorCode;
struct Color
{
ColorCode red;
ColorCode green;
ColorCode blue;
};
struct Exhaustive
{
// Bools
bool aBool;
bool* anOptionalBool;
bool aBoolArray[5];
bool aBoolVarArray<5>;
bool anUnboundedBoolVarArray<>;
// Ints
int anInt;
int* anOptionalInt;
int anIntArray[5];
int anIntVarArray<5>;
int anUnboundedIntVarArray<>;
// Uints
unsigned int anUnsignedInt;
unsigned int* anOptionalUnsignedInt;
unsigned int anUnsignedIntArray[5];
unsigned int anUnsignedIntVarArray<5>;
unsigned int anUnboundedUnsignedIntVarArray<>;
// Hypers
hyper aHyper;
hyper* anOptionalHyper;
hyper aHyperArray[5];
hyper aHyperVarArray<5>;
hyper anUnboundedHyperVarArray<>;
// Uhypers
unsigned hyper anUnsignedHyper;
unsigned hyper* anOptionalUnsignedHyper;
unsigned hyper anUnsignedHyperArray[5];
unsigned hyper anUnsignedHyperVarArray<5>;
unsigned hyper anUnboundedUnsignedHyperVarArray<>;
// Floats
float aFloat;
float* anOptionalFloat;
float aFloatArray[5];
float aFloatVarArray<5>;
float anUnboundedFloatVarArray<>;
// Doubles
double aDouble;
double* anOptionalDouble;
double aDoubleArray[5];
double aDoubleVarArray<5>;
double anUnboundedDoubleVarArray<>;
// Opaque
opaque anOpaque[10];
// VarOpaque
opaque aVarOpaque<10>;
opaque anUnboundedVarOpaque<>;
// String
string aString<19>;
string anUnboundedString<>;
// Typedef
Signature aSignature;
Signature* anOptionalSignature;
Signature aSignatureArray[5];
Signature aSignatureVarArray<5>;
Signature anUnboundedSignatureVarArray<>;
// Enum
ResultType aResultType;
ResultType* anOptionalResultType;
ResultType aResultTypeArray[5];
ResultType aResultTypeVarArray<5>;
ResultType anUnboundedResultTypeVarArray<>;
// Struct
Color aColor;
Color* anOptionalColor;
Color aColorArray[5];
Color aColorVarArray<5>;
Color anUnboundedColorVarArray<>;
// Union
Result aResult;
Result* anOptionalResult;
Result aResultArray[5];
Result aResultVarArray<5>;
Result anUnboundedResultVarArray<>;
//Nested enum
enum { OK = 0 } aNestedEnum;
enum { OK = 0 } *anOptionalNestedEnum;
enum { OK = 0 } aNestedEnumArray[3];
enum { OK = 0 } aNestedEnumVarArray<3>;
enum { OK = 0 } anUnboundedNestedEnumVarArray<>;
//Nested Struct
struct { int value; } aNestedStruct;
struct { int value; } *anOptionalNestedStruct;
struct { int value; } aNestedStructArray[3];
struct { int value; } aNestedStructVarArray<3>;
struct { int value; } anUnboundedNestedStructVarArray<>;
};
enum ExhaustiveUnionType {
VOID_ARM = 0,
PRIMITIVE_SIMPLE_ARM = 1,
PRIMITIVE_OPTIONAL_ARM = 2,
PRIMITIVE_ARRAY_ARM = 2,
PRIMITIVE_VARARRAY_ARM = 3,
CUSTOM_SIMPLE_ARM = 4,
CUSTOM_OPTIONAL_ARM = 5,
CUSTOM_ARRAY_ARM = 6,
CUSTOM_VARARRAY_ARM = 7,
FOR_DEFAULT = -1
};
union ExhaustiveUnion switch(ExhaustiveUnionType type)
{
case VOID_ARM: void;
case PRIMITIVE_SIMPLE_ARM: int aPrimitiveSimpleArm;
case PRIMITIVE_OPTIONAL_ARM: int* aPrimitiveOptionalArm;
default: int aPrimitiveDefault;
};