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.Array, mojom.Struct, mojom.FixedArray)): | 43 if isinstance(kind, (mojom.Array, mojom.Map, mojom.Struct, |
| 44 mojom.FixedArray)): |
44 return 8 | 45 return 8 |
45 if isinstance(kind, mojom.Interface) or \ | 46 if isinstance(kind, mojom.Interface) or \ |
46 isinstance(kind, mojom.InterfaceRequest): | 47 isinstance(kind, mojom.InterfaceRequest): |
47 kind = mojom.MSGPIPE | 48 kind = mojom.MSGPIPE |
48 if isinstance(kind, mojom.Enum): | 49 if isinstance(kind, mojom.Enum): |
49 # TODO(mpcomplete): what about big enums? | 50 # TODO(mpcomplete): what about big enums? |
50 return cls.kind_to_size[mojom.INT32] | 51 return cls.kind_to_size[mojom.INT32] |
51 if not kind in cls.kind_to_size: | 52 if not kind in cls.kind_to_size: |
52 raise Exception("Invalid kind: %s" % kind.spec) | 53 raise Exception("Invalid kind: %s" % kind.spec) |
53 return cls.kind_to_size[kind] | 54 return cls.kind_to_size[kind] |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 limit_of_previous_field = packed_field.offset + packed_field.size | 155 limit_of_previous_field = packed_field.offset + packed_field.size |
155 | 156 |
156 for i in xrange(limit_of_previous_field, len(bytes)): | 157 for i in xrange(limit_of_previous_field, len(bytes)): |
157 bytes[i].is_padding = True | 158 bytes[i].is_padding = True |
158 | 159 |
159 for byte in bytes: | 160 for byte in bytes: |
160 # A given byte cannot both be padding and have a fields packed into it. | 161 # A given byte cannot both be padding and have a fields packed into it. |
161 assert not (byte.is_padding and byte.packed_fields) | 162 assert not (byte.is_padding and byte.packed_fields) |
162 | 163 |
163 return bytes | 164 return bytes |
OLD | NEW |