Back to home page

EIC code displayed by LXR

 
 

    


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

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 #ifndef UPB_REFLECTION_MESSAGE_H_
0009 #define UPB_REFLECTION_MESSAGE_H_
0010 
0011 #include <stddef.h>
0012 
0013 #include "upb/mem/arena.h"
0014 #include "upb/message/map.h"
0015 #include "upb/message/message.h"
0016 #include "upb/reflection/common.h"
0017 
0018 // Must be last.
0019 #include "upb/port/def.inc"
0020 
0021 #ifdef __cplusplus
0022 extern "C" {
0023 #endif
0024 
0025 // Returns a mutable pointer to a map, array, or submessage value. If the given
0026 // arena is non-NULL this will construct a new object if it was not previously
0027 // present. May not be called for primitive fields.
0028 UPB_API upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg,
0029                                                     const upb_FieldDef* f,
0030                                                     upb_Arena* a);
0031 
0032 // Returns the field that is set in the oneof, or NULL if none are set.
0033 UPB_API const upb_FieldDef* upb_Message_WhichOneofByDef(const upb_Message* msg,
0034                                                         const upb_OneofDef* o);
0035 
0036 // Clear all data and unknown fields.
0037 void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m);
0038 
0039 // Clears any field presence and sets the value back to its default.
0040 UPB_API void upb_Message_ClearFieldByDef(upb_Message* msg,
0041                                          const upb_FieldDef* f);
0042 
0043 // May only be called for fields where upb_FieldDef_HasPresence(f) == true.
0044 UPB_API bool upb_Message_HasFieldByDef(const upb_Message* msg,
0045                                        const upb_FieldDef* f);
0046 
0047 // Returns the value in the message associated with this field def.
0048 UPB_API upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg,
0049                                                    const upb_FieldDef* f);
0050 
0051 // Sets the given field to the given value. For a msg/array/map/string, the
0052 // caller must ensure that the target data outlives |msg| (by living either in
0053 // the same arena or a different arena that outlives it).
0054 //
0055 // Returns false if allocation fails.
0056 UPB_API bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
0057                                        upb_MessageValue val, upb_Arena* a);
0058 
0059 // Iterate over present fields.
0060 //
0061 // size_t iter = kUpb_Message_Begin;
0062 // const upb_FieldDef *f;
0063 // upb_MessageValue val;
0064 // while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) {
0065 //   process_field(f, val);
0066 // }
0067 //
0068 // If ext_pool is NULL, no extensions will be returned.  If the given symtab
0069 // returns extensions that don't match what is in this message, those extensions
0070 // will be skipped.
0071 
0072 #define kUpb_Message_Begin -1
0073 
0074 UPB_API bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
0075                               const upb_DefPool* ext_pool,
0076                               const upb_FieldDef** f, upb_MessageValue* val,
0077                               size_t* iter);
0078 
0079 // Clears all unknown field data from this message and all submessages.
0080 UPB_API bool upb_Message_DiscardUnknown(upb_Message* msg,
0081                                         const upb_MessageDef* m, int maxdepth);
0082 
0083 #ifdef __cplusplus
0084 } /* extern "C" */
0085 #endif
0086 
0087 #include "upb/port/undef.inc"
0088 
0089 #endif /* UPB_REFLECTION_MESSAGE_H_ */