Hi Stefan, So, a List of structs is actually not encoded as a list of pointers. Instead, the struct bodies appear contiguously. So, to swap two elements in a list of structs, you would need to swap each field value within the two structs. For pointer fields, you could use target.adoptField(source.disownField()) to avoid performing a deep copy. You could write some code based on AnyStruct (capnp/any.h) that does such a swap in a schema-agnostic way, but there's no built-in code for this at present.
List(Text), List(Data), and List(List(T)) are actually encoded as lists of pointers. In those cases the List builders have adopt() and disown() methods that operate on whole elements which you could use to implement swapping pretty easily. -Kenton On Wed, Sep 25, 2019 at 5:09 AM Stefan Kaps <[email protected]> wrote: > Hi @all, > > during serialization I need to reorder the contents of a list after > creation. How would I do that? As far as I understood, it's all > pointers. So are there capnp::List<> - operators to swap 2 items? > > All the best, > Stefan > > -- > You received this message because you are subscribed to the Google Groups > "Cap'n Proto" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/capnproto/8fbf6664-fbfc-4aa2-b054-894a8f01137e%40googlegroups.com > <https://groups.google.com/d/msgid/capnproto/8fbf6664-fbfc-4aa2-b054-894a8f01137e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/CAJouXQn_RpXvCNZzGWYAk75Y1iGfPz4NgVQwf8DJqisrHao9HQ%40mail.gmail.com.
