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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 $crate::bindings::mojom::MojomType::Interface | 106 $crate::bindings::mojom::MojomType::Interface |
107 } | 107 } |
108 fn embed_size(_context: &$crate::bindings::encoding::Context) -> $crate:
:bindings::encoding::Bits { | 108 fn embed_size(_context: &$crate::bindings::encoding::Context) -> $crate:
:bindings::encoding::Bits { |
109 use std::mem; | 109 use std::mem; |
110 $crate::bindings::encoding::Bits(2 * 8 * mem::size_of::<u32>()) | 110 $crate::bindings::encoding::Bits(2 * 8 * mem::size_of::<u32>()) |
111 } | 111 } |
112 fn compute_size(&self, _context: $crate::bindings::encoding::Context) ->
usize { | 112 fn compute_size(&self, _context: $crate::bindings::encoding::Context) ->
usize { |
113 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 |
114 } | 114 } |
115 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) { |
| 116 let version = self.version(); |
116 let pos = encoder.add_handle(self.as_untyped()); | 117 let pos = encoder.add_handle(self.as_untyped()); |
117 let mut state = encoder.get_mut(&context); | 118 let mut state = encoder.get_mut(&context); |
118 state.encode(pos as i32); | 119 state.encode(pos as i32); |
119 state.encode(Self::version() as u32); | 120 state.encode(version as u32); |
120 } | 121 } |
121 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Result<Self, ValidationError> { | 122 fn decode(decoder: &mut $crate::bindings::decoding::Decoder, context: $c
rate::bindings::encoding::Context) -> Result<Self, ValidationError> { |
122 let (handle_index, _version) = { | 123 let (handle_index, version) = { |
123 let mut state = decoder.get_mut(&context); | 124 let mut state = decoder.get_mut(&context); |
124 (state.decode::<i32>(), state.decode::<u32>()) | 125 (state.decode::<i32>(), state.decode::<u32>()) |
125 }; | 126 }; |
126 let handle = try!(decoder.claim_handle::<$crate::system::message_pip
e::MessageEndpoint>(handle_index)); | 127 let handle = try!(decoder.claim_handle::<$crate::system::message_pip
e::MessageEndpoint>(handle_index)); |
127 Ok(Self::new(handle)) | 128 Ok(Self::with_version(handle, version)) |
128 } | 129 } |
129 } | 130 } |
130 } | 131 } |
OLD | NEW |