Merge pull request #136 from ternaris/lists-from-tuples

support initializing DynamicListBuilder from tuple
This commit is contained in:
Jason Paryani
2017-04-09 17:36:35 -07:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -122,5 +122,6 @@ cdef to_python_reader(C_DynamicValue.Reader self, object parent)
cdef to_python_builder(C_DynamicValue.Builder self, object parent) cdef to_python_builder(C_DynamicValue.Builder self, object parent)
cdef _to_dict(msg, bint verbose, bint ordered) cdef _to_dict(msg, bint verbose, bint ordered)
cdef _from_list(_DynamicListBuilder msg, list d) cdef _from_list(_DynamicListBuilder msg, list d)
cdef _from_tuple(_DynamicListBuilder msg, tuple d)
cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField field, value, parent) cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField field, value, parent)
cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent) cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent)

View File

@@ -727,6 +727,9 @@ cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
elif value_type is list: elif value_type is list:
builder = to_python_builder(thisptr.init(field, len(value)), parent) builder = to_python_builder(thisptr.init(field, len(value)), parent)
_from_list(builder, value) _from_list(builder, value)
elif value_type is tuple:
builder = to_python_builder(thisptr.init(field, len(value)), parent)
_from_tuple(builder, value)
elif value_type is dict: elif value_type is dict:
if _DynamicSetterClasses is DynamicStruct_Builder: if _DynamicSetterClasses is DynamicStruct_Builder:
builder = to_python_builder(thisptr.get(field), parent) builder = to_python_builder(thisptr.get(field), parent)
@@ -912,6 +915,11 @@ cdef _from_list(_DynamicListBuilder msg, list d):
msg._set(i, x) msg._set(i, x)
cdef _from_tuple(_DynamicListBuilder msg, tuple d):
for i, x in enumerate(d):
msg._set(i, x)
cdef class _DynamicEnum: cdef class _DynamicEnum:
cdef _init(self, capnp.DynamicEnum other, object parent): cdef _init(self, capnp.DynamicEnum other, object parent):
self.thisptr = other self.thisptr = other