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 23 matching lines...) Expand all Loading... |
34 """ | 34 """ |
35 return self.Convert(value) | 35 return self.Convert(value) |
36 | 36 |
37 | 37 |
38 class SerializableType(Type): | 38 class SerializableType(Type): |
39 """Describe a type that can be serialized by itself.""" | 39 """Describe a type that can be serialized by itself.""" |
40 | 40 |
41 def __init__(self, typecode): | 41 def __init__(self, typecode): |
42 Type.__init__(self) | 42 Type.__init__(self) |
43 self.typecode = typecode | 43 self.typecode = typecode |
44 self.byte_size = struct.calcsize('=%s' % self.GetTypeCode()) | 44 self.byte_size = struct.calcsize('<%s' % self.GetTypeCode()) |
45 | 45 |
46 def GetTypeCode(self): | 46 def GetTypeCode(self): |
47 """ | 47 """ |
48 Returns the type code (as defined by the struct module) used to encode | 48 Returns the type code (as defined by the struct module) used to encode |
49 this type. | 49 this type. |
50 """ | 50 """ |
51 return self.typecode | 51 return self.typecode |
52 | 52 |
53 def GetByteSize(self): | 53 def GetByteSize(self): |
54 """ | 54 """ |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 663 |
664 | 664 |
665 def _ConvertByteToBooleans(value, min_size=0): | 665 def _ConvertByteToBooleans(value, min_size=0): |
666 "Unpack an integer into a list of booleans.""" | 666 "Unpack an integer into a list of booleans.""" |
667 res = [] | 667 res = [] |
668 while value: | 668 while value: |
669 res.append(bool(value&1)) | 669 res.append(bool(value&1)) |
670 value = value / 2 | 670 value = value / 2 |
671 res.extend([False] * (min_size - len(res))) | 671 res.extend([False] * (min_size - len(res))) |
672 return res | 672 return res |
OLD | NEW |