I've been playing with this a bit and the closest I've been able to get is constructing a new message with the AnyPointer at the root. That, however, prepends a struct pointer to the whole thing. I can just chop it off, but I'm thinking there must be a better way.
auto msg = context.getParams().getMsg(); // AnyPointer MallocMessageBuilder messageBuilder; messageBuilder.setRoot(msg); auto flatWordsArray = messageToFlatArray(messageBuilder); auto byteArray = flatWordsArray.asBytes(); ~John On Thursday, May 14, 2020 at 11:30:38 PM UTC-7, John Demme wrote: > > Hi- > > In the C++ API, is there an (easy) way to get the binary encoded message > of an AnyPointer field? Or a generic field? (If I understand, they're > encoded the same under the hood.) I don't think anyPointer->getAs<Data>() > would work, would it? > > The background here is that I'm trying to write a generic proxy for > CapnProto messages using CapnProto RPC. Since I'm not re-compiling the > proxy itself, it cannot know the possible types for AnyPointer. Since > messages don't need any schema data to be traversed (though not > interpreted) correctly, this *should *be possible. > > To be more concrete: > interface ProxyChannel { > send @0 (msg :AnyPointer); > recv @1 () -> (respMsg :AnyPointer); > } > > I'm using :Data instead of :AnyPointer now, but that puts a unnecessary > burden on the clients. > > ~John > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/7f1b3509-0bac-4854-8256-d85a718031d7%40googlegroups.com.