Cap'n Proto 0.9 released
capnproto.org/news/2021-08-14-capnproto-0.9.htmlPosted Aug 15, 2021, 6:22 AM UTC
6410
Posted Aug 15, 2021, 6:22 AM UTC
Still a bit confused. Pointers are send over network to another machine? How would target machine dereference it? Or this is really just for one machine?
Think “offset”, instead of pointer, and with ways to validate.
Ah.. so it's "like" casting raw bytes to struct with validations.
Cap'n Proto is an interchange format and RPC protocol that works without decoding/encoding messages. It is a bit like protobuf, without the serialization/deserialization step.
It has multiple implementations (C++, Rust, Python) and a powerful interface language.
I've been using it for some time now and I'm a happy user.
How can you not serialize data when you are sending them over wire?
In formats like JSON or Protobuf, a field is at an unknown position within an object. You have to parse everything leading up to that field within the object to find and use a single field.
For example, in JSON to get
.betain an object like this:you first have to parse all of
alpha. You have to parse it since whether or not a"beta":belongs to the original object or a nested object depends on how "nested" that"beta":is; in the above example, the first textual occurrence of"beta"is not the field we're looking for. To know that, we have to track the opening and closing of objects and strings.The other cost of a format like this is making multiple accesses. After fetching
.beta, f you want to read.gamma, you have to either do all this again, or allocate additional data-structures (usually hashtables) that index where each field is within each (sub)object.In Cap'n Proto, a field is always at a known fixed position relative to the start of the object. So, you don't need to parse anything that comes before it to know where it is. For the above object, this looks something like (but not exactly)
Variable-size elements, like sub-objects and arrays, are stored using "relative pointers" -- the offset between where the pointer is, and where the pointed-at data is. As long as you check the resulting offset is still in bounds of the original binary blob (e.g., in this case, it's at most offset 7), the access is "safe".
This doesn't require allocating any additional structures per message, and it doesn't require accessing any words you don't specifically ask for.
Sending pointers over the network, what could go wrong? But your explanation makes total sense.
I mean, conceptually, this is no different from any other way of sending variable length data. It's no more scary than the Content-Length HTTP header.
https://capnproto.org/
I asked: Does this mean they are sending pointers?
Their FAQ said: Yes but they claim it's secure.
I didn't go too deep in to read all the docs.
From the FAQ
It's secure as long as the length of the buffer containing the message is known, the implementation can systematically check each offset for overflow before adding it to the base and dereferencing.
[deleted]