Allow creation of ListSchema from other Schemas
This commit is contained in:
@@ -217,6 +217,11 @@ cdef extern from "capnp/schema.h" namespace " ::capnp":
|
|||||||
cdef cppclass ListSchema:
|
cdef cppclass ListSchema:
|
||||||
SchemaType getElementType()
|
SchemaType getElementType()
|
||||||
|
|
||||||
|
ListSchema listSchemaOfStruct" ::capnp::ListSchema::of"(StructSchema)
|
||||||
|
ListSchema listSchemaOfEnum" ::capnp::ListSchema::of"(EnumSchema)
|
||||||
|
ListSchema listSchemaOfInterface" ::capnp::ListSchema::of"(InterfaceSchema)
|
||||||
|
ListSchema listSchemaOfList" ::capnp::ListSchema::of"(ListSchema)
|
||||||
|
|
||||||
cdef cppclass ConstSchema:
|
cdef cppclass ConstSchema:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -2569,6 +2569,34 @@ cdef class _EnumSchema:
|
|||||||
cdef class ListSchema:
|
cdef class ListSchema:
|
||||||
cdef C_ListSchema thisptr
|
cdef C_ListSchema thisptr
|
||||||
|
|
||||||
|
def __init__(self, schema=None):
|
||||||
|
cdef _StructSchema ss
|
||||||
|
cdef _EnumSchema es
|
||||||
|
cdef _InterfaceSchema iis
|
||||||
|
cdef ListSchema ls
|
||||||
|
|
||||||
|
if schema is not None:
|
||||||
|
if hasattr(schema, 'schema'):
|
||||||
|
s = schema.schema
|
||||||
|
else:
|
||||||
|
s = schema
|
||||||
|
|
||||||
|
typeSchema = type(s)
|
||||||
|
if typeSchema is _StructSchema:
|
||||||
|
ss = s
|
||||||
|
self.thisptr = capnp.listSchemaOfStruct(ss.thisptr)
|
||||||
|
elif typeSchema is _EnumSchema:
|
||||||
|
es = s
|
||||||
|
self.thisptr = capnp.listSchemaOfEnum(es.thisptr)
|
||||||
|
elif typeSchema is _InterfaceSchema:
|
||||||
|
iis = s
|
||||||
|
self.thisptr = capnp.listSchemaOfInterface(iis.thisptr)
|
||||||
|
elif typeSchema is ListSchema:
|
||||||
|
ls = s
|
||||||
|
self.thisptr = capnp.listSchemaOfList(ls.thisptr)
|
||||||
|
else:
|
||||||
|
raise ValueError("Unknown schema type")
|
||||||
|
|
||||||
cdef _init(self, C_ListSchema other):
|
cdef _init(self, C_ListSchema other):
|
||||||
self.thisptr = other
|
self.thisptr = other
|
||||||
return self
|
return self
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ def test_list_schema(addressbook):
|
|||||||
personType = peopleField.schema.elementType
|
personType = peopleField.schema.elementType
|
||||||
|
|
||||||
assert personType.node.id == addressbook.Person.schema.node.id
|
assert personType.node.id == addressbook.Person.schema.node.id
|
||||||
|
|
||||||
|
personListSchema = capnp.ListSchema(addressbook.Person)
|
||||||
|
|
||||||
|
assert personListSchema.elementType.node.id == addressbook.Person.schema.node.id
|
||||||
|
|||||||
Reference in New Issue
Block a user