Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:17

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // These functions are only used by generated code.
0009 
0010 #ifndef UPB_MESSAGE_MAP_GENCODE_UTIL_H_
0011 #define UPB_MESSAGE_MAP_GENCODE_UTIL_H_
0012 
0013 #include "upb/message/internal/map.h"
0014 
0015 // Must be last.
0016 #include "upb/port/def.inc"
0017 
0018 #ifdef __cplusplus
0019 extern "C" {
0020 #endif
0021 
0022 // Message map operations, these get the map from the message first.
0023 
0024 UPB_INLINE void _upb_msg_map_key(const void* msg, void* key, size_t size) {
0025   const upb_tabent* ent = (const upb_tabent*)msg;
0026   uint32_t u32len;
0027   upb_StringView k;
0028   k.data = upb_tabstr(ent->key, &u32len);
0029   k.size = u32len;
0030   _upb_map_fromkey(k, key, size);
0031 }
0032 
0033 UPB_INLINE void _upb_msg_map_value(const void* msg, void* val, size_t size) {
0034   const upb_tabent* ent = (const upb_tabent*)msg;
0035   upb_value v = {ent->val.val};
0036   _upb_map_fromvalue(v, val, size);
0037 }
0038 
0039 UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
0040                                        size_t size) {
0041   upb_tabent* ent = (upb_tabent*)msg;
0042   // This is like _upb_map_tovalue() except the entry already exists
0043   // so we can reuse the allocated upb_StringView for string fields.
0044   if (size == UPB_MAPTYPE_STRING) {
0045     upb_StringView* strp = (upb_StringView*)(uintptr_t)ent->val.val;
0046     memcpy(strp, val, sizeof(*strp));
0047   } else {
0048     memcpy(&ent->val.val, val, size);
0049   }
0050 }
0051 
0052 #ifdef __cplusplus
0053 } /* extern "C" */
0054 #endif
0055 
0056 #include "upb/port/undef.inc"
0057 
0058 #endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */