Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify existing messages #40

Open
RobinUS2 opened this issue Sep 18, 2015 · 1 comment
Open

Modify existing messages #40

RobinUS2 opened this issue Sep 18, 2015 · 1 comment

Comments

@RobinUS2
Copy link

What is the most efficient way to edit an existing message? Basically I want to set a few fields on an already built message, but it seems that I need the builder for that (as there are no set methods on the Reader).

Is there a basic concept what is best to use this? Thanks!

@dwrensha
Copy link
Member

You can call MessageBuilder.setRoot(), which requires a copy. We could also implement a way to construct a MessageBuilder from some existing buffers without needing to copy. Such a constructor might cause weird behavior on maliciously constructed input, but on trusted input it would be fine.

Note also that using Cap'n Proto as a mutable format requires some care. Whenever you set a pointer field to a new value you'll leave behind dead space in the message where the old value was. If you're just modifying primitive fields, this isn't a problem. Also, you can effectively "garbage collect" such dead space away by copying a message into a new MessageBuilder with setRoot().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants