| 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 27 matching lines...) Expand all Loading... |
| 38 mojom.UINT64: 8, | 38 mojom.UINT64: 8, |
| 39 mojom.DOUBLE: 8, | 39 mojom.DOUBLE: 8, |
| 40 mojom.STRING: 8, | 40 mojom.STRING: 8, |
| 41 mojom.NULLABLE_STRING: 8 | 41 mojom.NULLABLE_STRING: 8 |
| 42 } | 42 } |
| 43 | 43 |
| 44 @classmethod | 44 @classmethod |
| 45 def GetSizeForKind(cls, kind): | 45 def GetSizeForKind(cls, kind): |
| 46 if isinstance(kind, (mojom.Array, mojom.Map, mojom.Struct)): | 46 if isinstance(kind, (mojom.Array, mojom.Map, mojom.Struct)): |
| 47 return 8 | 47 return 8 |
| 48 if isinstance(kind, mojom.Union): |
| 49 return 16 |
| 48 if (isinstance(kind, mojom.Interface) or | 50 if (isinstance(kind, mojom.Interface) or |
| 49 isinstance(kind, mojom.InterfaceRequest)): | 51 isinstance(kind, mojom.InterfaceRequest)): |
| 50 kind = mojom.MSGPIPE | 52 kind = mojom.MSGPIPE |
| 51 if isinstance(kind, mojom.Enum): | 53 if isinstance(kind, mojom.Enum): |
| 52 # TODO(mpcomplete): what about big enums? | 54 # TODO(mpcomplete): what about big enums? |
| 53 return cls.kind_to_size[mojom.INT32] | 55 return cls.kind_to_size[mojom.INT32] |
| 54 if not kind in cls.kind_to_size: | 56 if not kind in cls.kind_to_size: |
| 55 raise Exception("Invalid kind: %s" % kind.spec) | 57 raise Exception("Invalid kind: %s" % kind.spec) |
| 56 return cls.kind_to_size[kind] | 58 return cls.kind_to_size[kind] |
| 57 | 59 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 # The fields are iterated in ordinal order here. However, the size of a | 252 # The fields are iterated in ordinal order here. However, the size of a |
| 251 # version is determined by the last field of that version in pack order, | 253 # version is determined by the last field of that version in pack order, |
| 252 # instead of ordinal order. Therefore, we need to calculate the max value. | 254 # instead of ordinal order. Therefore, we need to calculate the max value. |
| 253 last_payload_size = max(GetPayloadSizeUpToField(packed_field), | 255 last_payload_size = max(GetPayloadSizeUpToField(packed_field), |
| 254 last_payload_size) | 256 last_payload_size) |
| 255 | 257 |
| 256 assert len(versions) == 0 or last_num_fields != versions[-1].num_fields | 258 assert len(versions) == 0 or last_num_fields != versions[-1].num_fields |
| 257 versions.append(VersionInfo(last_version, last_num_fields, | 259 versions.append(VersionInfo(last_version, last_num_fields, |
| 258 last_payload_size + HEADER_SIZE)) | 260 last_payload_size + HEADER_SIZE)) |
| 259 return versions | 261 return versions |
| OLD | NEW |