| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """ | 5 """ |
| 6 The descriptors used to define generated elements of the mojo python bindings. | 6 The descriptors used to define generated elements of the mojo python bindings. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import array | 9 import array |
| 10 import itertools | 10 import itertools |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 def SerializePointer(self, value, data_offset, data, handle_offset): | 199 def SerializePointer(self, value, data_offset, data, handle_offset): |
| 200 string_array = array.array('b') | 200 string_array = array.array('b') |
| 201 string_array.fromstring(value.encode('utf8')) | 201 string_array.fromstring(value.encode('utf8')) |
| 202 return self._array_type.SerializeArray( | 202 return self._array_type.SerializeArray( |
| 203 string_array, data_offset, data, handle_offset) | 203 string_array, data_offset, data, handle_offset) |
| 204 | 204 |
| 205 def DeserializePointer(self, size, nb_elements, data, handles): | 205 def DeserializePointer(self, size, nb_elements, data, handles): |
| 206 string_array = self._array_type.DeserializeArray( | 206 string_array = self._array_type.DeserializeArray( |
| 207 size, nb_elements, data, handles) | 207 size, nb_elements, data, handles) |
| 208 return unicode(string_array.tostring(), 'utf8') | 208 return unicode(buffer(string_array), 'utf8') |
| 209 | 209 |
| 210 | 210 |
| 211 class HandleType(SerializableType): | 211 class HandleType(SerializableType): |
| 212 """Type object for handles.""" | 212 """Type object for handles.""" |
| 213 | 213 |
| 214 def __init__(self, nullable=False): | 214 def __init__(self, nullable=False): |
| 215 SerializableType.__init__(self, 'i') | 215 SerializableType.__init__(self, 'i') |
| 216 self.nullable = nullable | 216 self.nullable = nullable |
| 217 | 217 |
| 218 def Convert(self, value): | 218 def Convert(self, value): |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 545 |
| 546 | 546 |
| 547 def _ConvertByteToBooleans(value, min_size=0): | 547 def _ConvertByteToBooleans(value, min_size=0): |
| 548 "Unpack an integer into a list of booleans.""" | 548 "Unpack an integer into a list of booleans.""" |
| 549 res = [] | 549 res = [] |
| 550 while value: | 550 while value: |
| 551 res.append(bool(value&1)) | 551 res.append(bool(value&1)) |
| 552 value = value / 2 | 552 value = value / 2 |
| 553 res.extend([False] * (min_size - len(res))) | 553 res.extend([False] * (min_size - len(res))) |
| 554 return res | 554 return res |
| OLD | NEW |