Wrap InterfaceSchema
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
cimport cython
|
cimport cython
|
||||||
cimport capnp_cpp as capnp
|
cimport capnp_cpp as capnp
|
||||||
cimport schema_cpp
|
cimport schema_cpp
|
||||||
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, ObjectPointer as C_DynamicObject, WordArrayPtr
|
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, ObjectPointer as C_DynamicObject, WordArrayPtr
|
||||||
|
|
||||||
from schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
from schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
||||||
from cython.operator cimport dereference as deref
|
from cython.operator cimport dereference as deref
|
||||||
@@ -61,7 +61,7 @@ _Type = _make_enum('DynamicValue.Type',
|
|||||||
LIST = capnp.TYPE_LIST,
|
LIST = capnp.TYPE_LIST,
|
||||||
ENUM = capnp.TYPE_ENUM,
|
ENUM = capnp.TYPE_ENUM,
|
||||||
STRUCT = capnp.TYPE_STRUCT,
|
STRUCT = capnp.TYPE_STRUCT,
|
||||||
INTERFACE = capnp.TYPE_INTERFACE,
|
# INTERFACE = capnp.TYPE_INTERFACE,
|
||||||
OBJECT = capnp.TYPE_OBJECT)
|
OBJECT = capnp.TYPE_OBJECT)
|
||||||
|
|
||||||
# Templated classes are weird in cython. I couldn't put it in a pxd header for some reason
|
# Templated classes are weird in cython. I couldn't put it in a pxd header for some reason
|
||||||
@@ -113,6 +113,9 @@ cdef class _NodeReader:
|
|||||||
property isConst:
|
property isConst:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
return self.thisptr.isConst()
|
return self.thisptr.isConst()
|
||||||
|
property isInterface:
|
||||||
|
def __get__(self):
|
||||||
|
return self.thisptr.isInterface()
|
||||||
|
|
||||||
cdef class _NestedNodeReader:
|
cdef class _NestedNodeReader:
|
||||||
cdef C_Node.NestedNode.Reader thisptr
|
cdef C_Node.NestedNode.Reader thisptr
|
||||||
@@ -820,6 +823,9 @@ cdef class _Schema:
|
|||||||
cpdef as_struct(self):
|
cpdef as_struct(self):
|
||||||
return _StructSchema()._init(self.thisptr.asStruct())
|
return _StructSchema()._init(self.thisptr.asStruct())
|
||||||
|
|
||||||
|
cpdef as_interface(self):
|
||||||
|
return _InterfaceSchema()._init(self.thisptr.asInterface())
|
||||||
|
|
||||||
cpdef get_dependency(self, id):
|
cpdef get_dependency(self, id):
|
||||||
return _Schema()._init(self.thisptr.getDependency(id))
|
return _Schema()._init(self.thisptr.getDependency(id))
|
||||||
|
|
||||||
@@ -885,26 +891,22 @@ cdef class _StructSchema:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<schema for %s>' % self.node.displayName
|
return '<schema for %s>' % self.node.displayName
|
||||||
|
|
||||||
cdef class _ParsedSchema:
|
cdef class _InterfaceSchema:
|
||||||
cdef C_ParsedSchema thisptr
|
cdef C_InterfaceSchema thisptr
|
||||||
cdef _init(self, C_ParsedSchema other):
|
|
||||||
|
cdef _init(self, C_InterfaceSchema other):
|
||||||
self.thisptr = other
|
self.thisptr = other
|
||||||
return self
|
return self
|
||||||
|
|
||||||
cpdef as_const_value(self):
|
cdef class _ParsedSchema(_Schema):
|
||||||
return to_python_reader(<C_DynamicValue.Reader>self.thisptr.asConst(), self)
|
cdef C_ParsedSchema thisptr_child
|
||||||
|
cdef _init_child(self, C_ParsedSchema other):
|
||||||
|
self.thisptr_child = other
|
||||||
|
self._init(other)
|
||||||
|
return self
|
||||||
|
|
||||||
cpdef as_struct(self):
|
cpdef get_nested(self, name):
|
||||||
return _StructSchema()._init(self.thisptr.asStruct())
|
return _ParsedSchema()._init_child(self.thisptr_child.getNested(name))
|
||||||
|
|
||||||
cpdef get_dependency(self, id):
|
|
||||||
return _Schema()._init(self.thisptr.getDependency(id))
|
|
||||||
|
|
||||||
cpdef get_proto(self):
|
|
||||||
return _NodeReader().init(self.thisptr.getProto())
|
|
||||||
|
|
||||||
cpdef getNested(self, name):
|
|
||||||
return _ParsedSchema()._init(self.thisptr.getNested(name))
|
|
||||||
|
|
||||||
class _StructABCMeta(type):
|
class _StructABCMeta(type):
|
||||||
"""A metaclass for the Type.Reader and Type.Builder ABCs."""
|
"""A metaclass for the Type.Reader and Type.Builder ABCs."""
|
||||||
@@ -932,7 +934,7 @@ cdef class SchemaParser:
|
|||||||
cdef ArrayPtr[StringPtr] importsPtr = ArrayPtr[StringPtr](importArray, <size_t>len(imports))
|
cdef ArrayPtr[StringPtr] importsPtr = ArrayPtr[StringPtr](importArray, <size_t>len(imports))
|
||||||
|
|
||||||
ret = _ParsedSchema()
|
ret = _ParsedSchema()
|
||||||
ret._init(self.thisptr.parseDiskFile(displayName, diskPath, importsPtr))
|
ret._init_child(self.thisptr.parseDiskFile(displayName, diskPath, importsPtr))
|
||||||
|
|
||||||
free(importArray)
|
free(importArray)
|
||||||
|
|
||||||
@@ -980,7 +982,7 @@ cdef class SchemaParser:
|
|||||||
local_module = _ModuleType(node.name)
|
local_module = _ModuleType(node.name)
|
||||||
module.__dict__[node.name] = local_module
|
module.__dict__[node.name] = local_module
|
||||||
|
|
||||||
schema = nodeSchema.getNested(node.name)
|
schema = nodeSchema.get_nested(node.name)
|
||||||
proto = schema.get_proto()
|
proto = schema.get_proto()
|
||||||
if proto.isStruct:
|
if proto.isStruct:
|
||||||
local_module.schema = schema.as_struct()
|
local_module.schema = schema.as_struct()
|
||||||
@@ -1015,6 +1017,11 @@ cdef class SchemaParser:
|
|||||||
_from_dict(msg, d)
|
_from_dict(msg, d)
|
||||||
return msg
|
return msg
|
||||||
return helper
|
return helper
|
||||||
|
def from_object():
|
||||||
|
def helper(obj):
|
||||||
|
builder = _MallocMessageBuilder()
|
||||||
|
return builder.set_root(obj)
|
||||||
|
return helper
|
||||||
class Reader(_DynamicStructReader):
|
class Reader(_DynamicStructReader):
|
||||||
"""An abstract base class. Readers are 'instances' of this class."""
|
"""An abstract base class. Readers are 'instances' of this class."""
|
||||||
__metaclass__ = _StructABCMeta
|
__metaclass__ = _StructABCMeta
|
||||||
@@ -1034,12 +1041,15 @@ cdef class SchemaParser:
|
|||||||
local_module.read = read(local_module)
|
local_module.read = read(local_module)
|
||||||
local_module.read_packed = read_packed(local_module)
|
local_module.read_packed = read_packed(local_module)
|
||||||
local_module.new_message = new_message(local_module)
|
local_module.new_message = new_message(local_module)
|
||||||
|
local_module.from_object = from_object()
|
||||||
local_module.from_dict = from_dict(local_module)
|
local_module.from_dict = from_dict(local_module)
|
||||||
local_module.from_bytes = make_from_bytes(local_module)
|
local_module.from_bytes = make_from_bytes(local_module)
|
||||||
local_module.Reader = Reader
|
local_module.Reader = Reader
|
||||||
local_module.Builder = Builder
|
local_module.Builder = Builder
|
||||||
elif proto.isConst:
|
elif proto.isConst:
|
||||||
module.__dict__[node.name] = schema.as_const_value()
|
module.__dict__[node.name] = schema.as_const_value()
|
||||||
|
elif proto.isInterface:
|
||||||
|
local_module.schema = schema.as_interface()
|
||||||
|
|
||||||
_load(schema, local_module)
|
_load(schema, local_module)
|
||||||
if not _os.path.isfile(file_name):
|
if not _os.path.isfile(file_name):
|
||||||
@@ -1134,6 +1144,7 @@ cdef class _MessageBuilder:
|
|||||||
if type(value) is _DynamicStructBuilder:
|
if type(value) is _DynamicStructBuilder:
|
||||||
value = value.as_reader();
|
value = value.as_reader();
|
||||||
self.thisptr.setRootDynamicStruct((<_DynamicStructReader>value).thisptr)
|
self.thisptr.setRootDynamicStruct((<_DynamicStructReader>value).thisptr)
|
||||||
|
return self.get_root(value.schema)
|
||||||
|
|
||||||
cpdef new_orphan(self, schema):
|
cpdef new_orphan(self, schema):
|
||||||
"""A method for instantiating Cap'n Proto orphans
|
"""A method for instantiating Cap'n Proto orphans
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ cdef extern from "capnp/schema.h" namespace " ::capnp":
|
|||||||
EnumSchema asEnum() except +
|
EnumSchema asEnum() except +
|
||||||
ConstSchema asConst() except +
|
ConstSchema asConst() except +
|
||||||
Schema getDependency(uint64_t id) except +
|
Schema getDependency(uint64_t id) except +
|
||||||
#InterfaceSchema asInterface() const;
|
InterfaceSchema asInterface() except +
|
||||||
|
|
||||||
|
cdef cppclass InterfaceSchema(Schema):
|
||||||
|
pass
|
||||||
|
|
||||||
cdef cppclass StructSchema(Schema):
|
cdef cppclass StructSchema(Schema):
|
||||||
cppclass Field:
|
cppclass Field:
|
||||||
@@ -116,7 +119,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||||||
TYPE_LIST " ::capnp::DynamicValue::LIST"
|
TYPE_LIST " ::capnp::DynamicValue::LIST"
|
||||||
TYPE_ENUM " ::capnp::DynamicValue::ENUM"
|
TYPE_ENUM " ::capnp::DynamicValue::ENUM"
|
||||||
TYPE_STRUCT " ::capnp::DynamicValue::STRUCT"
|
TYPE_STRUCT " ::capnp::DynamicValue::STRUCT"
|
||||||
TYPE_INTERFACE " ::capnp::DynamicValue::INTERFACE"
|
# TYPE_INTERFACE " ::capnp::DynamicValue::INTERFACE"
|
||||||
TYPE_OBJECT " ::capnp::DynamicValue::OBJECT"
|
TYPE_OBJECT " ::capnp::DynamicValue::OBJECT"
|
||||||
|
|
||||||
cdef cppclass DynamicStruct:
|
cdef cppclass DynamicStruct:
|
||||||
|
|||||||
Reference in New Issue
Block a user