Add handling of constants in schemas
This commit is contained in:
@@ -87,6 +87,12 @@ cdef class _NodeReader:
|
||||
property nestedNodes:
|
||||
def __get__(self):
|
||||
return _List_NestedNode_Reader()._init(self.thisptr.getNestedNodes())
|
||||
property isStruct:
|
||||
def __get__(self):
|
||||
return self.thisptr.isStruct()
|
||||
property isConst:
|
||||
def __get__(self):
|
||||
return self.thisptr.isConst()
|
||||
|
||||
cdef class _NestedNodeReader:
|
||||
cdef C_Node.NestedNode.Reader thisptr
|
||||
@@ -364,6 +370,9 @@ cdef class Schema:
|
||||
self.thisptr = other
|
||||
return self
|
||||
|
||||
cpdef asConstValue(self):
|
||||
return _DynamicValueReader()._init(<C_DynamicValue.Reader>self.thisptr.asConst(), self).toPython()
|
||||
|
||||
cpdef asStruct(self):
|
||||
return StructSchema()._init(self.thisptr.asStruct())
|
||||
|
||||
@@ -385,6 +394,9 @@ cdef class ParsedSchema:
|
||||
self.thisptr = other
|
||||
return self
|
||||
|
||||
cpdef asConstValue(self):
|
||||
return _DynamicValueReader()._init(<C_DynamicValue.Reader>self.thisptr.asConst(), self).toPython()
|
||||
|
||||
cpdef asStruct(self):
|
||||
return StructSchema()._init(self.thisptr.asStruct())
|
||||
|
||||
@@ -506,10 +518,11 @@ def _load(nodeSchema, module):
|
||||
module.__dict__[node.name] = local_module
|
||||
|
||||
schema = nodeSchema.getNested(node.name)
|
||||
try:
|
||||
proto = schema.getProto()
|
||||
if proto.isStruct:
|
||||
local_module.Schema = schema.asStruct()
|
||||
except:
|
||||
pass
|
||||
elif proto.isConst:
|
||||
module.__dict__[node.name] = schema.asConstValue()
|
||||
|
||||
_load(schema, local_module)
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ cdef extern from "capnp/schema.h" namespace " ::capnp":
|
||||
Node.Reader getProto() except +
|
||||
StructSchema asStruct() except +
|
||||
EnumSchema asEnum() except +
|
||||
ConstSchema asConst() except +
|
||||
Schema getDependency(uint64_t id) except +
|
||||
#InterfaceSchema asInterface() const;
|
||||
|
||||
@@ -64,6 +65,9 @@ cdef extern from "capnp/schema.h" namespace " ::capnp":
|
||||
Enumerant getEnumerantByName(char * name)
|
||||
Node.Reader getProto()
|
||||
|
||||
cdef cppclass ConstSchema:
|
||||
pass
|
||||
|
||||
cdef extern from "capnp/schema-loader.h" namespace " ::capnp":
|
||||
cdef cppclass SchemaLoader:
|
||||
SchemaLoader()
|
||||
|
||||
@@ -438,6 +438,12 @@ cdef extern from "capnp/schema.capnp.h" namespace " ::capnp::schema":
|
||||
UInt64 getScopeId()
|
||||
List[Node.Node.NestedNode].Reader getNestedNodes()
|
||||
UInt64 getId()
|
||||
bint isFile()
|
||||
bint isStruct()
|
||||
bint isEnum()
|
||||
bint isInterface()
|
||||
bint isConst()
|
||||
bint isAnnotation()
|
||||
cppclass Builder:
|
||||
|
||||
Node.Body getBody()
|
||||
@@ -452,6 +458,12 @@ cdef extern from "capnp/schema.capnp.h" namespace " ::capnp::schema":
|
||||
List[Node.Node.NestedNode].Builder initNestedNodes(int)
|
||||
UInt64 getId()
|
||||
void setId(UInt64)
|
||||
bint isFile()
|
||||
bint isStruct()
|
||||
bint isEnum()
|
||||
bint isInterface()
|
||||
bint isConst()
|
||||
bint isAnnotation()
|
||||
cdef cppclass AnnotationNode:
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
@0x934efea7f017fff0;
|
||||
|
||||
const qux :UInt32 = 123;
|
||||
|
||||
struct Person {
|
||||
id @0 :UInt32;
|
||||
name @1 :Text;
|
||||
|
||||
Reference in New Issue
Block a user