Commit graph

6 commits

Author SHA1 Message Date
Protobuf Team Bot
9d749cd5b0 Change Thunks that take by ref to take by pointer.
PiperOrigin-RevId: 592525870
2023-12-20 05:02:08 -08:00
Alyssa Haroldsen
f51182b543 Add RepeatedMut::clear, free for owned Repeated
PiperOrigin-RevId: 591046913
2023-12-14 14:11:56 -08:00
Jakob Buchgraber
976029283f Implement Maps for strings
This change implements maps with keys and values of type string e.g. Map<ProtoStr, i32> and Map<ProtoStr, ProtoStr>.

Implementing the Map type for ProtoStr has been different from scalar types because ProtoStr is an unsized type i.e. its size is not known at compile time. The existing Map implementation assumed sized types in many places. To make unsized types fit into the existing code architecture I have added an associated type 'Value' to the MapWith*KeyOps traits. The associated type needs to be sized and is the type returned by the Map::get(self, key) method e.g. for aProtoStr, the `type Value = &ProtoStr`.

PiperOrigin-RevId: 588783751
2023-12-07 07:25:00 -08:00
Jakob Buchgraber
001be3c655 Implement Maps for scalar types for the C++ kernel
This CL implements Maps for scalar types for the C++ runtime. It's orthogonal to cl/580453646. This CL is constrained by having to force template instantiation of proto2::Map<K, V>. Put differently, a Rust protobuf::Map<K, V> implementation needs to call 'extern "C"' functions with both key and value type in the function name (e.g. __pb_rust_Map_i32_f64_get()). We use macros to generate a Map implementation for every (K,V)-pair. An alternative would have been to use vtables.

Luckily a key in a protobuf map can only be integer types, bool and string. So the number of key types is bounded by the specification, while the number of value types is not i.e. any protobuf message can be a value in a map. Given these constraints we introduce one 'MapKeyOps' trait per key type e.g. MapKeyBOOLOps or MapKeyI32Ops. These traits need to be implemented for every value type e.g. 'impl MapKeyBOOLOps for i32' will implement 'Map::<bool, i32>'. In particular the MapKeyOps traits can also be implemented for generated messages without violating the orphan rule.

This CL also contains significant changes to the UPB runtime so that both upb.rs and cpp.rs export a similar interface to simplify the implementation in  map.rs and the generated code.

This CL does not yet implement the Proxied trait.

PiperOrigin-RevId: 582951914
2023-11-16 01:38:42 -08:00
Kevin King
65cdac4ac5 Finish Proxied impls for rust repeated scalars
PiperOrigin-RevId: 575935874
2023-10-23 14:54:44 -07:00
Protobuf Team Bot
e1bb7d65a8 Implement rust repeated scalars for cpp and upb
PiperOrigin-RevId: 574261929
2023-10-17 14:18:54 -07:00