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 #ifndef UPB_MINI_TABLE_DECODE_H_
0009 #define UPB_MINI_TABLE_DECODE_H_
0010 
0011 #include "upb/base/status.h"
0012 #include "upb/mem/arena.h"
0013 #include "upb/mini_table/extension.h"
0014 #include "upb/mini_table/sub.h"
0015 
0016 // Export the newer headers, for legacy users.  New users should include the
0017 // more specific headers directly.
0018 // IWYU pragma: begin_exports
0019 #include "upb/mini_descriptor/build_enum.h"
0020 #include "upb/mini_descriptor/link.h"
0021 // IWYU pragma: end_exports
0022 
0023 // Must be last.
0024 #include "upb/port/def.inc"
0025 
0026 typedef enum {
0027   kUpb_MiniTablePlatform_32Bit,
0028   kUpb_MiniTablePlatform_64Bit,
0029   kUpb_MiniTablePlatform_Native =
0030       UPB_SIZE(kUpb_MiniTablePlatform_32Bit, kUpb_MiniTablePlatform_64Bit),
0031 } upb_MiniTablePlatform;
0032 
0033 #ifdef __cplusplus
0034 extern "C" {
0035 #endif
0036 
0037 // Builds a mini table from the data encoded in the buffer [data, len]. If any
0038 // errors occur, returns NULL and sets a status message. In the success case,
0039 // the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum
0040 // fields to link the table to the appropriate sub-tables.
0041 upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
0042                                     upb_MiniTablePlatform platform,
0043                                     upb_Arena* arena, upb_Status* status);
0044 
0045 UPB_API_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
0046                                                   upb_Arena* arena,
0047                                                   upb_Status* status) {
0048   return _upb_MiniTable_Build(data, len, kUpb_MiniTablePlatform_Native, arena,
0049                               status);
0050 }
0051 
0052 // Initializes a MiniTableExtension buffer that has already been allocated.
0053 // This is needed by upb_FileDef and upb_MessageDef, which allocate all of the
0054 // extensions together in a single contiguous array.
0055 const char* _upb_MiniTableExtension_Init(const char* data, size_t len,
0056                                          upb_MiniTableExtension* ext,
0057                                          const upb_MiniTable* extendee,
0058                                          upb_MiniTableSub sub,
0059                                          upb_MiniTablePlatform platform,
0060                                          upb_Status* status);
0061 
0062 UPB_API_INLINE const char* upb_MiniTableExtension_Init(
0063     const char* data, size_t len, upb_MiniTableExtension* ext,
0064     const upb_MiniTable* extendee, upb_MiniTableSub sub, upb_Status* status) {
0065   return _upb_MiniTableExtension_Init(data, len, ext, extendee, sub,
0066                                       kUpb_MiniTablePlatform_Native, status);
0067 }
0068 
0069 UPB_API upb_MiniTableExtension* _upb_MiniTableExtension_Build(
0070     const char* data, size_t len, const upb_MiniTable* extendee,
0071     upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena,
0072     upb_Status* status);
0073 
0074 UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_Build(
0075     const char* data, size_t len, const upb_MiniTable* extendee,
0076     upb_Arena* arena, upb_Status* status) {
0077   upb_MiniTableSub sub = upb_MiniTableSub_FromMessage(NULL);
0078   return _upb_MiniTableExtension_Build(
0079       data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status);
0080 }
0081 
0082 UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildMessage(
0083     const char* data, size_t len, const upb_MiniTable* extendee,
0084     upb_MiniTable* submsg, upb_Arena* arena, upb_Status* status) {
0085   upb_MiniTableSub sub = upb_MiniTableSub_FromMessage(submsg);
0086   return _upb_MiniTableExtension_Build(
0087       data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status);
0088 }
0089 
0090 UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildEnum(
0091     const char* data, size_t len, const upb_MiniTable* extendee,
0092     upb_MiniTableEnum* subenum, upb_Arena* arena, upb_Status* status) {
0093   upb_MiniTableSub sub = upb_MiniTableSub_FromEnum(subenum);
0094   return _upb_MiniTableExtension_Build(
0095       data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status);
0096 }
0097 
0098 // Like upb_MiniTable_Build(), but the user provides a buffer of layout data so
0099 // it can be reused from call to call, avoiding repeated realloc()/free().
0100 //
0101 // The caller owns `*buf` both before and after the call, and must free() it
0102 // when it is no longer in use.  The function will realloc() `*buf` as
0103 // necessary, updating `*size` accordingly.
0104 upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
0105                                           upb_MiniTablePlatform platform,
0106                                           upb_Arena* arena, void** buf,
0107                                           size_t* buf_size, upb_Status* status);
0108 
0109 #ifdef __cplusplus
0110 } /* extern "C" */
0111 #endif
0112 
0113 #include "upb/port/undef.inc"
0114 
0115 #endif /* UPB_MINI_TABLE_DECODE_H_ */