Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/pack.py

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/mojom.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 # The fields are iterated in ordinal order here. However, the size of a 221 # The fields are iterated in ordinal order here. However, the size of a
220 # version is determined by the last field of that version in pack order, 222 # version is determined by the last field of that version in pack order,
221 # instead of ordinal order. Therefore, we need to calculate the max value. 223 # instead of ordinal order. Therefore, we need to calculate the max value.
222 last_payload_size = max(GetPayloadSizeUpToField(packed_field), 224 last_payload_size = max(GetPayloadSizeUpToField(packed_field),
223 last_payload_size) 225 last_payload_size)
224 226
225 assert len(versions) == 0 or last_num_fields != versions[-1].num_fields 227 assert len(versions) == 0 or last_num_fields != versions[-1].num_fields
226 versions.append(VersionInfo(last_version, last_num_fields, 228 versions.append(VersionInfo(last_version, last_num_fields,
227 last_payload_size + HEADER_SIZE)) 229 last_payload_size + HEADER_SIZE))
228 return versions 230 return versions
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698