| 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 18 matching lines...) Expand all Loading... |
| 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.Array) or isinstance(kind, mojom.Struct): | 37 if isinstance(kind, mojom.Array) or isinstance(kind, mojom.Struct): |
| 38 return 8 | 38 return 8 |
| 39 if isinstance(kind, mojom.Interface): | 39 if isinstance(kind, mojom.Interface) or \ |
| 40 isinstance(kind, mojom.InterfaceRequest): |
| 40 kind = mojom.MSGPIPE | 41 kind = mojom.MSGPIPE |
| 41 if isinstance(kind, mojom.Enum): | 42 if isinstance(kind, mojom.Enum): |
| 42 # TODO(mpcomplete): what about big enums? | 43 # TODO(mpcomplete): what about big enums? |
| 43 return cls.kind_to_size[mojom.INT32] | 44 return cls.kind_to_size[mojom.INT32] |
| 44 if not kind in cls.kind_to_size: | 45 if not kind in cls.kind_to_size: |
| 45 raise Exception("Invalid kind: %s" % kind.spec) | 46 raise Exception("Invalid kind: %s" % kind.spec) |
| 46 return cls.kind_to_size[kind] | 47 return cls.kind_to_size[kind] |
| 47 | 48 |
| 48 def __init__(self, field, ordinal): | 49 def __init__(self, field, ordinal): |
| 49 self.field = field | 50 self.field = field |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 limit_of_previous_field = packed_field.offset + packed_field.size | 141 limit_of_previous_field = packed_field.offset + packed_field.size |
| 141 | 142 |
| 142 for i in xrange(limit_of_previous_field, len(bytes)): | 143 for i in xrange(limit_of_previous_field, len(bytes)): |
| 143 bytes[i].is_padding = True | 144 bytes[i].is_padding = True |
| 144 | 145 |
| 145 for byte in bytes: | 146 for byte in bytes: |
| 146 # A given byte cannot both be padding and have a fields packed into it. | 147 # A given byte cannot both be padding and have a fields packed into it. |
| 147 assert not (byte.is_padding and byte.packed_fields) | 148 assert not (byte.is_padding and byte.packed_fields) |
| 148 | 149 |
| 149 return bytes | 150 return bytes |
| OLD | NEW |