Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:25:23

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 /*
0009 ** Our memory representation for parsing tables and messages themselves.
0010 ** Functions in this file are used by generated code and possibly reflection.
0011 **
0012 ** The definitions in this file are internal to upb.
0013 **/
0014 
0015 #ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_
0016 #define UPB_MESSAGE_INTERNAL_MESSAGE_H_
0017 
0018 #include <stdlib.h>
0019 #include <string.h>
0020 
0021 #include "upb/mem/arena.h"
0022 #include "upb/message/internal/extension.h"
0023 #include "upb/mini_table/message.h"
0024 
0025 // Must be last.
0026 #include "upb/port/def.inc"
0027 
0028 #ifdef __cplusplus
0029 extern "C" {
0030 #endif
0031 
0032 extern const float kUpb_FltInfinity;
0033 extern const double kUpb_Infinity;
0034 extern const double kUpb_NaN;
0035 
0036 // Internal members of a upb_Message that track unknown fields and/or
0037 // extensions. We can change this without breaking binary compatibility.
0038 
0039 typedef struct upb_Message_Internal {
0040   // Total size of this structure, including the data that follows.
0041   // Must be aligned to 8, which is alignof(upb_Extension)
0042   uint32_t size;
0043 
0044   /* Offsets relative to the beginning of this structure.
0045    *
0046    * Unknown data grows forward from the beginning to unknown_end.
0047    * Extension data grows backward from size to ext_begin.
0048    * When the two meet, we're out of data and have to realloc.
0049    *
0050    * If we imagine that the final member of this struct is:
0051    *   char data[size - overhead];  // overhead = sizeof(upb_Message_Internal)
0052    *
0053    * Then we have:
0054    *   unknown data: data[0 .. (unknown_end - overhead)]
0055    *   extensions data: data[(ext_begin - overhead) .. (size - overhead)] */
0056   uint32_t unknown_end;
0057   uint32_t ext_begin;
0058   // Data follows, as if there were an array:
0059   //   char data[size - sizeof(upb_Message_Internal)];
0060 } upb_Message_Internal;
0061 
0062 #ifdef UPB_TRACING_ENABLED
0063 UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
0064                                        const upb_Arena* arena);
0065 UPB_API void upb_Message_SetNewMessageTraceHandler(
0066     void (*handler)(const upb_MiniTable*, const upb_Arena*));
0067 #endif  // UPB_TRACING_ENABLED
0068 
0069 // Inline version upb_Message_New(), for internal use.
0070 UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* m,
0071                                                 upb_Arena* a) {
0072 #ifdef UPB_TRACING_ENABLED
0073   upb_Message_LogNewMessage(m, a);
0074 #endif  // UPB_TRACING_ENABLED
0075 
0076   const int size = m->UPB_PRIVATE(size);
0077   struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size);
0078   if (UPB_UNLIKELY(!msg)) return NULL;
0079   memset(msg, 0, size);
0080   return msg;
0081 }
0082 
0083 // Discards the unknown fields for this message only.
0084 void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg);
0085 
0086 // Adds unknown data (serialized protobuf data) to the given message.
0087 // The data is copied into the message instance.
0088 bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
0089                                           const char* data, size_t len,
0090                                           upb_Arena* arena);
0091 
0092 bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
0093                                        upb_Arena* arena);
0094 
0095 #ifdef __cplusplus
0096 } /* extern "C" */
0097 #endif
0098 
0099 #include "upb/port/undef.inc"
0100 
0101 #endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */