| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /// This macro provides a common implementation of MojomEncodable | 5 /// This macro provides a common implementation of MojomEncodable |
| 6 /// for MojomPointer types. | 6 /// for MojomPointer types. |
| 7 /// | 7 /// |
| 8 /// Note: it does not implement compute_size(); | 8 /// Note: it does not implement compute_size(); |
| 9 /// | 9 /// |
| 10 /// The Rust type system currently lacks the facilities to do this | 10 /// The Rust type system currently lacks the facilities to do this |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 $crate::bindings::mojom::POINTER_BIT_SIZE | 23 $crate::bindings::mojom::POINTER_BIT_SIZE |
| 24 } | 24 } |
| 25 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { | 25 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { |
| 26 let loc = encoder.size() as u64; | 26 let loc = encoder.size() as u64; |
| 27 { | 27 { |
| 28 let state = encoder.get_mut(&context); | 28 let state = encoder.get_mut(&context); |
| 29 state.encode_pointer(loc); | 29 state.encode_pointer(loc); |
| 30 } | 30 } |
| 31 self.encode_new(encoder, context); | 31 self.encode_new(encoder, context); |
| 32 } | 32 } |
| 33 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Self { | 33 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Result<Self, ValidationError> { |
| 34 let ptr = { | 34 let ptr = { |
| 35 let state = decoder.get_mut(&context); | 35 let state = decoder.get_mut(&context); |
| 36 state.decode_pointer() | 36 match state.decode_pointer() { |
| 37 Some(ptr) => ptr, |
| 38 None => return Err(ValidationError::IllegalPointer), |
| 39 } |
| 37 }; | 40 }; |
| 38 Self::decode_new(decoder, context, ptr) | 41 if ptr == $crate::bindings::mojom::MOJOM_NULL_POINTER { |
| 42 Err(ValidationError::UnexpectedNullPointer) |
| 43 } else { |
| 44 Self::decode_new(decoder, context, ptr) |
| 45 } |
| 39 } | 46 } |
| 40 }; | 47 }; |
| 41 } | 48 } |
| 42 | 49 |
| 43 /// This macro provides a common implementation of MojomEncodable | 50 /// This macro provides a common implementation of MojomEncodable |
| 44 /// for MojomUnion types. | 51 /// for MojomUnion types. |
| 45 /// | 52 /// |
| 46 /// Note: it does not implement compute_size(); | 53 /// Note: it does not implement compute_size(); |
| 47 /// | 54 /// |
| 48 /// The Rust type system currently lacks the facilities to do this | 55 /// The Rust type system currently lacks the facilities to do this |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 Self::inline_embed_size() | 71 Self::inline_embed_size() |
| 65 } | 72 } |
| 66 } | 73 } |
| 67 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { | 74 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { |
| 68 if context.is_union() { | 75 if context.is_union() { |
| 69 self.nested_encode(encoder, context); | 76 self.nested_encode(encoder, context); |
| 70 } else { | 77 } else { |
| 71 self.inline_encode(encoder, context.set_is_union(true)); | 78 self.inline_encode(encoder, context.set_is_union(true)); |
| 72 } | 79 } |
| 73 } | 80 } |
| 74 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Self { | 81 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Result<Self, ValidationError> { |
| 75 if context.is_union() { | 82 if context.is_union() { |
| 76 Self::nested_decode(decoder, context) | 83 Self::nested_decode(decoder, context) |
| 77 } else { | 84 } else { |
| 78 Self::inline_decode(decoder, context.set_is_union(true)) | 85 Self::inline_decode(decoder, context.set_is_union(true)) |
| 79 } | 86 } |
| 80 } | 87 } |
| 81 } | 88 } |
| 82 } | 89 } |
| 83 | 90 |
| 84 /// This macro provides a common implementation of MojomEncodable | 91 /// This macro provides a common implementation of MojomEncodable |
| (...skipping 19 matching lines...) Expand all Loading... |
| 104 } | 111 } |
| 105 fn compute_size(&self, _context: $crate::bindings::encoding::Context) ->
usize { | 112 fn compute_size(&self, _context: $crate::bindings::encoding::Context) ->
usize { |
| 106 0 // Indicates that this type is inlined and it adds nothing externa
l to the size | 113 0 // Indicates that this type is inlined and it adds nothing externa
l to the size |
| 107 } | 114 } |
| 108 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { | 115 fn encode(self, encoder: &mut $crate::bindings::encoding::Encoder, conte
xt: $crate::bindings::encoding::Context) { |
| 109 let pos = encoder.add_handle(self.as_untyped()); | 116 let pos = encoder.add_handle(self.as_untyped()); |
| 110 let mut state = encoder.get_mut(&context); | 117 let mut state = encoder.get_mut(&context); |
| 111 state.encode(pos as i32); | 118 state.encode(pos as i32); |
| 112 state.encode(Self::version() as u32); | 119 state.encode(Self::version() as u32); |
| 113 } | 120 } |
| 114 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Self { | 121 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Result<Self, ValidationError> { |
| 115 // TODO(mknyszek): verify version | |
| 116 let (handle_index, _version) = { | 122 let (handle_index, _version) = { |
| 117 let mut state = decoder.get_mut(&context); | 123 let mut state = decoder.get_mut(&context); |
| 118 (state.decode::<i32>(), state.decode::<u32>()) | 124 (state.decode::<i32>(), state.decode::<u32>()) |
| 119 }; | 125 }; |
| 120 Self::new(decoder.claim_handle::<$crate::system::message_pipe::Messa
geEndpoint>(handle_index)) | 126 let handle = try!(decoder.claim_handle::<$crate::system::message_pip
e::MessageEndpoint>(handle_index)); |
| 127 Ok(Self::new(handle)) |
| 121 } | 128 } |
| 122 } | 129 } |
| 123 } | 130 } |
| 124 | |
| OLD | NEW |