antocuni / capnpy

Other
45 stars 26 forks source link

Allow load_schema() to accept a str #31

Open kawing-chiu opened 6 years ago

kawing-chiu commented 6 years ago

The current API assumes that schema is saved in a file, but in my case the capnp schema is fetched from some db as a str. Maybe an argument can be add to load_schema() to support this usage?

colinfang commented 6 years ago

That sounds like a good idea.

If it is implemented we can remove a lot of boilerplate code in tests e.g.

        schema = """
        @0xbf5147cbbecf40c1;
        struct Point {
            x @0 :Int64;
            y @1 :Int64;
        }
        """
        mypkg = self.tmpdir.join("mypkg").ensure(dir=True)
        myschema = mypkg.join("myschema.capnp")
        myschema.write(schema)