I see I can use SchemaLoader.get() to get a capnp::Type out of a schema::Type::Reader, and from there I can get the ListSchema, and DynamicList. But the .get() method recurses on the Type, so it'll return the type of the inner struct, rather than outer List, and I suspect the returned DynamicList will iterate on the inner struct, rather than the outer list.
You mean SchemaLoader::getType(), right?
case schema::Type::LIST:return ListSchema::of(getType(proto.getList().getElementType(), scope));So the returned type should not lose the fact that the type represents a list (or list-of-lists, or list-of-list-of-lists, etc.).Do you have some code that doesn't work as you expect, that you could share?
Hello,On Tue, Jan 24, 2023 at 1:10 PM Kenton Varda <ken...@cloudflare.com> wrote:You mean SchemaLoader::getType(), right?Correct.case schema::Type::LIST:return ListSchema::of(getType(proto.getList().getElementType(), scope));So the returned type should not lose the fact that the type represents a list (or list-of-lists, or list-of-list-of-lists, etc.).Do you have some code that doesn't work as you expect, that you could share?When looking at the code above, the recursion seemed to pretty much return a type representing List(struct) rather thanList(List(struct)),
I am not sure iterating over the DynamicList is doing the right thing. My code is crashing, so assumed I was doing something wrong.Let me work on a self contained example, don't have one handy.
Fundamentally... Once getType() returns, I have a capnp::Type that I can use to build a DynamicList, which I can use to iterate over the elements.Iterating over the elements is moving through the outer list, and returns a DynamicValue. Now I need to iterate over the elements on the inner list.To go from DynamicValue to another DynamicList... use getType() passing in getList().getElementType() (recursing inside once), and then DynamicValue.of<DynamicList<...>>?