1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2023 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ 9 #define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ 10 11 #include <stdint.h> 12 13 #include "upb/base/string_view.h" 14 #include "upb/hash/common.h" 15 #include "upb/message/internal/types.h" 16 17 // Map entries aren't actually stored for map fields, they are only used during 18 // parsing. (It helps a lot if all map entry messages have the same layout.) 19 // The mini_table layout code will ensure that all map entries have this layout. 20 // 21 // Note that users can and do create map entries directly, which will also use 22 // this layout. 23 24 typedef struct { 25 struct upb_Message message; 26 // We only need 2 hasbits max, but due to alignment we'll use 8 bytes here, 27 // and the uint64_t helps make this clear. 28 uint64_t hasbits; 29 union { 30 upb_StringView str; // For str/bytes. 31 upb_value val; // For all other types. 32 double d[2]; // Padding for 32-bit builds. 33 } k; 34 union { 35 upb_StringView str; // For str/bytes. 36 upb_value val; // For all other types. 37 double d[2]; // Padding for 32-bit builds. 38 } v; 39 } upb_MapEntry; 40 41 #endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ 42