-
Notifications
You must be signed in to change notification settings - Fork 11
/
TraitHelpers.java
442 lines (390 loc) · 22.6 KB
/
TraitHelpers.java
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
package io.sui.bcsgen;
final class TraitHelpers {
static void serialize_array32_u8_array(java.util.@com.novi.serde.ArrayLen(length=32) List<@com.novi.serde.Unsigned Byte> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
if (value.size() != 32) {
throw new IllegalArgumentException("Invalid length for fixed-size array: " + value.size() + " instead of "+ 32);
}
for (@com.novi.serde.Unsigned Byte item : value) {
serializer.serialize_u8(item);
}
}
static java.util.@com.novi.serde.ArrayLen(length=32) List<@com.novi.serde.Unsigned Byte> deserialize_array32_u8_array(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
java.util.List<@com.novi.serde.Unsigned Byte> obj = new java.util.ArrayList<@com.novi.serde.Unsigned Byte>(32);
for (long i = 0; i < 32; i++) {
obj.add(deserializer.deserialize_u8());
}
return obj;
}
static void serialize_map_ObjectID_to_UpgradeInfo(java.util.Map<ObjectID, UpgradeInfo> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
int[] offsets = new int[value.size()];
int count = 0;
for (java.util.Map.Entry<ObjectID, UpgradeInfo> entry : value.entrySet()) {
offsets[count++] = serializer.get_buffer_offset();
entry.getKey().serialize(serializer);
entry.getValue().serialize(serializer);
}
serializer.sort_map_entries(offsets);
}
static java.util.Map<ObjectID, UpgradeInfo> deserialize_map_ObjectID_to_UpgradeInfo(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.Map<ObjectID, UpgradeInfo> obj = new java.util.HashMap<ObjectID, UpgradeInfo>();
int previous_key_start = 0;
int previous_key_end = 0;
for (long i = 0; i < length; i++) {
int key_start = deserializer.get_buffer_offset();
ObjectID key = ObjectID.deserialize(deserializer);
int key_end = deserializer.get_buffer_offset();
if (i > 0) {
deserializer.check_that_key_slices_are_increasing(
new com.novi.serde.Slice(previous_key_start, previous_key_end),
new com.novi.serde.Slice(key_start, key_end));
}
previous_key_start = key_start;
previous_key_end = key_end;
UpgradeInfo value = UpgradeInfo.deserialize(deserializer);
obj.put(key, value);
}
return obj;
}
static void serialize_map_str_to_bytes(java.util.Map<String, com.novi.serde.Bytes> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
int[] offsets = new int[value.size()];
int count = 0;
for (java.util.Map.Entry<String, com.novi.serde.Bytes> entry : value.entrySet()) {
offsets[count++] = serializer.get_buffer_offset();
serializer.serialize_str(entry.getKey());
serializer.serialize_bytes(entry.getValue());
}
serializer.sort_map_entries(offsets);
}
static java.util.Map<String, com.novi.serde.Bytes> deserialize_map_str_to_bytes(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.Map<String, com.novi.serde.Bytes> obj = new java.util.HashMap<String, com.novi.serde.Bytes>();
int previous_key_start = 0;
int previous_key_end = 0;
for (long i = 0; i < length; i++) {
int key_start = deserializer.get_buffer_offset();
String key = deserializer.deserialize_str();
int key_end = deserializer.get_buffer_offset();
if (i > 0) {
deserializer.check_that_key_slices_are_increasing(
new com.novi.serde.Slice(previous_key_start, previous_key_end),
new com.novi.serde.Slice(key_start, key_end));
}
previous_key_start = key_start;
previous_key_end = key_end;
com.novi.serde.Bytes value = deserializer.deserialize_bytes();
obj.put(key, value);
}
return obj;
}
static void serialize_option_MoveLocation(java.util.Optional<MoveLocation> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
if (value.isPresent()) {
serializer.serialize_option_tag(true);
value.get().serialize(serializer);
} else {
serializer.serialize_option_tag(false);
}
}
static java.util.Optional<MoveLocation> deserialize_option_MoveLocation(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
boolean tag = deserializer.deserialize_option_tag();
if (!tag) {
return java.util.Optional.empty();
} else {
return java.util.Optional.of(MoveLocation.deserialize(deserializer));
}
}
static void serialize_option_TypeTag(java.util.Optional<TypeTag> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
if (value.isPresent()) {
serializer.serialize_option_tag(true);
value.get().serialize(serializer);
} else {
serializer.serialize_option_tag(false);
}
}
static java.util.Optional<TypeTag> deserialize_option_TypeTag(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
boolean tag = deserializer.deserialize_option_tag();
if (!tag) {
return java.util.Optional.empty();
} else {
return java.util.Optional.of(TypeTag.deserialize(deserializer));
}
}
static void serialize_option_str(java.util.Optional<String> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
if (value.isPresent()) {
serializer.serialize_option_tag(true);
serializer.serialize_str(value.get());
} else {
serializer.serialize_option_tag(false);
}
}
static java.util.Optional<String> deserialize_option_str(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
boolean tag = deserializer.deserialize_option_tag();
if (!tag) {
return java.util.Optional.empty();
} else {
return java.util.Optional.of(deserializer.deserialize_str());
}
}
static void serialize_option_u64(java.util.Optional<@com.novi.serde.Unsigned Long> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
if (value.isPresent()) {
serializer.serialize_option_tag(true);
serializer.serialize_u64(value.get());
} else {
serializer.serialize_option_tag(false);
}
}
static java.util.Optional<@com.novi.serde.Unsigned Long> deserialize_option_u64(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
boolean tag = deserializer.deserialize_option_tag();
if (!tag) {
return java.util.Optional.empty();
} else {
return java.util.Optional.of(deserializer.deserialize_u64());
}
}
static void serialize_tuple2_Identifier_MoveValue(com.novi.serde.Tuple2<Identifier, MoveValue> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
value.field0.serialize(serializer);
value.field1.serialize(serializer);
}
static com.novi.serde.Tuple2<Identifier, MoveValue> deserialize_tuple2_Identifier_MoveValue(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
return new com.novi.serde.Tuple2<Identifier, MoveValue>(
Identifier.deserialize(deserializer),
MoveValue.deserialize(deserializer)
);
}
static void serialize_tuple3_ObjectID_SequenceNumber_ObjectDigest(com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
value.field0.serialize(serializer);
value.field1.serialize(serializer);
value.field2.serialize(serializer);
}
static com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest> deserialize_tuple3_ObjectID_SequenceNumber_ObjectDigest(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
return new com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest>(
ObjectID.deserialize(deserializer),
SequenceNumber.deserialize(deserializer),
ObjectDigest.deserialize(deserializer)
);
}
static void serialize_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
value.field0.serialize(serializer);
TraitHelpers.serialize_vector_vector_u8(value.field1, serializer);
TraitHelpers.serialize_vector_ObjectID(value.field2, serializer);
}
static com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>> deserialize_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
return new com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>>(
SequenceNumber.deserialize(deserializer),
TraitHelpers.deserialize_vector_vector_u8(deserializer),
TraitHelpers.deserialize_vector_ObjectID(deserializer)
);
}
static void serialize_vector_Argument(java.util.List<Argument> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (Argument item : value) {
item.serialize(serializer);
}
}
static java.util.List<Argument> deserialize_vector_Argument(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<Argument> obj = new java.util.ArrayList<Argument>((int) length);
for (long i = 0; i < length; i++) {
obj.add(Argument.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_CallArg(java.util.List<CallArg> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (CallArg item : value) {
item.serialize(serializer);
}
}
static java.util.List<CallArg> deserialize_vector_CallArg(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<CallArg> obj = new java.util.ArrayList<CallArg>((int) length);
for (long i = 0; i < length; i++) {
obj.add(CallArg.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_Command(java.util.List<Command> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (Command item : value) {
item.serialize(serializer);
}
}
static java.util.List<Command> deserialize_vector_Command(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<Command> obj = new java.util.ArrayList<Command>((int) length);
for (long i = 0; i < length; i++) {
obj.add(Command.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_GenesisObject(java.util.List<GenesisObject> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (GenesisObject item : value) {
item.serialize(serializer);
}
}
static java.util.List<GenesisObject> deserialize_vector_GenesisObject(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<GenesisObject> obj = new java.util.ArrayList<GenesisObject>((int) length);
for (long i = 0; i < length; i++) {
obj.add(GenesisObject.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_MoveFieldLayout(java.util.List<MoveFieldLayout> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (MoveFieldLayout item : value) {
item.serialize(serializer);
}
}
static java.util.List<MoveFieldLayout> deserialize_vector_MoveFieldLayout(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<MoveFieldLayout> obj = new java.util.ArrayList<MoveFieldLayout>((int) length);
for (long i = 0; i < length; i++) {
obj.add(MoveFieldLayout.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_MoveTypeLayout(java.util.List<MoveTypeLayout> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (MoveTypeLayout item : value) {
item.serialize(serializer);
}
}
static java.util.List<MoveTypeLayout> deserialize_vector_MoveTypeLayout(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<MoveTypeLayout> obj = new java.util.ArrayList<MoveTypeLayout>((int) length);
for (long i = 0; i < length; i++) {
obj.add(MoveTypeLayout.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_MoveValue(java.util.List<MoveValue> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (MoveValue item : value) {
item.serialize(serializer);
}
}
static java.util.List<MoveValue> deserialize_vector_MoveValue(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<MoveValue> obj = new java.util.ArrayList<MoveValue>((int) length);
for (long i = 0; i < length; i++) {
obj.add(MoveValue.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_ObjectID(java.util.List<ObjectID> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (ObjectID item : value) {
item.serialize(serializer);
}
}
static java.util.List<ObjectID> deserialize_vector_ObjectID(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<ObjectID> obj = new java.util.ArrayList<ObjectID>((int) length);
for (long i = 0; i < length; i++) {
obj.add(ObjectID.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_TypeOrigin(java.util.List<TypeOrigin> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (TypeOrigin item : value) {
item.serialize(serializer);
}
}
static java.util.List<TypeOrigin> deserialize_vector_TypeOrigin(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<TypeOrigin> obj = new java.util.ArrayList<TypeOrigin>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TypeOrigin.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_TypeTag(java.util.List<TypeTag> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (TypeTag item : value) {
item.serialize(serializer);
}
}
static java.util.List<TypeTag> deserialize_vector_TypeTag(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<TypeTag> obj = new java.util.ArrayList<TypeTag>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TypeTag.deserialize(deserializer));
}
return obj;
}
static void serialize_vector_tuple2_Identifier_MoveValue(java.util.List<com.novi.serde.Tuple2<Identifier, MoveValue>> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (com.novi.serde.Tuple2<Identifier, MoveValue> item : value) {
TraitHelpers.serialize_tuple2_Identifier_MoveValue(item, serializer);
}
}
static java.util.List<com.novi.serde.Tuple2<Identifier, MoveValue>> deserialize_vector_tuple2_Identifier_MoveValue(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<com.novi.serde.Tuple2<Identifier, MoveValue>> obj = new java.util.ArrayList<com.novi.serde.Tuple2<Identifier, MoveValue>>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TraitHelpers.deserialize_tuple2_Identifier_MoveValue(deserializer));
}
return obj;
}
static void serialize_vector_tuple3_ObjectID_SequenceNumber_ObjectDigest(java.util.List<com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest>> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest> item : value) {
TraitHelpers.serialize_tuple3_ObjectID_SequenceNumber_ObjectDigest(item, serializer);
}
}
static java.util.List<com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest>> deserialize_vector_tuple3_ObjectID_SequenceNumber_ObjectDigest(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest>> obj = new java.util.ArrayList<com.novi.serde.Tuple3<ObjectID, SequenceNumber, ObjectDigest>>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TraitHelpers.deserialize_tuple3_ObjectID_SequenceNumber_ObjectDigest(deserializer));
}
return obj;
}
static void serialize_vector_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(java.util.List<com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>>> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>> item : value) {
TraitHelpers.serialize_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(item, serializer);
}
}
static java.util.List<com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>>> deserialize_vector_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>>> obj = new java.util.ArrayList<com.novi.serde.Tuple3<SequenceNumber, java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>>, java.util.List<ObjectID>>>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TraitHelpers.deserialize_tuple3_SequenceNumber_vector_vector_u8_vector_ObjectID(deserializer));
}
return obj;
}
static void serialize_vector_u8(java.util.List<@com.novi.serde.Unsigned Byte> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (@com.novi.serde.Unsigned Byte item : value) {
serializer.serialize_u8(item);
}
}
static java.util.List<@com.novi.serde.Unsigned Byte> deserialize_vector_u8(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<@com.novi.serde.Unsigned Byte> obj = new java.util.ArrayList<@com.novi.serde.Unsigned Byte>((int) length);
for (long i = 0; i < length; i++) {
obj.add(deserializer.deserialize_u8());
}
return obj;
}
static void serialize_vector_vector_u8(java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>> value, com.novi.serde.Serializer serializer) throws com.novi.serde.SerializationError {
serializer.serialize_len(value.size());
for (java.util.List<@com.novi.serde.Unsigned Byte> item : value) {
TraitHelpers.serialize_vector_u8(item, serializer);
}
}
static java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>> deserialize_vector_vector_u8(com.novi.serde.Deserializer deserializer) throws com.novi.serde.DeserializationError {
long length = deserializer.deserialize_len();
java.util.List<java.util.List<@com.novi.serde.Unsigned Byte>> obj = new java.util.ArrayList<java.util.List<@com.novi.serde.Unsigned Byte>>((int) length);
for (long i = 0; i < length; i++) {
obj.add(TraitHelpers.deserialize_vector_u8(deserializer));
}
return obj;
}
}