File indexing completed on 2026-07-13 08:34:21
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_WIRE_INTERNAL_READER_H_
0009 #define UPB_WIRE_INTERNAL_READER_H_
0010
0011
0012 #include "upb/port/def.inc"
0013
0014 #define kUpb_WireReader_WireTypeBits 3
0015 #define kUpb_WireReader_WireTypeMask 7
0016
0017 typedef struct {
0018 const char* ptr;
0019 uint64_t val;
0020 } UPB_PRIVATE(_upb_WireReader_LongVarint);
0021
0022 #ifdef __cplusplus
0023 extern "C" {
0024 #endif
0025
0026 UPB_PRIVATE(_upb_WireReader_LongVarint)
0027 UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val);
0028
0029 UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)(
0030 const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) {
0031 uint64_t byte = (uint8_t)*ptr;
0032 if (UPB_LIKELY((byte & 0x80) == 0)) {
0033 *val = (uint32_t)byte;
0034 return ptr + 1;
0035 }
0036 const char* start = ptr;
0037 UPB_PRIVATE(_upb_WireReader_LongVarint)
0038 res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte);
0039 if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) ||
0040 res.val > maxval) {
0041 return NULL;
0042 }
0043 *val = res.val;
0044 return res.ptr;
0045 }
0046
0047 UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) {
0048 return tag >> kUpb_WireReader_WireTypeBits;
0049 }
0050
0051 UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) {
0052 return tag & kUpb_WireReader_WireTypeMask;
0053 }
0054
0055 #ifdef __cplusplus
0056 }
0057 #endif
0058
0059 #include "upb/port/undef.inc"
0060
0061 #endif