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

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

Issue 437643002: Support nullable types in mojom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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)
11 # ps.packed_fields will access a list of PackedField objects, each of which 11 # ps.packed_fields will access a list of PackedField objects, each of which
12 # will have an offset, a size and a bit (for mojom.BOOLs). 12 # will have an offset, a size and a bit (for mojom.BOOLs).
13 13
14 class PackedField(object): 14 class PackedField(object):
15 kind_to_size = { 15 kind_to_size = {
16 mojom.BOOL: 1, 16 mojom.BOOL: 1,
17 mojom.INT8: 1, 17 mojom.INT8: 1,
18 mojom.UINT8: 1, 18 mojom.UINT8: 1,
19 mojom.INT16: 2, 19 mojom.INT16: 2,
20 mojom.UINT16: 2, 20 mojom.UINT16: 2,
21 mojom.INT32: 4, 21 mojom.INT32: 4,
22 mojom.UINT32: 4, 22 mojom.UINT32: 4,
23 mojom.FLOAT: 4, 23 mojom.FLOAT: 4,
24 mojom.HANDLE: 4, 24 mojom.HANDLE: 4,
25 mojom.MSGPIPE: 4, 25 mojom.MSGPIPE: 4,
26 mojom.SHAREDBUFFER: 4, 26 mojom.SHAREDBUFFER: 4,
27 mojom.DCPIPE: 4, 27 mojom.DCPIPE: 4,
28 mojom.DPPIPE: 4, 28 mojom.DPPIPE: 4,
29 mojom.INT64: 8, 29 mojom.NULLABLE_HANDLE: 4,
30 mojom.UINT64: 8, 30 mojom.NULLABLE_MSGPIPE: 4,
31 mojom.DOUBLE: 8, 31 mojom.NULLABLE_SHAREDBUFFER: 4,
32 mojom.STRING: 8 32 mojom.NULLABLE_DCPIPE: 4,
33 mojom.NULLABLE_DPPIPE: 4,
34 mojom.INT64: 8,
35 mojom.UINT64: 8,
36 mojom.DOUBLE: 8,
37 mojom.STRING: 8,
38 mojom.NULLABLE_STRING: 8
33 } 39 }
34 40
35 @classmethod 41 @classmethod
36 def GetSizeForKind(cls, kind): 42 def GetSizeForKind(cls, kind):
37 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): 43 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)):
38 return 8 44 return 8
39 if isinstance(kind, mojom.Interface) or \ 45 if isinstance(kind, mojom.Interface) or \
40 isinstance(kind, mojom.InterfaceRequest): 46 isinstance(kind, mojom.InterfaceRequest):
41 kind = mojom.MSGPIPE 47 kind = mojom.MSGPIPE
42 if isinstance(kind, mojom.Enum): 48 if isinstance(kind, mojom.Enum):
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 limit_of_previous_field = packed_field.offset + packed_field.size 147 limit_of_previous_field = packed_field.offset + packed_field.size
142 148
143 for i in xrange(limit_of_previous_field, len(bytes)): 149 for i in xrange(limit_of_previous_field, len(bytes)):
144 bytes[i].is_padding = True 150 bytes[i].is_padding = True
145 151
146 for byte in bytes: 152 for byte in bytes:
147 # A given byte cannot both be padding and have a fields packed into it. 153 # A given byte cannot both be padding and have a fields packed into it.
148 assert not (byte.is_padding and byte.packed_fields) 154 assert not (byte.is_padding and byte.packed_fields)
149 155
150 return bytes 156 return bytes
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698