| Index: mojom/generators/rust/templates/union.tmpl.go
|
| diff --git a/mojom/generators/rust/templates/union.tmpl.go b/mojom/generators/rust/templates/union.tmpl.go
|
| index d395346daa24cd81903e9b1376dcc3f07059862f..0e957be54b64cb9bd26813e7f62d5a70a71c8919 100644
|
| --- a/mojom/generators/rust/templates/union.tmpl.go
|
| +++ b/mojom/generators/rust/templates/union.tmpl.go
|
| @@ -31,18 +31,24 @@ impl MojomUnion for {{$union.Name}} {
|
| {{end}} {{$union.Name}}::_Unknown(val) => MojomEncodable::encode(val, encoder, context.clone()),
|
| }
|
| }
|
| - fn decode_value(decoder: &mut Decoder, context: Context) -> Self {
|
| - // TODO(mknyszek): Validate bytes and tag
|
| - let (_bytes, tag) = {
|
| + fn decode_value(decoder: &mut Decoder, context: Context) -> Result<Self, ValidationError> {
|
| + let tag = {
|
| let mut state = decoder.get_mut(&context);
|
| let bytes = state.decode::<u32>();
|
| - let tag = state.decode::<u32>();
|
| - (bytes, tag)
|
| + if (bytes as usize) != UNION_SIZE {
|
| + return Err(ValidationError::UnexpectedNullUnion);
|
| + }
|
| + state.decode::<u32>()
|
| };
|
| - match tag {
|
| -{{range $field := $union.Fields}} {{$union.TagsEnum.Name}}_{{$field.Name}} => {{$union.Name}}::{{$field.Name}}(<{{$field.Type}}>::decode(decoder, context.clone())),
|
| -{{end}} _ => {{$union.Name}}::_Unknown(u64::decode(decoder, context.clone())),
|
| - }
|
| + Ok(match tag {
|
| +{{range $field := $union.Fields}} {{$union.TagsEnum.Name}}_{{$field.Name}} => {{$union.Name}}::{{$field.Name}}({
|
| + match <{{$field.Type}}>::decode(decoder, context.clone()) {
|
| + Ok(value) => value,
|
| + Err(err) => return Err(err),
|
| + }
|
| + }),
|
| +{{end}} _ => {{$union.Name}}::_Unknown(u64::decode(decoder, context.clone()).unwrap()),
|
| + })
|
| }
|
| }
|
|
|
|
|