-
Notifications
You must be signed in to change notification settings - Fork 14
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
[Rust] Support mutation #164
Comments
It wouldn't be quite as simple. All deserialized objects currently contain a I think a better approach would be to add additional One compromise could be to make the reference types generic so they could work with multiple slice types. |
Another option would be to improve the
All of these functions should suitably marked as being be sound (as in no segfaults), but not safe (as in it will allow invalid messages and/or wrong interpretation of messages). |
As a work-around, perhaps something like this could be of use?
use object::{Object, ObjectRef};
use planus::ReadAsRoot;
#[path = "object_generated.rs"]
mod object;
fn mutate_object(input: &[u8]) -> planus::Result<Vec<u8>> {
let object_ref: ObjectRef<'_> = ObjectRef::read_as_root(input)?;
let mut object: Object = object_ref.try_into()?;
object.counter += 1;
let mut builder = planus::Builder::new();
let finished = builder.finish(object, None);
Ok(finished.to_vec())
} Note however |
Yep, this is what I'm currently doing. It's not as optimal as a mutation API, but it works currently. |
Perhaps a better way to mutate data in a client-server architecture (where buffers from the client are untrusted) is to send over the field modifications from the client instead. This would make updates to large buffers a lot faster as compared to a O(n) validation of the new buffer. Mutations would then only happen in a trusted environment where safety isn't so much of an issue. Would need to write this "diff" format as another FBS schema. You could then load part or the whole buffer that's being modified and mutate the fields without changing or deserialising anything else if not needed. Could mutation work with non-scalar values if you load the whole message? Then inserting the new value into the offset and shifting the rest of the message to the right (perhaps updating any offsets as needed?). Also, if none of this makes sense, please forgive me. I don't know much about the internals of FBs yet. :) |
The above is very much usecase specific for us. Hopefully this is a better reply...
Extending the builder would probably mean smaller code size too, as I don't think you'd need extra I'm guessing it would be a bit clumsier to use than something like the syntax used for creating messages currently but we want it to be developer friendly too.
Validating the message in an O(n) way when loading would mean using |
Support mutating a deserialised object as seen in google/flatbuffers#5772
Maybe add setters to
[x]Ref
to set fields?The text was updated successfully, but these errors were encountered: