Cloning DynamicStructs

9 views
Skip to first unread message

Vaci

unread,
Nov 18, 2021, 7:31:30 AMNov 18
to Cap'n Proto
Hi,

Should it be possible to use capnp::clone() to copy a DynamicStruct? 

This code currently doesn't compile:

#include <capnp/dynamic.h>
#include <capnp/message.h>
#include "foo.capnp.h"
int main() {
  capnp::MallocMessageBuilder mb;
  auto root = mb.initRoot<Foo>();
  auto a = root.asReader();
  auto a2 = capnp::clone(a); // succeeds
  auto b = capnp::toDynamic(a);
  auto b2 = capnp::clone(b); // fails
}

...but I'm not clear what it is about DynamicStructs that make them less copyable?

Cheers,
Vaci



Kenton Varda

unread,
Nov 19, 2021, 2:39:51 PMNov 19
to Vaci, Cap'n Proto
No, there's no fundamental limitation here. I think we just need an overload of `clone()` for this that accounts for the subtle API differences with `DynamicStruct`, e.g. passing the `Schema` in various places.

-Kenton

--
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 capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/ce287ada-fee5-4bed-b353-10c438136d40n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages