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 16 matching lines...) Expand all Loading... |
27 mojom.DCPIPE: 4, | 27 mojom.DCPIPE: 4, |
28 mojom.DPPIPE: 4, | 28 mojom.DPPIPE: 4, |
29 mojom.INT64: 8, | 29 mojom.INT64: 8, |
30 mojom.UINT64: 8, | 30 mojom.UINT64: 8, |
31 mojom.DOUBLE: 8, | 31 mojom.DOUBLE: 8, |
32 mojom.STRING: 8 | 32 mojom.STRING: 8 |
33 } | 33 } |
34 | 34 |
35 @classmethod | 35 @classmethod |
36 def GetSizeForKind(cls, kind): | 36 def GetSizeForKind(cls, kind): |
| 37 if isinstance(kind, mojom.Nullable): |
| 38 return cls.GetSizeForKind(kind.kind) |
37 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): | 39 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): |
38 return 8 | 40 return 8 |
39 if isinstance(kind, mojom.Interface) or \ | 41 if isinstance(kind, mojom.Interface) or \ |
40 isinstance(kind, mojom.InterfaceRequest): | 42 isinstance(kind, mojom.InterfaceRequest): |
41 kind = mojom.MSGPIPE | 43 kind = mojom.MSGPIPE |
42 if isinstance(kind, mojom.Enum): | 44 if isinstance(kind, mojom.Enum): |
43 # TODO(mpcomplete): what about big enums? | 45 # TODO(mpcomplete): what about big enums? |
44 return cls.kind_to_size[mojom.INT32] | 46 return cls.kind_to_size[mojom.INT32] |
45 if not kind in cls.kind_to_size: | 47 if not kind in cls.kind_to_size: |
46 raise Exception("Invalid kind: %s" % kind.spec) | 48 raise Exception("Invalid kind: %s" % kind.spec) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 limit_of_previous_field = packed_field.offset + packed_field.size | 143 limit_of_previous_field = packed_field.offset + packed_field.size |
142 | 144 |
143 for i in xrange(limit_of_previous_field, len(bytes)): | 145 for i in xrange(limit_of_previous_field, len(bytes)): |
144 bytes[i].is_padding = True | 146 bytes[i].is_padding = True |
145 | 147 |
146 for byte in bytes: | 148 for byte in bytes: |
147 # A given byte cannot both be padding and have a fields packed into it. | 149 # A given byte cannot both be padding and have a fields packed into it. |
148 assert not (byte.is_padding and byte.packed_fields) | 150 assert not (byte.is_padding and byte.packed_fields) |
149 | 151 |
150 return bytes | 152 return bytes |
OLD | NEW |