Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing compiled schema from CodeGeneratorRequest; _NodeReader vs _DynamicListReader #321

Open
ahupp opened this issue Jul 23, 2023 · 1 comment

Comments

@ahupp
Copy link

ahupp commented Jul 23, 2023

I'm writing some python with pycapnp to reflect on arbitrary capnp RPC endpoints. These endpoints have a method that returns their corresponding CodeGeneratorRequest, and I was hoping to load that at runtime. However, I'm hitting this error. Setup for the example to get a compiled schema:

$ cat example.capnp
@0xc9b9b8866c80620b;

struct Example {
  value @0 :Int64;
}

$ capnp compile -o- -I /usr/include example.capnp > example.bin

Then this script to load the compiled schema:

import capnp
import capnp.schema_capnp

cgr = capnp.schema_capnp.CodeGeneratorRequest.read(open("repro.bin", "rb"))
loader = capnp.SchemaLoader()
loader.load(cgr.nodes)

This fails with:

Traceback (most recent call last):
  File "example.py", line 6, in <module>
    loader.load(cgr.nodes)
TypeError: Argument 'reader' has incorrect type (expected capnp.lib.capnp._NodeReader, got capnp.lib.capnp._DynamicListReader)

Am I doing this wrong? Is there a way to work around it?

@ahupp
Copy link
Author

ahupp commented Jul 23, 2023

It kind of looks like I can use:

loader = capnp.SchemaLoader()
for node in cgr.nodes:
   loader.load_dynamic(node)

Along with copying some of the Schema -> python module logic in SchemaParser. Still doesn't quite work though, I'm seeing a wide range of errors. Happy to share a more detailed repro if this is unexpected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant