Cap'n Proto provides a schema loader, which can be used to dynamically load schemas during runtime. To port this functionality to pycapnp, a new class is provided `C_SchemaLoader`, which exposes the Cap'n Proto C++ interface, and `SchemaLoader`, which is part of the pycapnp library. The specific use case for this is when a capnp message contains a Node.Reader: The schema for a yet unseen message can be loaded dynamically, allowing the future message to be properly processed. If the message is a struct containing other structs, all the schemas for every struct must be loaded to correctly parse the message. See https://github.com/DaneSlattery/capnp_generic_poc for a proof-of-concept. Add docs and cleanup Add more docs Reduce changes Fix flake8 formatting Fix get datatype
37 lines
1.5 KiB
Cython
37 lines
1.5 KiB
Cython
from capnp.includes.capnp_cpp cimport (
|
|
Maybe, PyPromise, VoidPromise, RemotePromise,
|
|
DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability,
|
|
RpcSystem, MessageBuilder, Own, PyRefCounter, Node, DynamicStruct
|
|
)
|
|
|
|
from capnp.includes.schema_cpp cimport ByteArray
|
|
|
|
from non_circular cimport reraise_kj_exception
|
|
|
|
from cpython.ref cimport PyObject
|
|
|
|
cdef extern from "capnp/helpers/fixMaybe.h":
|
|
EnumSchema.Enumerant fixMaybe(Maybe[EnumSchema.Enumerant]) except +reraise_kj_exception
|
|
StructSchema.Field fixMaybe(Maybe[StructSchema.Field]) except +reraise_kj_exception
|
|
|
|
cdef extern from "capnp/helpers/capabilityHelper.h":
|
|
PyPromise then(PyPromise promise, Own[PyRefCounter] func, Own[PyRefCounter] error_func)
|
|
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
|
|
DynamicValue.Reader new_server(InterfaceSchema&, PyObject *)
|
|
Capability.Client server_to_client(InterfaceSchema&, PyObject *)
|
|
PyPromise convert_to_pypromise(RemotePromise)
|
|
PyPromise convert_to_pypromise(VoidPromise)
|
|
VoidPromise taskToPromise(Own[PyRefCounter] coroutine, PyObject* callback)
|
|
void init_capnp_api()
|
|
|
|
cdef extern from "capnp/helpers/rpcHelper.h":
|
|
Capability.Client bootstrapHelper(RpcSystem&)
|
|
Capability.Client bootstrapHelperServer(RpcSystem&)
|
|
|
|
cdef extern from "capnp/helpers/serialize.h":
|
|
ByteArray messageToPackedBytes(MessageBuilder &, size_t wordCount)
|
|
|
|
cdef extern from "capnp/helpers/deserialize.h":
|
|
Node.Reader toReader(DynamicStruct.Reader reader) except +reraise_kj_exception
|
|
|