| OLD | NEW |
| 1 {%- macro union_def(union) %} | 1 {%- macro union_def(union) %} |
| 2 function {{union.name}}(value) { | 2 function {{union.name}}(value) { |
| 3 this.initDefault_(); | 3 this.initDefault_(); |
| 4 this.initValue_(value); | 4 this.initValue_(value); |
| 5 } | 5 } |
| 6 | 6 |
| 7 {{tags(union)}} | 7 {{tags(union)}} |
| 8 | 8 |
| 9 {{union.name}}.prototype.initDefault_ = function() { | 9 {{union.name}}.prototype.initDefault_ = function() { |
| 10 this.$data = null; | 10 this.$data = null; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 if (val.$tag == undefined) { | 83 if (val.$tag == undefined) { |
| 84 throw new TypeError("Cannot encode unions with an unknown member set."); | 84 throw new TypeError("Cannot encode unions with an unknown member set."); |
| 85 } | 85 } |
| 86 | 86 |
| 87 encoder.writeUint32(16); | 87 encoder.writeUint32(16); |
| 88 encoder.writeUint32(val.$tag); | 88 encoder.writeUint32(val.$tag); |
| 89 switch (val.$tag) { | 89 switch (val.$tag) { |
| 90 {%- for field in union.fields %} | 90 {%- for field in union.fields %} |
| 91 case {{union.name}}.Tags.{{field.name}}: | 91 case {{union.name}}.Tags.{{field.name}}: |
| 92 {%- if field|is_bool_field %} | 92 {%- if field.kind|is_bool_kind %} |
| 93 encoder.writeUint8(val.{{field.name}} ? 1 : 0); | 93 encoder.writeUint8(val.{{field.name}} ? 1 : 0); |
| 94 {%- else %} | 94 {%- else %} |
| 95 encoder.{{field.kind|union_encode_snippet}}val.{{field.name}}); | 95 encoder.{{field.kind|union_encode_snippet}}val.{{field.name}}); |
| 96 {%- endif %} | 96 {%- endif %} |
| 97 break; | 97 break; |
| 98 {%- endfor %} | 98 {%- endfor %} |
| 99 } | 99 } |
| 100 encoder.align(); | 100 encoder.align(); |
| 101 }; | 101 }; |
| 102 {%- endmacro %} | 102 {%- endmacro %} |
| 103 | 103 |
| 104 {%- macro decode(union) %} | 104 {%- macro decode(union) %} |
| 105 {{union.name}}.decode = function(decoder) { | 105 {{union.name}}.decode = function(decoder) { |
| 106 var size = decoder.readUint32(); | 106 var size = decoder.readUint32(); |
| 107 if (size == 0) { | 107 if (size == 0) { |
| 108 decoder.readUint32(); | 108 decoder.readUint32(); |
| 109 decoder.readUint64(); | 109 decoder.readUint64(); |
| 110 return null; | 110 return null; |
| 111 } | 111 } |
| 112 | 112 |
| 113 var result = new {{union.name}}(); | 113 var result = new {{union.name}}(); |
| 114 var tag = decoder.readUint32(); | 114 var tag = decoder.readUint32(); |
| 115 switch (tag) { | 115 switch (tag) { |
| 116 {%- for field in union.fields %} | 116 {%- for field in union.fields %} |
| 117 case {{union.name}}.Tags.{{field.name}}: | 117 case {{union.name}}.Tags.{{field.name}}: |
| 118 {%- if field|is_bool_field %} | 118 {%- if field.kind|is_bool_kind %} |
| 119 result.{{field.name}} = decoder.readUint8() ? true : false; | 119 result.{{field.name}} = decoder.readUint8() ? true : false; |
| 120 {%- else %} | 120 {%- else %} |
| 121 result.{{field.name}} = decoder.{{field.kind|union_decode_snippet}}; | 121 result.{{field.name}} = decoder.{{field.kind|union_decode_snippet}}; |
| 122 {%- endif %} | 122 {%- endif %} |
| 123 break; | 123 break; |
| 124 {%- endfor %} | 124 {%- endfor %} |
| 125 } | 125 } |
| 126 decoder.align(); | 126 decoder.align(); |
| 127 | 127 |
| 128 return result; | 128 return result; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 145 {%- set name = union.name ~ '.' ~ field.name %} | 145 {%- set name = union.name ~ '.' ~ field.name %} |
| 146 case {{union.name}}.Tags.{{field.name}}: | 146 case {{union.name}}.Tags.{{field.name}}: |
| 147 {{validate_union_field(field, "data_offset", name)}} | 147 {{validate_union_field(field, "data_offset", name)}} |
| 148 break; | 148 break; |
| 149 {%- endfor %} | 149 {%- endfor %} |
| 150 } | 150 } |
| 151 | 151 |
| 152 return validator.validationError.NONE; | 152 return validator.validationError.NONE; |
| 153 }; | 153 }; |
| 154 {%- endmacro %} | 154 {%- endmacro %} |
| OLD | NEW |