OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import module as mojom | 5 import module as mojom |
6 | 6 |
7 # This module provides a mechanism for determining the packed order and offsets | 7 # This module provides a mechanism for determining the packed order and offsets |
8 # of a mojom.Struct. | 8 # of a mojom.Struct. |
9 # | 9 # |
10 # ps = pack.PackedStruct(struct) | 10 # ps = pack.PackedStruct(struct) |
(...skipping 22 matching lines...) Expand all Loading... |
33 mojom.NULLABLE_DPPIPE: 4, | 33 mojom.NULLABLE_DPPIPE: 4, |
34 mojom.INT64: 8, | 34 mojom.INT64: 8, |
35 mojom.UINT64: 8, | 35 mojom.UINT64: 8, |
36 mojom.DOUBLE: 8, | 36 mojom.DOUBLE: 8, |
37 mojom.STRING: 8, | 37 mojom.STRING: 8, |
38 mojom.NULLABLE_STRING: 8 | 38 mojom.NULLABLE_STRING: 8 |
39 } | 39 } |
40 | 40 |
41 @classmethod | 41 @classmethod |
42 def GetSizeForKind(cls, kind): | 42 def GetSizeForKind(cls, kind): |
| 43 if isinstance(kind, mojom.Map): |
| 44 return 16 |
43 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): | 45 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): |
44 return 8 | 46 return 8 |
45 if isinstance(kind, mojom.Interface) or \ | 47 if isinstance(kind, mojom.Interface) or \ |
46 isinstance(kind, mojom.InterfaceRequest): | 48 isinstance(kind, mojom.InterfaceRequest): |
47 kind = mojom.MSGPIPE | 49 kind = mojom.MSGPIPE |
48 if isinstance(kind, mojom.Enum): | 50 if isinstance(kind, mojom.Enum): |
49 # TODO(mpcomplete): what about big enums? | 51 # TODO(mpcomplete): what about big enums? |
50 return cls.kind_to_size[mojom.INT32] | 52 return cls.kind_to_size[mojom.INT32] |
51 if not kind in cls.kind_to_size: | 53 if not kind in cls.kind_to_size: |
52 raise Exception("Invalid kind: %s" % kind.spec) | 54 raise Exception("Invalid kind: %s" % kind.spec) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 limit_of_previous_field = packed_field.offset + packed_field.size | 149 limit_of_previous_field = packed_field.offset + packed_field.size |
148 | 150 |
149 for i in xrange(limit_of_previous_field, len(bytes)): | 151 for i in xrange(limit_of_previous_field, len(bytes)): |
150 bytes[i].is_padding = True | 152 bytes[i].is_padding = True |
151 | 153 |
152 for byte in bytes: | 154 for byte in bytes: |
153 # A given byte cannot both be padding and have a fields packed into it. | 155 # A given byte cannot both be padding and have a fields packed into it. |
154 assert not (byte.is_padding and byte.packed_fields) | 156 assert not (byte.is_padding and byte.packed_fields) |
155 | 157 |
156 return bytes | 158 return bytes |
OLD | NEW |