@ -359,8 +359,8 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
# endif /* UPB_BASE_STATUS_H_ */
# ifndef UPB_INTERNAL_ARRAY_INTERNAL _H_
# define UPB_INTERNAL_ARRAY_INTERNAL _H_
# ifndef UPB_COLLECTIONS_ INTERNAL_ARRAY_H_
# define UPB_COLLECTIONS_ INTERNAL_ARRAY_H_
# include <string.h>
@ -1366,7 +1366,7 @@ UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) {
# endif
# endif /* UPB_INTERNAL_ARRAY_INTERNAL _H_ */
# endif /* UPB_COLLECTIONS_ INTERNAL_ARRAY_H_ */
# ifndef UPB_COLLECTIONS_MAP_H_
# define UPB_COLLECTIONS_MAP_H_
@ -1479,8 +1479,8 @@ UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter);
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
# ifndef UPB_COLLECTIONS_MAP_ INTERNAL_H_
# define UPB_COLLECTIONS_MAP_ INTERNAL_H_
# ifndef UPB_COLLECTIONS_INTERNAL_MAP _H_
# define UPB_COLLECTIONS_INTERNAL_MAP _H_
# ifndef UPB_HASH_STR_TABLE_H_
@ -1916,47 +1916,18 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size);
# endif
# endif /* UPB_COLLECTIONS_MAP_INTERNAL_H_ */
# ifndef UPB_BASE_LOG2_H_
# define UPB_BASE_LOG2_H_
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
UPB_INLINE int upb_Log2Ceiling ( int x ) {
if ( x < = 1 ) return 0 ;
# ifdef __GNUC__
return 32 - __builtin_clz ( x - 1 ) ;
# else
int lg2 = 0 ;
while ( ( 1 < < lg2 ) < x ) lg2 + + ;
return lg2 ;
# endif
}
UPB_INLINE int upb_Log2CeilingSize ( int x ) { return 1 < < upb_Log2Ceiling ( x ) ; }
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_BASE_LOG2_H_ */
# endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
# ifndef UPB_COLLECTIONS_MAP_SORTER_INTERNAL _H_
# define UPB_COLLECTIONS_MAP_SORTER_INTERNAL _H_
# ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
# define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_
# include <stdlib.h>
# ifndef UPB_MESSAGE_EXTENSION_INTERNAL _H_
# define UPB_MESSAGE_EXTENSION_INTERNAL _H_
# ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
# define UPB_MESSAGE_INTERNAL_EXTENSION_H_
// Public APIs for message operations that do not depend on the schema.
@ -2070,7 +2041,7 @@ const upb_Message_Extension* _upb_Message_Getext(
# endif
# endif /* UPB_MESSAGE_EXTENSION_INTERNAL _H_ */
# endif /* UPB_MESSAGE_INTERNAL_ EXTENSION_H_ */
# ifndef UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
# define UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
@ -2110,7 +2081,7 @@ typedef struct {
// require 8-byte alignment.
double d ;
} ;
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal.h:internal_layout)
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal/message .h:internal_layout)
upb_MapEntryData data ;
} upb_MapEntry ;
@ -2184,7 +2155,36 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
# endif
# endif /* UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ */
# endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */
# ifndef UPB_BASE_LOG2_H_
# define UPB_BASE_LOG2_H_
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
UPB_INLINE int upb_Log2Ceiling ( int x ) {
if ( x < = 1 ) return 0 ;
# ifdef __GNUC__
return 32 - __builtin_clz ( x - 1 ) ;
# else
int lg2 = 0 ;
while ( ( 1 < < lg2 ) < x ) lg2 + + ;
return lg2 ;
# endif
}
UPB_INLINE int upb_Log2CeilingSize ( int x ) { return 1 < < upb_Log2Ceiling ( x ) ; }
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_BASE_LOG2_H_ */
# ifndef UPB_GENERATED_CODE_SUPPORT_H_
# define UPB_GENERATED_CODE_SUPPORT_H_
@ -2244,6 +2244,10 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
# define UPB_MESSAGE_ACCESSORS_H_
# ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
# define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
/*
* * Our memory representation for parsing tables and messages themselves .
* * Functions in this file are used by generated code and possibly reflection .
@ -2423,10 +2427,6 @@ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len,
# endif /* UPB_MESSAGE_INTERNAL_H_ */
# ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
# define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
// Must be last.
# if defined(__GNUC__) && !defined(__clang__)
@ -11732,12 +11732,12 @@ UPB_INLINE const char* upb_WireReader_SkipValue(
# endif // UPB_WIRE_READER_H_
# ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL _H_
# define UPB_REFLECTION_DEF_BUILDER_INTERNAL _H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER _H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER _H_
# ifndef UPB_REFLECTION_DEF_POOL_INTERNAL _H_
# define UPB_REFLECTION_DEF_POOL_INTERNAL _H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92 _H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92 _H_
// Must be last.
@ -11746,117 +11746,377 @@ UPB_INLINE const char* upb_WireReader_SkipValue(
extern " C " {
# endif
upb_Arena * _upb_DefPool_Arena ( const upb_DefPool * s ) ;
size_t _upb_DefPool_BytesLoaded ( const upb_DefPool * s ) ;
upb_ExtensionRegistry * _upb_DefPool_ExtReg ( const upb_DefPool * s ) ;
bool _upb_DefPool_InsertExt ( upb_DefPool * s , const upb_MiniTableExtension * ext ,
const upb_FieldDef * f ) ;
bool _upb_DefPool_InsertSym ( upb_DefPool * s , upb_StringView sym , upb_value v ,
upb_Status * status ) ;
bool _upb_DefPool_LookupSym ( const upb_DefPool * s , const char * sym , size_t size ,
upb_value * v ) ;
void * * _upb_DefPool_ScratchData ( const upb_DefPool * s ) ;
size_t * _upb_DefPool_ScratchSize ( const upb_DefPool * s ) ;
void _upb_DefPool_SetPlatform ( upb_DefPool * s , upb_MiniTablePlatform platform ) ;
// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init * * deps ; // Dependencies of this file.
const upb_MiniTableFile * layout ;
const char * filename ;
upb_StringView descriptor ; // Serialized descriptor.
} _upb_DefPool_Init ;
UPB_INLINE char _upb_ToBase92 ( int8_t ch ) {
extern const char _kUpb_ToBase92 [ ] ;
UPB_ASSERT ( 0 < = ch & & ch < 92 ) ;
return _kUpb_ToBase92 [ ch ] ;
}
bool _upb_DefPool_LoadDefInit ( upb_DefPool * s , const _upb_DefPool_Init * init ) ;
UPB_INLINE char _upb_FromBase92 ( uint8_t ch ) {
extern const int8_t _kUpb_FromBase92 [ ] ;
if ( ' ' > ch | | ch > ' ~ ' ) return - 1 ;
return _kUpb_FromBase92 [ ch - ' ' ] ;
}
// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx ( upb_DefPool * s , const _upb_DefPool_Init * init ,
bool rebuild_minitable ) ;
UPB_INLINE const char * _upb_Base92_DecodeVarint ( const char * ptr ,
const char * end , char first_ch ,
uint8_t min , uint8_t max ,
uint32_t * out_val ) {
uint32_t val = 0 ;
uint32_t shift = 0 ;
const int bits_per_char =
upb_Log2Ceiling ( _upb_FromBase92 ( max ) - _upb_FromBase92 ( min ) ) ;
char ch = first_ch ;
while ( 1 ) {
uint32_t bits = _upb_FromBase92 ( ch ) - _upb_FromBase92 ( min ) ;
val | = bits < < shift ;
if ( ptr = = end | | * ptr < min | | max < * ptr ) {
* out_val = val ;
UPB_ASSUME ( ptr ! = NULL ) ;
return ptr ;
}
ch = * ptr + + ;
shift + = bits_per_char ;
if ( shift > = 32 ) return NULL ;
}
}
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
// Must be last.
// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
# define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
if ( UPB_DESC ( desc_type # # _has_options ) ( proto ) ) { \
size_t size ; \
char * pb = UPB_DESC ( options_type # # _serialize ) ( \
UPB_DESC ( desc_type # # _options ) ( proto ) , ctx - > tmp_arena , & size ) ; \
if ( ! pb ) _upb_DefBuilder_OomErr ( ctx ) ; \
target = \
UPB_DESC ( options_type # # _parse ) ( pb , size , _upb_DefBuilder_Arena ( ctx ) ) ; \
if ( ! target ) _upb_DefBuilder_OomErr ( ctx ) ; \
} else { \
target = ( const UPB_DESC ( options_type ) * ) kUpbDefOptDefault ; \
}
// upb_MdDecoder: used internally for decoding MiniDescriptors for messages,
// extensions, and enums.
typedef struct {
const char * end ;
upb_Status * status ;
jmp_buf err ;
} upb_MdDecoder ;
# ifdef __cplusplus
extern " C " {
# endif
UPB_PRINTF ( 2 , 3 )
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp ( upb_MdDecoder * d ,
const char * fmt , . . . ) {
if ( d - > status ) {
va_list argp ;
upb_Status_SetErrorMessage ( d - > status , " Error building mini table: " ) ;
va_start ( argp , fmt ) ;
upb_Status_VAppendErrorFormat ( d - > status , fmt , argp ) ;
va_end ( argp ) ;
}
UPB_LONGJMP ( d - > err , 1 ) ;
}
struct upb_DefBuilder {
upb_DefPool * symtab ;
upb_FileDef * file ; // File we are building.
upb_Arena * arena ; // Allocate defs here.
upb_Arena * tmp_arena ; // For temporary allocations.
upb_Status * status ; // Record errors here.
const upb_MiniTableFile * layout ; // NULL if we should build layouts.
upb_MiniTablePlatform platform ; // Platform we are targeting.
int enum_count ; // Count of enums built so far.
int msg_count ; // Count of messages built so far.
int ext_count ; // Count of extensions built so far.
jmp_buf err ; // longjmp() on error.
} ;
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory ( upb_MdDecoder * d ,
const void * ptr ) {
if ( ! ptr ) upb_MdDecoder_ErrorJmp ( d , " Out of memory " ) ;
}
extern const char * kUpbDefOptDefault ;
UPB_INLINE const char * upb_MdDecoder_DecodeBase92Varint (
upb_MdDecoder * d , const char * ptr , char first_ch , uint8_t min , uint8_t max ,
uint32_t * out_val ) {
ptr = _upb_Base92_DecodeVarint ( ptr , d - > end , first_ch , min , max , out_val ) ;
if ( ! ptr ) upb_MdDecoder_ErrorJmp ( d , " Overlong varint " ) ;
return ptr ;
}
// ctx->status has already been set elsewhere so just fail/longjmp()
UPB_NORETURN void _upb_DefBuilder_FailJmp ( upb_DefBuilder * ctx ) ;
UPB_NORETURN void _upb_DefBuilder_Errf ( upb_DefBuilder * ctx , const char * fmt ,
. . . ) UPB_PRINTF ( 2 , 3 ) ;
UPB_NORETURN void _upb_DefBuilder_OomErr ( upb_DefBuilder * ctx ) ;
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
const char * _upb_DefBuilder_MakeFullName ( upb_DefBuilder * ctx ,
const char * prefix ,
upb_StringView name ) ;
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
// Given a symbol and the base symbol inside which it is defined,
// find the symbol's definition.
const void * _upb_DefBuilder_ResolveAny ( upb_DefBuilder * ctx ,
const char * from_name_dbg ,
const char * base , upb_StringView sym ,
upb_deftype_t * type ) ;
const void * _upb_DefBuilder_Resolve ( upb_DefBuilder * ctx ,
const char * from_name_dbg , const char * base ,
upb_StringView sym , upb_deftype_t type ) ;
// Must be last.
char _upb_DefBuilder_ParseEscape ( upb_DefBuilder * ctx , const upb_FieldDef * f ,
const char * * src , const char * end ) ;
typedef enum {
kUpb_EncodedType_Double = 0 ,
kUpb_EncodedType_Float = 1 ,
kUpb_EncodedType_Fixed32 = 2 ,
kUpb_EncodedType_Fixed64 = 3 ,
kUpb_EncodedType_SFixed32 = 4 ,
kUpb_EncodedType_SFixed64 = 5 ,
kUpb_EncodedType_Int32 = 6 ,
kUpb_EncodedType_UInt32 = 7 ,
kUpb_EncodedType_SInt32 = 8 ,
kUpb_EncodedType_Int64 = 9 ,
kUpb_EncodedType_UInt64 = 10 ,
kUpb_EncodedType_SInt64 = 11 ,
kUpb_EncodedType_OpenEnum = 12 ,
kUpb_EncodedType_Bool = 13 ,
kUpb_EncodedType_Bytes = 14 ,
kUpb_EncodedType_String = 15 ,
kUpb_EncodedType_Group = 16 ,
kUpb_EncodedType_Message = 17 ,
kUpb_EncodedType_ClosedEnum = 18 ,
const char * _upb_DefBuilder_FullToShort ( const char * fullname ) ;
kUpb_EncodedType_RepeatedBase = 20 ,
} upb_EncodedType ;
UPB_INLINE void * _upb_DefBuilder_Alloc ( upb_DefBuilder * ctx , size_t bytes ) {
if ( bytes = = 0 ) return NULL ;
void * ret = upb_Arena_Malloc ( ctx - > arena , bytes ) ;
if ( ! ret ) _upb_DefBuilder_OomErr ( ctx ) ;
return ret ;
}
typedef enum {
kUpb_EncodedFieldModifier_FlipPacked = 1 < < 0 ,
kUpb_EncodedFieldModifier_IsRequired = 1 < < 1 ,
kUpb_EncodedFieldModifier_IsProto3Singular = 1 < < 2 ,
} upb_EncodedFieldModifier ;
// Adds a symbol |v| to the symtab, which must be a def pointer previously
// packed with pack_def(). The def's pointer to upb_FileDef* must be set before
// adding, so we know which entries to remove if building this file fails.
enum {
kUpb_EncodedValue_MinField = ' ' ,
kUpb_EncodedValue_MaxField = ' I ' ,
kUpb_EncodedValue_MinModifier = ' L ' ,
kUpb_EncodedValue_MaxModifier = ' [ ' ,
kUpb_EncodedValue_End = ' ^ ' ,
kUpb_EncodedValue_MinSkip = ' _ ' ,
kUpb_EncodedValue_MaxSkip = ' ~ ' ,
kUpb_EncodedValue_OneofSeparator = ' ~ ' ,
kUpb_EncodedValue_FieldSeparator = ' | ' ,
kUpb_EncodedValue_MinOneofField = ' ' ,
kUpb_EncodedValue_MaxOneofField = ' b ' ,
kUpb_EncodedValue_MaxEnumMask = ' A ' ,
} ;
enum {
kUpb_EncodedVersion_EnumV1 = ' ! ' ,
kUpb_EncodedVersion_ExtensionV1 = ' # ' ,
kUpb_EncodedVersion_MapV1 = ' % ' ,
kUpb_EncodedVersion_MessageV1 = ' $ ' ,
kUpb_EncodedVersion_MessageSetV1 = ' & ' ,
} ;
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
// Must be last.
typedef enum {
kUpb_FieldModifier_IsRepeated = 1 < < 0 ,
kUpb_FieldModifier_IsPacked = 1 < < 1 ,
kUpb_FieldModifier_IsClosedEnum = 1 < < 2 ,
kUpb_FieldModifier_IsProto3Singular = 1 < < 3 ,
kUpb_FieldModifier_IsRequired = 1 < < 4 ,
} kUpb_FieldModifier ;
typedef enum {
kUpb_MessageModifier_ValidateUtf8 = 1 < < 0 ,
kUpb_MessageModifier_DefaultIsPacked = 1 < < 1 ,
kUpb_MessageModifier_IsExtendable = 1 < < 2 ,
} kUpb_MessageModifier ;
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
// Must be last.
// If the input buffer has at least this many bytes available, the encoder call
// is guaranteed to succeed (as long as field number order is maintained).
# define kUpb_MtDataEncoder_MinSize 16
typedef struct {
char * end ; // Limit of the buffer passed as a parameter.
// Aliased to internal-only members in .cc.
char internal [ 32 ] ;
} upb_MtDataEncoder ;
# ifdef __cplusplus
extern " C " {
# endif
// Encodes field/oneof information for a given message. The sequence of calls
// should look like:
//
// upb_MtDataEncoder e;
// char buf[256];
// char* ptr = buf;
// e.end = ptr + sizeof(buf);
// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero
// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod);
// // Fields *must* be in field number order.
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
//
// // If oneofs are present. Oneofs must be encoded after regular fields.
// ptr = upb_MiniTable_StartOneof(&e, ptr)
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// ptr = upb_MiniTable_StartOneof(&e, ptr);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// Oneofs must be encoded after all regular fields.
char * upb_MtDataEncoder_StartMessage ( upb_MtDataEncoder * e , char * ptr ,
uint64_t msg_mod ) ;
char * upb_MtDataEncoder_PutField ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType type , uint32_t field_num ,
uint64_t field_mod ) ;
char * upb_MtDataEncoder_StartOneof ( upb_MtDataEncoder * e , char * ptr ) ;
char * upb_MtDataEncoder_PutOneofField ( upb_MtDataEncoder * e , char * ptr ,
uint32_t field_num ) ;
// Encodes the set of values for a given enum. The values must be given in
// order (after casting to uint32_t), and repeats are not allowed.
char * upb_MtDataEncoder_StartEnum ( upb_MtDataEncoder * e , char * ptr ) ;
char * upb_MtDataEncoder_PutEnumValue ( upb_MtDataEncoder * e , char * ptr ,
uint32_t val ) ;
char * upb_MtDataEncoder_EndEnum ( upb_MtDataEncoder * e , char * ptr ) ;
// Encodes an entire mini descriptor for an extension.
char * upb_MtDataEncoder_EncodeExtension ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType type , uint32_t field_num ,
uint64_t field_mod ) ;
// Encodes an entire mini descriptor for a map.
char * upb_MtDataEncoder_EncodeMap ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType key_type ,
upb_FieldType value_type , uint64_t key_mod ,
uint64_t value_mod ) ;
// Encodes an entire mini descriptor for a message set.
char * upb_MtDataEncoder_EncodeMessageSet ( upb_MtDataEncoder * e , char * ptr ) ;
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */
# ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
# define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
# ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_
# define UPB_REFLECTION_DEF_POOL_INTERNAL_H_
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
upb_Arena * _upb_DefPool_Arena ( const upb_DefPool * s ) ;
size_t _upb_DefPool_BytesLoaded ( const upb_DefPool * s ) ;
upb_ExtensionRegistry * _upb_DefPool_ExtReg ( const upb_DefPool * s ) ;
bool _upb_DefPool_InsertExt ( upb_DefPool * s , const upb_MiniTableExtension * ext ,
const upb_FieldDef * f ) ;
bool _upb_DefPool_InsertSym ( upb_DefPool * s , upb_StringView sym , upb_value v ,
upb_Status * status ) ;
bool _upb_DefPool_LookupSym ( const upb_DefPool * s , const char * sym , size_t size ,
upb_value * v ) ;
void * * _upb_DefPool_ScratchData ( const upb_DefPool * s ) ;
size_t * _upb_DefPool_ScratchSize ( const upb_DefPool * s ) ;
void _upb_DefPool_SetPlatform ( upb_DefPool * s , upb_MiniTablePlatform platform ) ;
// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init * * deps ; // Dependencies of this file.
const upb_MiniTableFile * layout ;
const char * filename ;
upb_StringView descriptor ; // Serialized descriptor.
} _upb_DefPool_Init ;
bool _upb_DefPool_LoadDefInit ( upb_DefPool * s , const _upb_DefPool_Init * init ) ;
// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx ( upb_DefPool * s , const _upb_DefPool_Init * init ,
bool rebuild_minitable ) ;
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */
// Must be last.
// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
# define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
if ( UPB_DESC ( desc_type # # _has_options ) ( proto ) ) { \
size_t size ; \
char * pb = UPB_DESC ( options_type # # _serialize ) ( \
UPB_DESC ( desc_type # # _options ) ( proto ) , ctx - > tmp_arena , & size ) ; \
if ( ! pb ) _upb_DefBuilder_OomErr ( ctx ) ; \
target = \
UPB_DESC ( options_type # # _parse ) ( pb , size , _upb_DefBuilder_Arena ( ctx ) ) ; \
if ( ! target ) _upb_DefBuilder_OomErr ( ctx ) ; \
} else { \
target = ( const UPB_DESC ( options_type ) * ) kUpbDefOptDefault ; \
}
# ifdef __cplusplus
extern " C " {
# endif
struct upb_DefBuilder {
upb_DefPool * symtab ;
upb_FileDef * file ; // File we are building.
upb_Arena * arena ; // Allocate defs here.
upb_Arena * tmp_arena ; // For temporary allocations.
upb_Status * status ; // Record errors here.
const upb_MiniTableFile * layout ; // NULL if we should build layouts.
upb_MiniTablePlatform platform ; // Platform we are targeting.
int enum_count ; // Count of enums built so far.
int msg_count ; // Count of messages built so far.
int ext_count ; // Count of extensions built so far.
jmp_buf err ; // longjmp() on error.
} ;
extern const char * kUpbDefOptDefault ;
// ctx->status has already been set elsewhere so just fail/longjmp()
UPB_NORETURN void _upb_DefBuilder_FailJmp ( upb_DefBuilder * ctx ) ;
UPB_NORETURN void _upb_DefBuilder_Errf ( upb_DefBuilder * ctx , const char * fmt ,
. . . ) UPB_PRINTF ( 2 , 3 ) ;
UPB_NORETURN void _upb_DefBuilder_OomErr ( upb_DefBuilder * ctx ) ;
const char * _upb_DefBuilder_MakeFullName ( upb_DefBuilder * ctx ,
const char * prefix ,
upb_StringView name ) ;
// Given a symbol and the base symbol inside which it is defined,
// find the symbol's definition.
const void * _upb_DefBuilder_ResolveAny ( upb_DefBuilder * ctx ,
const char * from_name_dbg ,
const char * base , upb_StringView sym ,
upb_deftype_t * type ) ;
const void * _upb_DefBuilder_Resolve ( upb_DefBuilder * ctx ,
const char * from_name_dbg , const char * base ,
upb_StringView sym , upb_deftype_t type ) ;
char _upb_DefBuilder_ParseEscape ( upb_DefBuilder * ctx , const upb_FieldDef * f ,
const char * * src , const char * end ) ;
const char * _upb_DefBuilder_FullToShort ( const char * fullname ) ;
UPB_INLINE void * _upb_DefBuilder_Alloc ( upb_DefBuilder * ctx , size_t bytes ) {
if ( bytes = = 0 ) return NULL ;
void * ret = upb_Arena_Malloc ( ctx - > arena , bytes ) ;
if ( ! ret ) _upb_DefBuilder_OomErr ( ctx ) ;
return ret ;
}
// Adds a symbol |v| to the symtab, which must be a def pointer previously
// packed with pack_def(). The def's pointer to upb_FileDef* must be set before
// adding, so we know which entries to remove if building this file fails.
UPB_INLINE void _upb_DefBuilder_Add ( upb_DefBuilder * ctx , const char * name ,
upb_value v ) {
upb_StringView sym = { . data = name , . size = strlen ( name ) } ;
@ -12067,116 +12327,35 @@ upb_MessageDef* _upb_MessageDefs_New(
# endif
# endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */
# ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
# define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
upb_ServiceDef * _upb_ServiceDef_At ( const upb_ServiceDef * s , int i ) ;
// Allocate and initialize an array of |n| service defs.
upb_ServiceDef * _upb_ServiceDefs_New (
upb_DefBuilder * ctx , int n ,
const UPB_DESC ( ServiceDescriptorProto ) * const * protos ) ;
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */
# ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_
# define UPB_REFLECTION_DESC_STATE_INTERNAL_H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
// Must be last.
# endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */
// If the input buffer has at least this many bytes available, the encoder call
// is guaranteed to succeed (as long as field number order is maintained).
# define kUpb_MtDataEncoder_MinSize 16
# ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
# define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_
typedef struct {
char * end ; // Limit of the buffer passed as a parameter.
// Aliased to internal-only members in .cc.
char internal [ 32 ] ;
} upb_MtDataEncoder ;
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
// Encodes field/oneof information for a given message. The sequence of calls
// should look like:
//
// upb_MtDataEncoder e;
// char buf[256];
// char* ptr = buf;
// e.end = ptr + sizeof(buf);
// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero
// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod);
// // Fields *must* be in field number order.
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...);
//
// // If oneofs are present. Oneofs must be encoded after regular fields.
// ptr = upb_MiniTable_StartOneof(&e, ptr)
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// ptr = upb_MiniTable_StartOneof(&e, ptr);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...);
//
// Oneofs must be encoded after all regular fields.
char * upb_MtDataEncoder_StartMessage ( upb_MtDataEncoder * e , char * ptr ,
uint64_t msg_mod ) ;
char * upb_MtDataEncoder_PutField ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType type , uint32_t field_num ,
uint64_t field_mod ) ;
char * upb_MtDataEncoder_StartOneof ( upb_MtDataEncoder * e , char * ptr ) ;
char * upb_MtDataEncoder_PutOneofField ( upb_MtDataEncoder * e , char * ptr ,
uint32_t field_num ) ;
// Encodes the set of values for a given enum. The values must be given in
// order (after casting to uint32_t), and repeats are not allowed.
char * upb_MtDataEncoder_StartEnum ( upb_MtDataEncoder * e , char * ptr ) ;
char * upb_MtDataEncoder_PutEnumValue ( upb_MtDataEncoder * e , char * ptr ,
uint32_t val ) ;
char * upb_MtDataEncoder_EndEnum ( upb_MtDataEncoder * e , char * ptr ) ;
// Encodes an entire mini descriptor for an extension.
char * upb_MtDataEncoder_EncodeExtension ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType type , uint32_t field_num ,
uint64_t field_mod ) ;
// Encodes an entire mini descriptor for a map.
char * upb_MtDataEncoder_EncodeMap ( upb_MtDataEncoder * e , char * ptr ,
upb_FieldType key_type ,
upb_FieldType value_type , uint64_t key_mod ,
uint64_t value_mod ) ;
upb_ServiceDef * _upb_ServiceDef_At ( const upb_ServiceDef * s , int i ) ;
// Encodes an entire mini descriptor for a message set.
char * upb_MtDataEncoder_EncodeMessageSet ( upb_MtDataEncoder * e , char * ptr ) ;
// Allocate and initialize an array of |n| service defs.
upb_ServiceDef * _upb_ServiceDefs_New (
upb_DefBuilder * ctx , int n ,
const UPB_DESC ( ServiceDescriptorProto ) * const * protos ) ;
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */
# endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */
# ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_
# define UPB_REFLECTION_DESC_STATE_INTERNAL_H_
// Must be last.
@ -12281,28 +12460,6 @@ upb_ExtensionRange* _upb_ExtensionRanges_New(
# endif /* UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ */
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
// Must be last.
typedef enum {
kUpb_FieldModifier_IsRepeated = 1 < < 0 ,
kUpb_FieldModifier_IsPacked = 1 < < 1 ,
kUpb_FieldModifier_IsClosedEnum = 1 < < 2 ,
kUpb_FieldModifier_IsProto3Singular = 1 < < 3 ,
kUpb_FieldModifier_IsRequired = 1 < < 4 ,
} kUpb_FieldModifier ;
typedef enum {
kUpb_MessageModifier_ValidateUtf8 = 1 < < 0 ,
kUpb_MessageModifier_DefaultIsPacked = 1 < < 1 ,
kUpb_MessageModifier_IsExtendable = 1 < < 2 ,
} kUpb_MessageModifier ;
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
# ifndef UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_
# define UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_
@ -12556,163 +12713,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) {
# endif /* UPB_WIRE_INTERNAL_DECODE_H_ */
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
// Must be last.
# ifdef __cplusplus
extern " C " {
# endif
UPB_INLINE char _upb_ToBase92 ( int8_t ch ) {
extern const char _kUpb_ToBase92 [ ] ;
UPB_ASSERT ( 0 < = ch & & ch < 92 ) ;
return _kUpb_ToBase92 [ ch ] ;
}
UPB_INLINE char _upb_FromBase92 ( uint8_t ch ) {
extern const int8_t _kUpb_FromBase92 [ ] ;
if ( ' ' > ch | | ch > ' ~ ' ) return - 1 ;
return _kUpb_FromBase92 [ ch - ' ' ] ;
}
UPB_INLINE const char * _upb_Base92_DecodeVarint ( const char * ptr ,
const char * end , char first_ch ,
uint8_t min , uint8_t max ,
uint32_t * out_val ) {
uint32_t val = 0 ;
uint32_t shift = 0 ;
const int bits_per_char =
upb_Log2Ceiling ( _upb_FromBase92 ( max ) - _upb_FromBase92 ( min ) ) ;
char ch = first_ch ;
while ( 1 ) {
uint32_t bits = _upb_FromBase92 ( ch ) - _upb_FromBase92 ( min ) ;
val | = bits < < shift ;
if ( ptr = = end | | * ptr < min | | max < * ptr ) {
* out_val = val ;
UPB_ASSUME ( ptr ! = NULL ) ;
return ptr ;
}
ch = * ptr + + ;
shift + = bits_per_char ;
if ( shift > = 32 ) return NULL ;
}
}
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
// Must be last.
typedef enum {
kUpb_EncodedType_Double = 0 ,
kUpb_EncodedType_Float = 1 ,
kUpb_EncodedType_Fixed32 = 2 ,
kUpb_EncodedType_Fixed64 = 3 ,
kUpb_EncodedType_SFixed32 = 4 ,
kUpb_EncodedType_SFixed64 = 5 ,
kUpb_EncodedType_Int32 = 6 ,
kUpb_EncodedType_UInt32 = 7 ,
kUpb_EncodedType_SInt32 = 8 ,
kUpb_EncodedType_Int64 = 9 ,
kUpb_EncodedType_UInt64 = 10 ,
kUpb_EncodedType_SInt64 = 11 ,
kUpb_EncodedType_OpenEnum = 12 ,
kUpb_EncodedType_Bool = 13 ,
kUpb_EncodedType_Bytes = 14 ,
kUpb_EncodedType_String = 15 ,
kUpb_EncodedType_Group = 16 ,
kUpb_EncodedType_Message = 17 ,
kUpb_EncodedType_ClosedEnum = 18 ,
kUpb_EncodedType_RepeatedBase = 20 ,
} upb_EncodedType ;
typedef enum {
kUpb_EncodedFieldModifier_FlipPacked = 1 < < 0 ,
kUpb_EncodedFieldModifier_IsRequired = 1 < < 1 ,
kUpb_EncodedFieldModifier_IsProto3Singular = 1 < < 2 ,
} upb_EncodedFieldModifier ;
enum {
kUpb_EncodedValue_MinField = ' ' ,
kUpb_EncodedValue_MaxField = ' I ' ,
kUpb_EncodedValue_MinModifier = ' L ' ,
kUpb_EncodedValue_MaxModifier = ' [ ' ,
kUpb_EncodedValue_End = ' ^ ' ,
kUpb_EncodedValue_MinSkip = ' _ ' ,
kUpb_EncodedValue_MaxSkip = ' ~ ' ,
kUpb_EncodedValue_OneofSeparator = ' ~ ' ,
kUpb_EncodedValue_FieldSeparator = ' | ' ,
kUpb_EncodedValue_MinOneofField = ' ' ,
kUpb_EncodedValue_MaxOneofField = ' b ' ,
kUpb_EncodedValue_MaxEnumMask = ' A ' ,
} ;
enum {
kUpb_EncodedVersion_EnumV1 = ' ! ' ,
kUpb_EncodedVersion_ExtensionV1 = ' # ' ,
kUpb_EncodedVersion_MapV1 = ' % ' ,
kUpb_EncodedVersion_MessageV1 = ' $ ' ,
kUpb_EncodedVersion_MessageSetV1 = ' & ' ,
} ;
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
# ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
# define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
// Must be last.
// upb_MdDecoder: used internally for decoding MiniDescriptors for messages,
// extensions, and enums.
typedef struct {
const char * end ;
upb_Status * status ;
jmp_buf err ;
} upb_MdDecoder ;
UPB_PRINTF ( 2 , 3 )
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp ( upb_MdDecoder * d ,
const char * fmt , . . . ) {
if ( d - > status ) {
va_list argp ;
upb_Status_SetErrorMessage ( d - > status , " Error building mini table: " ) ;
va_start ( argp , fmt ) ;
upb_Status_VAppendErrorFormat ( d - > status , fmt , argp ) ;
va_end ( argp ) ;
}
UPB_LONGJMP ( d - > err , 1 ) ;
}
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory ( upb_MdDecoder * d ,
const void * ptr ) {
if ( ! ptr ) upb_MdDecoder_ErrorJmp ( d , " Out of memory " ) ;
}
UPB_INLINE const char * upb_MdDecoder_DecodeBase92Varint (
upb_MdDecoder * d , const char * ptr , char first_ch , uint8_t min , uint8_t max ,
uint32_t * out_val ) {
ptr = _upb_Base92_DecodeVarint ( ptr , d - > end , first_ch , min , max , out_val ) ;
if ( ! ptr ) upb_MdDecoder_ErrorJmp ( d , " Overlong varint " ) ;
return ptr ;
}
# endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
// This should #undef all macros #defined in def.inc
# undef UPB_SIZE