Support _DynamicListReader in _setDynamicField

See the test for an explanation.

Note that I'm not sure what the purpose of `_setDynamicFieldWithField` and
`_setDynamicFieldStatic` is. It does not appear to be used. I've kept them for
now (they are a public API), but perhaps this can be removed.
This commit is contained in:
Lasse Blaauwbroek
2023-11-07 05:18:29 +01:00
committed by Jacob Alexander
parent aafec2281e
commit ef5e039067
4 changed files with 37 additions and 0 deletions

View File

@@ -362,6 +362,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
void adopt(uint, DynamicOrphan) except +reraise_kj_exception
DynamicOrphan disown(uint)
StructSchema getStructElementType'getSchema().getStructElementType'()
DynamicList.Reader asReader() except +reraise_kj_exception
cdef extern from "capnp/any.h" namespace " ::capnp":
cdef cppclass AnyPointer nogil:

View File

@@ -714,6 +714,14 @@ cdef C_DynamicValue.Reader _extract_dynamic_struct_reader(_DynamicStructReader v
return C_DynamicValue.Reader(value.thisptr)
cdef C_DynamicValue.Reader _extract_dynamic_list_builder(_DynamicListBuilder value):
return C_DynamicValue.Reader(value.thisptr.asReader())
cdef C_DynamicValue.Reader _extract_dynamic_list_reader(_DynamicListReader value):
return C_DynamicValue.Reader(value.thisptr)
cdef C_DynamicValue.Reader _extract_dynamic_client(_DynamicCapabilityClient value):
return C_DynamicValue.Reader(value.thisptr)
@@ -805,6 +813,10 @@ cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
thisptr.set(field, _extract_dynamic_struct_builder(value))
elif value_type is _DynamicStructReader:
thisptr.set(field, _extract_dynamic_struct_reader(value))
elif value_type is _DynamicListBuilder:
thisptr.set(field, _extract_dynamic_list_builder(value))
elif value_type is _DynamicListReader:
thisptr.set(field, _extract_dynamic_list_reader(value))
elif value_type is _DynamicCapabilityClient:
thisptr.set(field, _extract_dynamic_client(value))
elif isinstance(value, _DynamicCapabilityServer):
@@ -821,6 +833,7 @@ cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
.format(field, str(value), str(type(value))))
# TODO: Is this function used by anyone? Can it be removed?
cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField field, value, parent):
cdef C_DynamicValue.Reader temp
value_type = type(value)
@@ -854,6 +867,10 @@ cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField
thisptr.setByField(field.thisptr, _extract_dynamic_struct_builder(value))
elif value_type is _DynamicStructReader:
thisptr.setByField(field.thisptr, _extract_dynamic_struct_reader(value))
elif value_type is _DynamicListBuilder:
thisptr.setByField(field.thisptr, _extract_dynamic_list_builder(value))
elif value_type is _DynamicListReader:
thisptr.setByField(field.thisptr, _extract_dynamic_list_reader(value))
elif value_type is _DynamicCapabilityClient:
thisptr.setByField(field.thisptr, _extract_dynamic_client(value))
elif isinstance(value, _DynamicCapabilityServer):
@@ -870,6 +887,7 @@ cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField
.format(field, str(value), str(type(value))))
# TODO: Is this function used by anyone? Can it be removed?
cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent):
cdef C_DynamicValue.Reader temp
value_type = type(value)
@@ -903,6 +921,10 @@ cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent)
thisptr.set(field, _extract_dynamic_struct_builder(value))
elif value_type is _DynamicStructReader:
thisptr.set(field, _extract_dynamic_struct_reader(value))
elif value_type is _DynamicListBuilder:
thisptr.set(field, _extract_dynamic_list_builder(value))
elif value_type is _DynamicListReader:
thisptr.set(field, _extract_dynamic_list_reader(value))
elif value_type is _DynamicCapabilityClient:
thisptr.set(field, _extract_dynamic_client(value))
elif isinstance(value, _DynamicCapabilityServer):