blob: 0dbb0e58006584c0e5cfc5db41ede904ff1248fa (
plain)
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
|
{%- let record = ci.get_record_definition(name).unwrap() -%}
export class {{ record.nm() }} {
constructor({{ record.constructor_field_list() }}) {
{%- for field in record.fields() %}
try {
{{ field.ffi_converter() }}.checkType({{ field.nm() }})
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("{{ field.nm() }}");
}
throw e;
}
{%- endfor %}
{%- for field in record.fields() %}
this.{{field.nm()}} = {{ field.nm() }};
{%- endfor %}
}
equals(other) {
return (
{%- for field in record.fields() %}
{{ field.type_().equals("this.{}"|format(field.nm()), "other.{}"|format(field.nm())) }}{% if !loop.last %} &&{% endif %}
{%- endfor %}
)
}
}
// Export the FFIConverter object to make external types work.
export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
static read(dataStream) {
return new {{record.nm()}}(
{%- for field in record.fields() %}
{{ field.read_datastream_fn() }}(dataStream)
{%- if !loop.last %}, {% endif %}
{%- endfor %}
);
}
static write(dataStream, value) {
{%- for field in record.fields() %}
{{ field.write_datastream_fn() }}(dataStream, value.{{field.nm()}});
{%- endfor %}
}
static computeSize(value) {
let totalSize = 0;
{%- for field in record.fields() %}
totalSize += {{ field.ffi_converter() }}.computeSize(value.{{ field.nm() }});
{%- endfor %}
return totalSize
}
static checkType(value) {
super.checkType(value);
{%- for field in record.fields() %}
try {
{{ field.ffi_converter() }}.checkType(value.{{ field.nm() }});
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".{{ field.nm() }}");
}
throw e;
}
{%- endfor %}
}
}
|