Hi William,
When init()ing a Text field, you need to specify the size of the text:
req.getPayload().initAs<Text>(123);
You can also directly set the field to an existing string:
req.getPayload().setAs<Text>("foo");
-Kenton
On Fri, Dec 7, 2018 at 10:30 AM <[email protected]> wrote:
> Hello,
>
> using cap'n'proto c++ library, I've made a structure for generic request
> exchange
>
> struct Request {
> timestamp @0: UInt64;
> resource @1: Text;
> payload @2: AnyPointer;
> }
>
> resource used for the request name, and payload for the request argument.
>
> I successfully used it with custom structure inside the payload, but I
> can't figure out how I can put simple Text in the payload
>
> ::capnp::MallocMessageBuilder message;
> Request::Builder req = message.initRoot<Request>();
> req.setTimestamp(timestamp_now());
>
> req.setResource("MyRequest");
>
>
>
> and now I would like to init the payload and put text in it. I tried
> something like that
> auto payload_text = req.getPayload().initAs<Text>();
> gives me
> error: too few arguments to function call, expected 2, have 1
> return _::PointerHelpers<T>::init(builder);
>
> auto payload_text = req.getPayload().getAs<Text>();
> compile, but then I cannot change the text in payload_text
>
> I couldn't find any sample where AnyPointer is used with Text. Any clue ?
>
> Best regards,
>
> William
>
> --
> 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].
> Visit this group at https://groups.google.com/group/capnproto.
>
--
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].
Visit this group at https://groups.google.com/group/capnproto.