The non-string field setters can bypass the vtables already, the string setters still go through the vtable path here because its more important to let them take an `impl SettableValue` to be able to set either a &str or a &ProtoStr already.
PiperOrigin-RevId: 609705233
The purpose is to avoid duplicating the mapping of different types that are only relevant to the serializer but not to the exposed api (e.g. FIXED32 vs INT32)
Treat type=GROUP as rust-type=MESSAGE here which is all that is needed for us to support groups in the rust codegen.
The RustFieldType is parallel to the preexisting FieldDescriptor::CppType which _almost_ does what we need, but it treats Bytes and Strings as the same cpptype which Rust codegen doesn't.
PiperOrigin-RevId: 609416940
Needed to pass in the message as a parameter to the clearer thunk!
Now the clear() augmentations in accessors_test.rs are working as expected.
PiperOrigin-RevId: 603394469
Add convenience _opt for singular message fields.
Users can detect if the message is set or unset, and unwrap via into_inner.
PiperOrigin-RevId: 602749065
This is the final CL (part 4 of 4) in the ProxiedWithPresence chain.
In the past, we had returned Mut directly for the `_mut` accessors.
This was a temporary engagement in order to get the other submsg machinery checked in.
As we prep for the finalization of v0.6, we can finally conform to the rest of the `_mut` getters.
$field$_mut now correctly returns $pb$::FieldEntry<'_, $msg_type$> as a part of this.
All test callsites have been updated to `.or_default` in order to test the mutational pathway as before.
PiperOrigin-RevId: 602739186
For the cpp runtime, call the `Message::CopyFrom` method.
For the upb runtime, expose the message `MiniTable` and call `upb_Message_DeepCopy`.
PiperOrigin-RevId: 595166276
accessors_test.rs is getting a bit unwieldy, approaching 1K LOC. This CL breaks out the repeated tests into their own file (accessors_repeated_test.rs), as we expect the tests here to grow. This follows the precedent of `accessors_map_test.rs`.
PiperOrigin-RevId: 588554476
We've had access to views for submessages for a while:
If you hit some_message.submsg().some_int(), you'll get a view for that int.
Until now, there hasn't been a way to get some_message.submsg_mut(), so we introduce the mutational pathway here.
We haven't added fully-functioning mutation, but this is a step towards that goal.
subview was inaccurate, so I've refactored and renamed: { accessor_fns_for_views, accessor_fns_for_muts }.
PiperOrigin-RevId: 581984371
We continue our foray into googletest-rust [1], this time with homegrown matchers.
Our unit tests will now be able to check is_unset() and is_set() for all types that implement ProxiedWithPresence. In practice, this boils down to [u8] and ProtoStr.
Note that we've broken out matchers_upb and matchers_cpp, similar to what was done with aliasing here [2].
[1] https://github.com/google/googletest-rust
[2] 9a0bc392b3 (diff-08e5182ff36ad340a3bfb628995524a2a36a89b59a514ba027b0f25e048dd5c3R90)
PiperOrigin-RevId: 573895179
$Msg$View is incorrect, we need to actually invoke the getter_thunks. We'll use void* to get us off to the races.
Sprinkled in TODOs as appropriate; and we'll tackle imports in another CL. For now, its important to return the actual raw message, and that's what this CL does for our base uses.
PiperOrigin-RevId: 564785201
This is predominantly a wrapper around `BytesMut`, for simplicity.
Bytes and string fields are mostly the same, except for possible UTF-8 handling.
This also implements some minor parts of `ProtoStr` that were missed.
PiperOrigin-RevId: 561422951
This makes a few changes:
- It changes generated messages to reference message innards as a type in `__runtime` instead of branching on what fields should be there. That results in much less bifurcation in gencode and lets runtime-agnostic code reference raw message innards.
- It adds a generic mechanism for creating vtable-based mutators. These vtables point to thunks generated for interacting with C++ or upb fields. Right now, the design results in 2-word (msg+vtable) mutators for C++ and 3-word mutators (msg+arena+vtable) for UPB. See upb.rs for an explanation of the design options. I chose the `RawMessage+&Arena` design for mutator data as opposed to a `&MessageInner` design because it did not result in extra-indirection layout changes for message mutators. We could revisit this in the future with performance data, since this results in all field mutators being 3 words large instead of the register-friendly 2 words.
- And lastly, as a nearby change that touches on many of the same topics, it adds some extra SAFETY comments for Send/Sync in message gencode.
PiperOrigin-RevId: 559483437
Only emit has_field() if the field support presence. Only emit field_opt() getter if the field is both optional and supports presence.
PiperOrigin-RevId: 555133374
This CL adds function bodies for: {as_view, into_view, as_mut, into_mut, set_on} [1].
Our prior cl/552609955 didn't have `RawMessage` inside $Msg$Mut, so that's also been rectified in this CL.
[1] Everything in this set is a part of the Proxied trait, except set_on, which belongs to the SettableValue trait.
PiperOrigin-RevId: 553935803
This CL sets up the basic plumbing end-to-end for singular message fields.
We add skeletonized support for `Proxied` messages. This is done
by creating structs for $Msg$View and $Msg$Mut, and providing
stubbed impls.
PiperOrigin-RevId: 552609955
We were always emitting Optional<T> for accessors, when they should've been behind `_opt`.
We've refactored our previous accessor into `getter` and `getter_opt`. We'll only emit `getter_opt` when we're dealing with optional fields.
PiperOrigin-RevId: 544087591
Needed to lowercase fieldnames and add underscores when they use protected cpp names. Ended up using `cpp::FieldName` from the cpp impl to get this for free.
Also added escaping to Rust accessors, so that protected keywords will compile.
PiperOrigin-RevId: 543995050
Before this CL all messages were generated in the top-level crate module. With
this change we generate messages under the module specified by the package
declaration in the .proto file.
Dots are interpreted as submodule separator in consistency with how C++
namespaces are handled.
Note that name of the proto_library target still remains to be used as the crate name. This CL only adds crate submodules dependeing on the specified package.
PiperOrigin-RevId: 524235162