How to reuse a reader object when i need to duplicate the definition of a struct for later use/re-access?

28 views
Skip to first unread message

Fay Wong

unread,
Nov 5, 2019, 5:15:58 AM11/5/19
to Cap'n Proto
Just as the mail title.

How could i reuse a reader object after i have consumed it once?

I am implement a runtime mvvm ui engine, for example, <ul v-for="item in data.goodList" ...

when data.goodList changes, i need to re-generate the structure of ul template, so i need to access the definition of the ul node at any time when user interact with my engine.

BR,
sid

Kenton Varda

unread,
Nov 6, 2019, 1:25:08 PM11/6/19
to Fay Wong, Cap'n Proto
Hi Fay,

I'm not sure I understand your question. Reader objects are reusable. Is there some problem you're running into when trying to reuse a reader object?

-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/dd7887fb-a1ac-498c-8589-4910d6d6d9cf%40googlegroups.com.
Message has been deleted

Fay Wong

unread,
Nov 13, 2019, 6:49:10 AM11/13/19
to Cap'n Proto
>>Reader objects are reusable
Is there some special API need to invoke or just use the Reader object as directly?

I noticed that when a reader object has been used once, the subsequent read will failed.

Is there some rewind operation need to be done just as the fread similar operation(i guess there may be some pointer internal)?


my code example:


kj::ArrayPtr<const kj::byte> byteArray((const kj::byte *) buf, (size_t) bufSize);
kj
::ArrayInputStream arrayInputStream(byteArray);
kj
::BufferedInputStreamWrapper input(arrayInputStream);
capnp
::PackedMessageReader message(input);


maybe i need to rewind the inputstream to the begin so as to reuse the Reader object to retrive the target object?

On Thursday, November 7, 2019 at 2:25:08 AM UTC+8, Kenton Varda wrote:
Hi Fay,

I'm not sure I understand your question. Reader objects are reusable. Is there some problem you're running into when trying to reuse a reader object?

-Kenton

On Tue, Nov 5, 2019 at 2:16 AM Fay Wong <philip...@gmail.com> wrote:
Just as the mail title.

How could i reuse a reader object after i have consumed it once?

I am implement a runtime mvvm ui engine, for example, <ul v-for="item in data.goodList" ...

when data.goodList changes, i need to re-generate the structure of ul template, so i need to access the definition of the ul node at any time when user interact with my engine.

BR,
sid

--
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 capn...@googlegroups.com.

Kenton Varda

unread,
Nov 13, 2019, 5:09:25 PM11/13/19
to Fay Wong, Cap'n Proto
Hi Fay,

What do you mean by "the subsequent read will fail". Fail how? An exception? Segmentation fault? You need to provide details for us to be able to help you.

It would also help if you provided a more complete code sample. The code you provided doesn't access any reader multiple times, so I'm not sure where the failure comes in.

-Kenton

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/6fe4c17c-a04c-4811-ad0b-aa3f39929e8f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages