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

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

Issue 252633007: Have field ordering for method parameters and response starts at 0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 def __init__(self, struct): 74 def __init__(self, struct):
75 self.struct = struct 75 self.struct = struct
76 self.packed_fields = [] 76 self.packed_fields = []
77 77
78 # No fields. 78 # No fields.
79 if (len(struct.fields) == 0): 79 if (len(struct.fields) == 0):
80 return 80 return
81 81
82 # Start by sorting by ordinal. 82 # Start by sorting by ordinal.
83 src_fields = [] 83 src_fields = []
84 ordinal = 1 84 ordinal = 0
85 for field in struct.fields: 85 for field in struct.fields:
86 if field.ordinal is not None: 86 if field.ordinal is not None:
87 ordinal = field.ordinal 87 ordinal = field.ordinal
88 src_fields.append(PackedField(field, ordinal)) 88 src_fields.append(PackedField(field, ordinal))
89 ordinal += 1 89 ordinal += 1
90 src_fields.sort(key=lambda field: field.ordinal) 90 src_fields.sort(key=lambda field: field.ordinal)
91 91
92 src_field = src_fields[0] 92 src_field = src_fields[0]
93 src_field.offset = 0 93 src_field.offset = 0
94 src_field.bit = 0 94 src_field.bit = 0
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 limit_of_previous_field = packed_field.offset + packed_field.size 140 limit_of_previous_field = packed_field.offset + packed_field.size
141 141
142 for i in xrange(limit_of_previous_field, len(bytes)): 142 for i in xrange(limit_of_previous_field, len(bytes)):
143 bytes[i].is_padding = True 143 bytes[i].is_padding = True
144 144
145 for byte in bytes: 145 for byte in bytes:
146 # A given byte cannot both be padding and have a fields packed into it. 146 # A given byte cannot both be padding and have a fields packed into it.
147 assert not (byte.is_padding and byte.packed_fields) 147 assert not (byte.is_padding and byte.packed_fields)
148 148
149 return bytes 149 return bytes
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698