From 1bfc20fefb4c2915e030939e25ff4d35113bba33 Mon Sep 17 00:00:00 2001 From: Florian Friesdorf Date: Thu, 9 Feb 2017 02:10:50 +0100 Subject: [PATCH] support initializing DynamicListBuilder from tuple --- capnp/lib/capnp.pxd | 1 + capnp/lib/capnp.pyx | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/capnp/lib/capnp.pxd b/capnp/lib/capnp.pxd index 8cbf3b7..dc0ed4e 100644 --- a/capnp/lib/capnp.pxd +++ b/capnp/lib/capnp.pxd @@ -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_dict(msg, bint verbose, bint ordered) cdef _from_list(_DynamicListBuilder msg, list d) +cdef _from_tuple(_DynamicListBuilder msg, tuple d) cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField field, value, parent) cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 284bd7c..53756ca 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -719,6 +719,9 @@ cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent): elif value_type is list: builder = to_python_builder(thisptr.init(field, len(value)), parent) _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: if _DynamicSetterClasses is DynamicStruct_Builder: builder = to_python_builder(thisptr.get(field), parent) @@ -904,6 +907,11 @@ cdef _from_list(_DynamicListBuilder msg, list d): 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 _init(self, capnp.DynamicEnum other, object parent): self.thisptr = other