File indexing completed on 2026-07-28 09:30:13
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_WIRE_READER_H_
0009 #define UPB_WIRE_READER_H_
0010
0011 #include <stddef.h>
0012 #include <stdint.h>
0013 #include <string.h>
0014
0015 #include "upb/base/internal/endian.h"
0016 #include "upb/wire/eps_copy_input_stream.h"
0017 #include "upb/wire/internal/reader.h"
0018 #include "upb/wire/types.h" // IWYU pragma: export
0019
0020
0021 #include "upb/port/def.inc"
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef __cplusplus
0030 extern "C" {
0031 #endif
0032
0033
0034
0035
0036
0037
0038
0039 UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr,
0040 uint32_t* tag) {
0041 uint64_t val;
0042 ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX);
0043 if (!ptr) return NULL;
0044 *tag = val;
0045 return ptr;
0046 }
0047
0048
0049 UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag);
0050
0051
0052 UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag);
0053
0054 UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr,
0055 uint64_t* val) {
0056 return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX);
0057 }
0058
0059
0060
0061
0062
0063
0064
0065 UPB_INLINE const char* upb_WireReader_SkipVarint(const char* ptr) {
0066 uint64_t val;
0067 return upb_WireReader_ReadVarint(ptr, &val);
0068 }
0069
0070
0071
0072
0073
0074
0075
0076 UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) {
0077 uint64_t size64;
0078 ptr = upb_WireReader_ReadVarint(ptr, &size64);
0079 if (!ptr || size64 >= INT32_MAX) return NULL;
0080 *size = size64;
0081 return ptr;
0082 }
0083
0084
0085
0086
0087
0088
0089 UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) {
0090 uint32_t uval;
0091 memcpy(&uval, ptr, 4);
0092 uval = upb_BigEndian32(uval);
0093 memcpy(val, &uval, 4);
0094 return ptr + 4;
0095 }
0096
0097
0098
0099
0100
0101
0102 UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) {
0103 uint64_t uval;
0104 memcpy(&uval, ptr, 8);
0105 uval = upb_BigEndian64(uval);
0106 memcpy(val, &uval, 8);
0107 return ptr + 8;
0108 }
0109
0110 const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)(
0111 const char* ptr, uint32_t tag, int depth_limit,
0112 upb_EpsCopyInputStream* stream);
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 UPB_INLINE const char* upb_WireReader_SkipGroup(
0124 const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) {
0125 return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream);
0126 }
0127
0128 UPB_INLINE const char* _upb_WireReader_SkipValue(
0129 const char* ptr, uint32_t tag, int depth_limit,
0130 upb_EpsCopyInputStream* stream) {
0131 switch (upb_WireReader_GetWireType(tag)) {
0132 case kUpb_WireType_Varint:
0133 return upb_WireReader_SkipVarint(ptr);
0134 case kUpb_WireType_32Bit:
0135 return ptr + 4;
0136 case kUpb_WireType_64Bit:
0137 return ptr + 8;
0138 case kUpb_WireType_Delimited: {
0139 int size;
0140 ptr = upb_WireReader_ReadSize(ptr, &size);
0141 if (!ptr || !upb_EpsCopyInputStream_CheckSize(stream, ptr, size)) {
0142 return NULL;
0143 }
0144 ptr += size;
0145 return ptr;
0146 }
0147 case kUpb_WireType_StartGroup:
0148 return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit,
0149 stream);
0150 case kUpb_WireType_EndGroup:
0151 return NULL;
0152 default:
0153 return NULL;
0154 }
0155 }
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 UPB_INLINE const char* upb_WireReader_SkipValue(
0170 const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) {
0171 return _upb_WireReader_SkipValue(ptr, tag, 100, stream);
0172 }
0173
0174 #ifdef __cplusplus
0175 }
0176 #endif
0177
0178 #include "upb/port/undef.inc"
0179
0180 #endif