Back to home page

EIC code displayed by LXR

 
 

    


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

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_UTIL_REQUIRED_FIELDS_H_
0009 #define UPB_UTIL_REQUIRED_FIELDS_H_
0010 
0011 #include <stddef.h>
0012 
0013 #include "upb/reflection/def.h"
0014 #include "upb/reflection/message.h"
0015 
0016 // Must be last.
0017 #include "upb/port/def.inc"
0018 
0019 #ifdef __cplusplus
0020 extern "C" {
0021 #endif
0022 
0023 // A FieldPath can be encoded as an array of upb_FieldPathEntry, in the
0024 // following format:
0025 //    { {.field = f1}, {.field = f2} }                      # f1.f2
0026 //    { {.field = f1}, {.index = 5}, {.field = f2} }        # f1[5].f2
0027 //    { {.field = f1}, {.key = "abc"}, {.field = f2} }      # f1["abc"].f2
0028 //
0029 // Users must look at the type of `field` to know if an index or map key
0030 // follows.
0031 //
0032 // A field path may be NULL-terminated, in which case a NULL field indicates
0033 // the end of the field path.
0034 typedef union {
0035   const upb_FieldDef* field;
0036   size_t array_index;
0037   upb_MessageValue map_key;
0038 } upb_FieldPathEntry;
0039 
0040 // Writes a string representing `*path` to `buf` in the following textual
0041 // format:
0042 //    foo.bar                    # Regular fields
0043 //    repeated_baz[2].bar        # Repeated field
0044 //    int32_msg_map[5].bar       # Integer-keyed map
0045 //    string_msg_map["abc"]      # String-keyed map
0046 //    bool_msg_map[true]         # Bool-keyed map
0047 //
0048 // The input array `*path` must be NULL-terminated.  The pointer `*path` will be
0049 // updated to point to one past the terminating NULL pointer of the input array.
0050 //
0051 // The output buffer `buf` will always be NULL-terminated. If the output data
0052 // (including NULL terminator) exceeds `size`, the result will be truncated.
0053 // Returns the string length of the data we attempted to write, excluding the
0054 // terminating NULL.
0055 size_t upb_FieldPath_ToText(upb_FieldPathEntry** path, char* buf, size_t size);
0056 
0057 // Checks whether `msg` or any of its children has unset required fields,
0058 // returning `true` if any are found.  `msg` may be NULL, in which case the
0059 // message will be treated as empty.
0060 //
0061 // When this function returns true, `fields` is updated (if non-NULL) to point
0062 // to a heap-allocated array encoding the field paths of the required fields
0063 // that are missing.  Each path is terminated with {.field = NULL}, and a final
0064 // {.field = NULL} terminates the list of paths.  The caller is responsible for
0065 // freeing this array.
0066 bool upb_util_HasUnsetRequired(const upb_Message* msg, const upb_MessageDef* m,
0067                                const upb_DefPool* ext_pool,
0068                                upb_FieldPathEntry** fields);
0069 
0070 #ifdef __cplusplus
0071 } /* extern "C" */
0072 #endif
0073 
0074 #include "upb/port/undef.inc"
0075 
0076 #endif /* UPB_UTIL_REQUIRED_FIELDS_H_ */