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

The public API should explicitly show that objects are write-only or read-only #564

Open
matheusd opened this issue May 10, 2024 · 0 comments

Comments

@matheusd
Copy link
Contributor

This wasn't immediately clear to me and led me somewhat astray: capnproto messages are not safe for both decoding and writing.

To be clear: this is not a limitation of go-capnp itself, it's a limitation of the capnproto serialization format. In particular, decoding/unmarshalling a message and then attempting to modify it is not safe.

The original capnproto C++ API solves this by using two different object types for reading from unmarshalled data and creating data: a Builder hierarchy, used to build new objects and a Reader hierarchy, used after unmarshalling/decoding a byte stream.

While the current go-capnp API implicitly also somewhat encapsulates this behavior (attempting to use a byte slice as a message without going through unmarshalling will error), IMO this should be an explicit design element of the public-facing API.

I haven't thought this through significantly, but my initial opinion would be for something like ResetForRead() and ResetForWrite() marking the message as read-only or write-only, then erroring out when the wrong method is called (still mulling over this).

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

1 participant