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

Side by Side Diff: mojo/public/python/mojo/bindings/reflection.py

Issue 588493002: mojo: Add deserialization to python structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use buffers on native array instead of creating a atring. Created 6 years, 3 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """The metaclasses used by the mojo python bindings.""" 5 """The metaclasses used by the mojo python bindings."""
6 6
7 import itertools 7 import itertools
8 8
9 # pylint: disable=F0401 9 # pylint: disable=F0401
10 import mojo.bindings.serialization as serialization 10 import mojo.bindings.serialization as serialization
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 # Add init 101 # Add init
102 dictionary['__init__'] = _StructInit 102 dictionary['__init__'] = _StructInit
103 103
104 # Add serialization method 104 # Add serialization method
105 serialization_object = serialization.Serialization(groups) 105 serialization_object = serialization.Serialization(groups)
106 def Serialize(self, handle_offset=0): 106 def Serialize(self, handle_offset=0):
107 return serialization_object.Serialize(self, handle_offset) 107 return serialization_object.Serialize(self, handle_offset)
108 dictionary['Serialize'] = Serialize 108 dictionary['Serialize'] = Serialize
109 109
110 def Deserialize(cls, data, handles):
111 result = cls.__new__(cls)
112 fields = {}
113 serialization_object.Deserialize(fields, data, handles)
114 result._fields = fields
115 return result
116 dictionary['Deserialize'] = classmethod(Deserialize)
117
110 return type.__new__(mcs, name, bases, dictionary) 118 return type.__new__(mcs, name, bases, dictionary)
111 119
112 # Prevent adding new attributes, or mutating constants. 120 # Prevent adding new attributes, or mutating constants.
113 def __setattr__(mcs, key, value): 121 def __setattr__(mcs, key, value):
114 raise AttributeError, 'can\'t set attribute' 122 raise AttributeError, 'can\'t set attribute'
115 123
116 # Prevent deleting constants. 124 # Prevent deleting constants.
117 def __delattr__(mcs, key): 125 def __delattr__(mcs, key):
118 raise AttributeError, 'can\'t delete attribute' 126 raise AttributeError, 'can\'t delete attribute'
119 127
(...skipping 11 matching lines...) Expand all
131 def Get(self): 139 def Get(self):
132 if field.name not in self._fields: 140 if field.name not in self._fields:
133 self._fields[field.name] = field.GetDefaultValue() 141 self._fields[field.name] = field.GetDefaultValue()
134 return self._fields[field.name] 142 return self._fields[field.name]
135 143
136 # pylint: disable=W0212 144 # pylint: disable=W0212
137 def Set(self, value): 145 def Set(self, value):
138 self._fields[field.name] = field.field_type.Convert(value) 146 self._fields[field.name] = field.field_type.Convert(value)
139 147
140 return property(Get, Set) 148 return property(Get, Set)
OLDNEW
« no previous file with comments | « mojo/public/python/mojo/bindings/descriptor.py ('k') | mojo/public/python/mojo/bindings/serialization.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698