We implement two functions to access map fields in UPB Go glue library:

1. getter function to access the upb_Map corresponding to a map proto field
2. conversion function to get a Go map from a upb_Map. The conversion function uses generics, so it must be a standalone function independent of `MessageAccessor`.

Accessing map fields is not as efficient as accessing other proto field types, because of two reasons:
- we need to make a copy of map values in Go, since the memory representations are different in UPB C
- we need to call C functions from Go, because the upb_Map struct fields are not exported and we can't access the bits directly, causing performance overhead

Luckily the map fields can be quite rare, so the performance overhead should not be too significant overall.

PiperOrigin-RevId: 559191359
pull/13675/head^2
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 243add4411
commit 043ad5ce6e
  1. 5
      upb/base/string_view.h

@ -47,7 +47,10 @@ typedef struct {
const char* data;
size_t size;
} upb_StringView;
// LINT.ThenChange(GoogleInternalName0)
// LINT.ThenChange(
// GoogleInternalName0,
// //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string
// )
#ifdef __cplusplus
extern "C" {

Loading…
Cancel
Save